From 8b31167c7ae33b67eb1c7ce3068c797b5ab53483 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 7 Sep 2017 15:46:21 +1000 Subject: [PATCH] spec-tool: correctly offset extension enum values --- tools/spec.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/spec.py b/tools/spec.py index 05d6275..c99c65e 100755 --- a/tools/spec.py +++ b/tools/spec.py @@ -410,11 +410,26 @@ def parse_commands(nodes): ############################################################################### def parse_extension(types, node): + number = int(node.attrib['number']) - 1 + assert(number >= 0) r = node.find('require') for enum in r.findall('./enum'): 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'): if not command.attrib['name'] in types: raise "unknown command"