spec-tool: correctly offset extension enum values

This commit is contained in:
Danny Robson 2017-09-07 15:46:21 +10:00
parent 66354ace30
commit 8b31167c7a

View File

@ -410,11 +410,26 @@ def parse_commands(nodes):
############################################################################### ###############################################################################
def parse_extension(types, node): def parse_extension(types, node):
number = int(node.attrib['number']) - 1
assert(number >= 0)
r = node.find('require') r = node.find('require')
for enum in r.findall('./enum'): for enum in r.findall('./enum'):
if 'extends' in enum.attrib: if 'extends' in enum.attrib:
types[enum.attrib['extends']].add(name=enum.attrib['name']) target = types[enum.attrib['extends']]
name = enum.attrib['name']
if 'offset' in enum.attrib:
offset = int(enum.attrib['offset'])
value = 1000000000 + 1000 * number + offset
if 'dir' in enum.attrib:
value *= -1
target.add(name, "%i" % value)
elif 'bitpos' in enum.attrib:
target.add(name, '1 << %s' % (enum.attrib['bitpos']))
elif 'value' in enum.attrib:
target.add(name, enum.attrib['value'])
else:
assert False, 'unhandled enum extension'
for command in r.findall('./command'): for command in r.findall('./command'):
if not command.attrib['name'] in types: if not command.attrib['name'] in types:
raise "unknown command" raise "unknown command"