diff options
author | Neale Ranns <nranns@cisco.com> | 2020-04-22 16:06:45 +0000 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2020-04-24 07:22:32 +0000 |
commit | b5c0d35f9445d4d99f2c5c7bd3175e68721a8ee5 (patch) | |
tree | cc9bac6c400033ae6b7b0de36bcfc480d810cf5f /src | |
parent | 0e2751cc1d246145cee6b1e4a588c30270c7ce21 (diff) |
vapi: packed enum type generation
Type: fix
if the ,api/.json specifies that a enum should be u8/u16 that the
generated c enum needs to be packed.
Signed-off-by: Neale Ranns <nranns@cisco.com>
Change-Id: Ia0497b45e4c510a5c63cd02e966769bf20686838
Diffstat (limited to 'src')
-rwxr-xr-x | src/vpp-api/vapi/vapi_c_gen.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/vpp-api/vapi/vapi_c_gen.py b/src/vpp-api/vapi/vapi_c_gen.py index 330bd92ef8f..a881ad578ae 100755 --- a/src/vpp-api/vapi/vapi_c_gen.py +++ b/src/vpp-api/vapi/vapi_c_gen.py @@ -153,6 +153,12 @@ class CSimpleType (SimpleType): 'i64': 'be64toh', 'u64': 'be64toh', } + __packed = "__attribute__((packed))" + pack_dict = { + 'i8': __packed, 'u8': __packed, + 'i16': __packed, 'u16': __packed, + } + def get_c_name(self): return self.name @@ -162,6 +168,9 @@ class CSimpleType (SimpleType): def get_swap_to_host_func_name(self): return self.swap_to_host_dict[self.name] + def get_packed_string(self): + return self.pack_dict[self.name] + def get_swap_to_be_code(self, struct, var, cast=None): x = "%s%s" % (struct, var) return "%s = %s%s(%s);" % (x, @@ -182,14 +191,18 @@ class CSimpleType (SimpleType): pass return False + def get_packed(self): + return self.pack_dict.get(self.name, "") + class CEnum(Enum): def get_c_name(self): return "vapi_enum_%s" % self.name def get_c_def(self): - return "typedef enum {\n%s\n} %s;" % ( + return "typedef enum {\n%s\n} %s %s;" % ( "\n".join([" %s = %s," % (i, j) for i, j in self.value_pairs]), + self.type.get_packed(), self.get_c_name() ) |