if name == 'genxml':
self.gen = Gen(attrs['gen'])
elif name in ('instruction', 'struct', 'register'):
+ if name == 'instruction' and 'engine' in attrs:
+ engines = set(attrs['engine'].split('|'))
+ if not engines & self.engines:
+ return
self.start_container(attrs)
elif name == 'field':
self.start_field(attrs)
help="If OUTPUT is unset or '-', then it defaults to '/dev/stdout'")
p.add_argument('--cpp-guard', type=str,
help='If unset, then CPP_GUARD is derived from OUTPUT.')
+ p.add_argument('--engines', nargs='?', type=str, default='render',
+ help="Comma-separated list of engines whose instructions should be parsed (default: %(default)s)")
p.add_argument('xml_sources', metavar='XML_SOURCE', nargs='+')
pargs = p.parse_args()
def main():
pargs = parse_args()
+ engines = pargs.engines.split(',')
+ valid_engines = [ 'render', 'blitter', 'video' ]
+ if set(engines) - set(valid_engines):
+ print("Invalid engine specified, valid engines are:\n")
+ for e in valid_engines:
+ print("\t%s" % e)
+ sys.exit(1)
+
# Maps name => Container
containers = {}
for source in pargs.xml_sources:
- XmlParser(containers).parse(source)
+ p = XmlParser(containers)
+ p.engines = set(engines)
+ p.parse(source)
with open(pargs.output, 'wb') as f:
f.write(TEMPLATE.render(containers=containers, guard=pargs.cpp_guard))
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
+import argparse
import ast
import xml.parsers.expat
import re
if name == "instruction":
self.instruction = safe_name(attrs["name"])
self.length_bias = int(attrs["bias"])
+ if "engine" in attrs:
+ self.instruction_engines = set(attrs["engine"].split('|'))
+ else:
+ # When an instruction doesn't have the engine specified,
+ # it is considered to be for all engines, so 'None' is used
+ # to signify that the instruction belongs to all engines.
+ self.instruction_engines = None
elif name == "struct":
self.struct = safe_name(attrs["name"])
self.structs[attrs["name"]] = 1
def emit_instruction(self):
name = self.instruction
+ if self.instruction_engines and not self.instruction_engines & self.engines:
+ return
+
if not self.length is None:
print('#define %-33s %6d' %
(self.gen_prefix(name + "_length"), self.length))
self.parser.ParseFile(file)
file.close()
-if len(sys.argv) < 2:
- print("No input xml file specified")
- sys.exit(1)
+def parse_args():
+ p = argparse.ArgumentParser()
+ p.add_argument('xml_source', metavar='XML_SOURCE',
+ help="Input xml file")
+ p.add_argument('--engines', nargs='?', type=str, default='render',
+ help="Comma-separated list of engines whose instructions should be parsed (default: %(default)s)")
+
+ pargs = p.parse_args()
+
+ if pargs.engines is None:
+ print("No engines specified")
+ sys.exit(1)
+
+ return pargs
+
+def main():
+ pargs = parse_args()
+
+ input_file = pargs.xml_source
+ engines = pargs.engines.split(',')
+ valid_engines = [ 'render', 'blitter', 'video' ]
+ if set(engines) - set(valid_engines):
+ print("Invalid engine specified, valid engines are:\n")
+ for e in valid_engines:
+ print("\t%s" % e)
+ sys.exit(1)
-input_file = sys.argv[1]
+ p = Parser()
+ p.engines = set(engines)
+ p.parse(input_file)
-p = Parser()
-p.parse(input_file)
+if __name__ == '__main__':
+ main()