def num_from_str(num_str):
if num_str.lower().startswith('0x'):
return int(num_str, base=16)
- else:
- assert not num_str.startswith('0'), 'octals numbers not allowed'
- return int(num_str)
+
+ assert not num_str.startswith('0'), 'octals numbers not allowed'
+ return int(num_str)
class Field(object):
ufixed_pattern = re.compile(r"u(\d+)\.(\d+)")
print(" %-36s %s%s;" % (type, self.name, dim))
prefix = ""
- if len(self.values) > 0 and self.default == None:
+ if self.values and self.default == None:
if self.prefix:
prefix = self.prefix + "_"
def collect_dwords(self, dwords, start, dim):
for field in self.fields:
- if type(field) is Group:
+ if isinstance(field, Group):
if field.count == 1:
field.collect_dwords(dwords, start + field.start, dim)
else:
# to the dword for those fields.
field_index = 0
for field in dw.fields:
- if type(field) is Field and field.is_struct_type():
+ if isinstance(field, Field) and field.is_struct_type():
name = field.name + field.dim
print("")
print(" uint32_t v%d_%d;" % (index, field_index))
non_address_fields.append("/* unhandled field %s, type %s */\n" % \
(name, field.type))
- if len(non_address_fields) > 0:
+ if non_address_fields:
print(" |\n".join(" " + f for f in non_address_fields) + ";")
if dw.size == 32:
def gen_prefix(self, name):
if name[0] == "_":
return 'GEN%s%s' % (self.gen, name)
- else:
- return 'GEN%s_%s' % (self.gen, name)
+ return 'GEN%s_%s' % (self.gen, name)
def gen_guard(self):
return self.gen_prefix("PACK_H")
def emit_instruction(self):
name = self.instruction
- if not self.length == None:
+ if not self.length is None:
print('#define %-33s %6d' %
(self.gen_prefix(name + "_length"), self.length))
print('#define %-33s %6d' %
default_fields = []
for field in self.group.fields:
- if not type(field) is Field:
+ if not isinstance(field, Field):
continue
- if field.default == None:
+ if field.default is None:
continue
default_fields.append(" .%-35s = %6d" % (field.name, field.default))
def emit_register(self):
name = self.register
- if not self.reg_num == None:
+ if not self.reg_num is None:
print('#define %-33s 0x%04x' %
(self.gen_prefix(name + "_num"), self.reg_num))
- if not self.length == None:
+ if not self.length is None:
print('#define %-33s %6d' %
(self.gen_prefix(name + "_length"), self.length))
def emit_struct(self):
name = self.struct
- if not self.length == None:
+ if not self.length is None:
print('#define %-33s %6d' %
(self.gen_prefix(name + "_length"), self.length))