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
diff --git a/src/vpp-api/vapi/vapi_c_gen.py b/src/vpp-api/vapi/vapi_c_gen.py
index 330bd92..a881ad5 100755
--- a/src/vpp-api/vapi/vapi_c_gen.py
+++ b/src/vpp-api/vapi/vapi_c_gen.py
@@ -153,6 +153,12 @@
'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 @@
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 @@
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()
)