diff --git a/src/compiler/isaspec/decode.py b/src/compiler/isaspec/decode.py index 1ee7cd29b4d..afa56edf508 100755 --- a/src/compiler/isaspec/decode.py +++ b/src/compiler/isaspec/decode.py @@ -23,6 +23,7 @@ from mako.template import Template from isa import ISA +import argparse import os import sys @@ -293,20 +294,41 @@ glue = """\ """ -xml = sys.argv[1] -glue_h = sys.argv[2] -dst_c = sys.argv[3] -dst_h = sys.argv[4] +def guard(p): + return os.path.basename(p).upper().replace("-", "_").replace(".", "_") -isa = ISA(xml) +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--xml', required=True, help='isaspec XML file.') + parser.add_argument('--out-c', required=True, help='Output C file.') + parser.add_argument('--out-h', required=True, help='Output H file.') + parser.add_argument('--out-glue-h', + required=True, + help='Output glue H file.') + args = parser.parse_args() -with open(glue_h, 'w') as f: - guard = os.path.basename(glue_h).upper().replace("-", "_").replace(".", "_") - f.write(Template(glue).render(guard=guard, isa=os.path.basename(dst_h))) + isa = ISA(args.xml) -with open(dst_c, 'w') as f: - f.write(Template(template).render(isa=isa)) + try: + with open(args.out_glue_h, 'w') as f: + f.write(Template(glue).render(guard=guard(args.out_glue_h), + isa=os.path.basename(args.out_h))) -with open(dst_h, 'w') as f: - guard = os.path.basename(dst_h).upper().replace("-", "_").replace(".", "_") - f.write(Template(header).render(isa=isa, guard=guard)) + with open(args.out_c, 'w') as f: + f.write(Template(template).render(isa=isa)) + + with open(args.out_h, 'w') as f: + f.write(Template(header).render(isa=isa, guard=guard(args.out_h))) + + except Exception: + # In the event there's an error, this imports some helpers from mako + # to print a useful stack trace and prints it, then exits with + # status 1, if python is run with debug; otherwise it just raises + # the exception + import sys + from mako import exceptions + print(exceptions.text_error_template().render(), file=sys.stderr) + sys.exit(1) + +if __name__ == '__main__': + main() diff --git a/src/compiler/isaspec/encode.py b/src/compiler/isaspec/encode.py index 2784b871a62..5993ee69eec 100755 --- a/src/compiler/isaspec/encode.py +++ b/src/compiler/isaspec/encode.py @@ -23,6 +23,7 @@ from mako.template import Template from isa import ISA, BitSetDerivedField, BitSetAssertField +import argparse import sys import re @@ -683,14 +684,28 @@ isa = s.isa """ def main(): - xml = sys.argv[1] - dst = sys.argv[2] + parser = argparse.ArgumentParser() + parser.add_argument('--xml', required=True, help='isaspec XML file.') + parser.add_argument('--out-h', required=True, help='Output H file.') + args = parser.parse_args() - isa = ISA(xml) + isa = ISA(args.xml) s = State(isa) - with open(dst, 'w') as f: - f.write(Template(template).render(s=s, encode_bitset=Template(encode_bitset_template))) + try: + with open(args.out_h, 'w') as f: + encode_bitset = Template(encode_bitset_template) + f.write(Template(template).render(s=s, encode_bitset=encode_bitset)) + + except Exception: + # In the event there's an error, this imports some helpers from mako + # to print a useful stack trace and prints it, then exits with + # status 1, if python is run with debug; otherwise it just raises + # the exception + import sys + from mako import exceptions + print(exceptions.text_error_template().render(), file=sys.stderr) + sys.exit(1) if __name__ == '__main__': main() diff --git a/src/freedreno/isa/meson.build b/src/freedreno/isa/meson.build index a0fbd58aefe..63b4c43b042 100644 --- a/src/freedreno/isa/meson.build +++ b/src/freedreno/isa/meson.build @@ -36,7 +36,8 @@ ir3_isa = custom_target( input: ['ir3.xml'], output: ['isaspec-isa.h', 'ir3-isa.c', 'ir3-isa.h'], command: [ - prog_isaspec_decode, '@INPUT@', '@OUTPUT@' + prog_isaspec_decode, '--xml', '@INPUT@', '--out-glue-h', '@OUTPUT0@', + '--out-c', '@OUTPUT1@', '--out-h', '@OUTPUT2@', ], depend_files: isa_depend_files, ) @@ -76,7 +77,7 @@ encode_h = custom_target( input: ['ir3.xml'], output: 'encode.h', command: [ - prog_isaspec_encode, '@INPUT@', '@OUTPUT@' + prog_isaspec_encode, '--xml', '@INPUT@', '--out-h', '@OUTPUT@' ], depend_files: isa_depend_files, )