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 (cherry picked from commit b5c0d35f9445d4d99f2c5c7bd3175e68721a8ee5)
This commit is contained in:
parent
4e138bf173
commit
66cb17227c
@ -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()
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user