def __init__(self, parser, attrs):
self.parser = parser
- self.name = safe_name(attrs["name"])
+ if "name" in attrs:
+ self.name = safe_name(attrs["name"])
self.start = int(attrs["start"])
self.end = int(attrs["end"])
self.type = attrs["type"]
if ufixed_match:
self.type = 'ufixed'
self.fractional_size = int(ufixed_match.group(2))
-
+
sfixed_match = Field.sfixed_pattern.match(self.type)
if sfixed_match:
self.type = 'sfixed'
type = 'uint32_t'
elif self.type in self.parser.structs:
type = 'struct ' + self.parser.gen_prefix(safe_name(self.type))
+ elif self.type == 'mbo':
+ return
else:
print("#error unhandled type: %s" % self.type)
-
+
print(" %-36s %s%s;" % (type, self.name, dim))
if len(self.values) > 0 and self.default == None:
# assert dwords[index].address == None
dwords[index].address = field
- # Does this field extend into the next dword?
- if index < field.end // 32 and dwords[index].size == 32:
- if index + 1 in dwords:
- assert dwords[index + 1].size == 32
+ # Coalesce all the dwords covered by this field. The two cases we
+ # handle are where multiple fields are in a 64 bit word (typically
+ # and address and a few bits) or where a single struct field
+ # completely covers multiple dwords.
+ while index < (start + field.end) // 32:
+ if index + 1 in dwords and not dwords[index] == dwords[index + 1]:
dwords[index].fields.extend(dwords[index + 1].fields)
dwords[index].size = 64
dwords[index + 1] = dwords[index]
+ index = index + 1
def emit_pack_function(self, start):
dwords = {}
field_index = 0
for field in dw.fields:
- name = field.name + field.dim
+ if field.type != "mbo":
+ name = field.name + field.dim
+
if field.type == "mbo":
s = "__gen_mbo(%d, %d)" % \
(field.start - dword_start, field.end - dword_start)
print("struct %s {" % self.gen_prefix(name))
group.emit_template_struct("")
print("};\n")
-
+
def emit_pack_function(self, name, group):
name = self.gen_prefix(name)
print("static inline void\n%s_pack(__gen_user_data *data, void * restrict dst,\n%sconst struct %s * restrict values)\n{" %
name = value.name
print('#define %-36s %4d' % (name.upper(), value.value))
print('')
-
+
def parse(self, filename):
file = open(filename, "rb")
self.parser.ParseFile(file)