type = 'uint32_t'
elif self.type in self.parser.structs:
type = 'struct ' + self.parser.gen_prefix(safe_name(self.type))
+ elif self.type in self.parser.enums:
+ type = 'enum ' + self.parser.gen_prefix(safe_name(self.type))
elif self.type == 'mbo':
return
else:
elif field.type == "uint":
s = "__gen_uint(values->%s, %d, %d)" % \
(name, start, end)
+ elif field.type in self.parser.enums:
+ s = "__gen_uint(values->%s, %d, %d)" % \
+ (name, start, end)
elif field.type == "int":
s = "__gen_sint(values->%s, %d, %d)" % \
(name, start, end)
convert = "__gen_unpack_address"
elif field.type == "uint":
convert = "__gen_unpack_uint"
+ elif field.type in self.parser.enums:
+ convert = "__gen_unpack_uint"
elif field.type == "int":
convert = "__gen_unpack_sint"
elif field.type == "bool":
self.packet = None
self.struct = None
self.structs = {}
+ # Set of enum names we've seen.
+ self.enums = set()
self.registers = {}
def gen_prefix(self, name):
elif name == "enum":
self.values = []
self.enum = safe_name(attrs["name"])
+ self.enums.add(attrs["name"])
if "prefix" in attrs:
self.prefix = safe_name(attrs["prefix"])
else:
print('')
def emit_enum(self):
- print('/* enum %s */' % self.gen_prefix(self.enum))
+ print('enum %s {' % self.gen_prefix(self.enum))
for value in self.values:
if self.prefix:
name = self.prefix + "_" + value.name
else:
name = value.name
- print('#define %-36s %6d' % (name.upper(), value.value))
- print('')
+ print(' % -36s = %6d,' % (name.upper(), value.value))
+ print('};\n')
def parse(self, filename):
file = open(filename, "rb")