return self.isa.bitsets[self.extends].get_root()
return self
+class BitSetTemplate(object):
+ """Class that encapsulates a template declaration
+ """
+ def __init__(self, isa, xml):
+ self.isa = isa
+ self.name = xml.attrib['name']
+ self.display = xml.text.strip()
+ dbg("found template '{}: {}'".format(self.name, self.display))
+
class BitSetEnum(object):
"""Class that encapsulates an enum declaration
"""
# Table of (globally defined) expressions:
self.expressions = {}
+ # Table of templates:
+ self.templates = {}
+
# Table of enums:
self.enums = {}
# Extract expressions:
self.parse_expressions(root)
+ # Extract templates:
+ for template in root.findall('template'):
+ t = BitSetTemplate(self, template)
+ self.templates[t.name] = t
+
# Extract enums:
for enum in root.findall('enum'):
e = BitSetEnum(self, enum)
self.bitsets[b.name] = b
self.leafs.setdefault(b.name, []).append(b)
+ # Resolve all templates:
+ for _, bitset in self.bitsets.items():
+ for case in bitset.cases:
+ if case.display:
+ case.display = self.resolve_templates(case.display)
+
def validate_isa(self):
# We only support multiples of 32 bits for now
assert self.bitsize % 32 == 0
continue
for bitset in bitsets:
yield name, bitset
+
+ def resolve_templates(self, display_string):
+ matches = re.findall(r'\{([^\}]+)\}', display_string)
+ for m in matches:
+ if m in self.templates:
+ display_string = display_string.replace("{" + m + "}", self.templates[m].display)
+
+ return display_string