freedreno/registers: Refactor gen_header.py to allow more options
We want it to also generate .py files with reg definitions. Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23217>
This commit is contained in:
committed by
Marge Bot
parent
10e75aae1b
commit
a9fc9bc46b
@@ -38,7 +38,7 @@ foreach f : xml_files
|
||||
_name,
|
||||
input: [gen_header_py, f],
|
||||
output: _name,
|
||||
command: [prog_python, '@INPUT0@', rnn_src_path, '@INPUT1@'],
|
||||
command: [prog_python, '@INPUT0@', '--rnn', rnn_src_path, '--xml', '@INPUT1@', 'c-defines'],
|
||||
capture: true,
|
||||
)
|
||||
_gzname = f + '.gz'
|
||||
@@ -58,7 +58,7 @@ freedreno_xml_header_files += custom_target(
|
||||
'a6xx-pack.xml.h',
|
||||
input: [gen_header_py, 'a6xx.xml'],
|
||||
output: 'a6xx-pack.xml.h',
|
||||
command: [prog_python, '@INPUT0@', rnn_src_path, '@INPUT1@', '--pack-structs'],
|
||||
command: [prog_python, '@INPUT0@', '--rnn', rnn_src_path, '--xml', '@INPUT1@', 'c-pack-structs'],
|
||||
capture: true,
|
||||
)
|
||||
|
||||
@@ -66,6 +66,6 @@ freedreno_xml_header_files += custom_target(
|
||||
'adreno-pm4-pack.xml.h',
|
||||
input: [gen_header_py, 'adreno_pm4.xml'],
|
||||
output: 'adreno-pm4-pack.xml.h',
|
||||
command: [prog_python, '@INPUT0@', rnn_src_path, '@INPUT1@', '--pack-structs'],
|
||||
command: [prog_python, '@INPUT0@', '--rnn', rnn_src_path, '--xml', '@INPUT1@', 'c-pack-structs'],
|
||||
capture: true,
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ import xml.parsers.expat
|
||||
import sys
|
||||
import os
|
||||
import collections
|
||||
import argparse
|
||||
|
||||
class Error(Exception):
|
||||
def __init__(self, message):
|
||||
@@ -705,16 +706,14 @@ class Parser(object):
|
||||
self.dump_reg_variants(regname, self.variant_regs[regname])
|
||||
|
||||
|
||||
def main():
|
||||
def dump_c(rnn_path, xml_path, guard, func):
|
||||
p = Parser()
|
||||
rnn_path = sys.argv[1]
|
||||
xml_file = sys.argv[2]
|
||||
if len(sys.argv) > 3 and sys.argv[3] == '--pack-structs':
|
||||
do_structs = True
|
||||
guard = str.replace(os.path.basename(xml_file), '.', '_').upper() + '_STRUCTS'
|
||||
else:
|
||||
do_structs = False
|
||||
guard = str.replace(os.path.basename(xml_file), '.', '_').upper()
|
||||
|
||||
try:
|
||||
p.parse(rnn_path, xml_path)
|
||||
except Error as e:
|
||||
print(e, file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
print("#ifndef %s\n#define %s\n" % (guard, guard))
|
||||
|
||||
@@ -728,18 +727,37 @@ def main():
|
||||
print("#define __struct_cast(X) (struct X)")
|
||||
print("#endif")
|
||||
|
||||
try:
|
||||
p.parse(rnn_path, xml_file)
|
||||
except Error as e:
|
||||
print(e, file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
if do_structs:
|
||||
p.dump_structs()
|
||||
else:
|
||||
p.dump()
|
||||
func(p)
|
||||
|
||||
print("\n#endif /* %s */" % guard)
|
||||
|
||||
|
||||
def dump_c_defines(args):
|
||||
guard = str.replace(os.path.basename(args.xml), '.', '_').upper()
|
||||
dump_c(args.rnn, args.xml, guard, lambda p: p.dump())
|
||||
|
||||
|
||||
def dump_c_pack_structs(args):
|
||||
guard = str.replace(os.path.basename(args.xml), '.', '_').upper() + '_STRUCTS'
|
||||
dump_c(args.rnn, args.xml, guard, lambda p: p.dump_structs())
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--rnn', type=str, required=True)
|
||||
parser.add_argument('--xml', type=str, required=True)
|
||||
|
||||
subparsers = parser.add_subparsers(required=True)
|
||||
|
||||
parser_c_defines = subparsers.add_parser('c-defines')
|
||||
parser_c_defines.set_defaults(func=dump_c_defines)
|
||||
|
||||
parser_c_pack_structs = subparsers.add_parser('c-pack-structs')
|
||||
parser_c_pack_structs.set_defaults(func=dump_c_pack_structs)
|
||||
|
||||
args = parser.parse_args()
|
||||
args.func(args)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -34,9 +34,10 @@ foreach f : xml_files
|
||||
_name,
|
||||
input: [gen_header_py, f],
|
||||
output: _name,
|
||||
command: [prog_python, '@INPUT0@', rnn_src_path, '@INPUT1@'],
|
||||
command: [prog_python, '@INPUT0@', '--rnn', rnn_src_path, '--xml', '@INPUT1@', 'c-defines'],
|
||||
capture: true,
|
||||
)
|
||||
|
||||
_gzname = f + '.gz'
|
||||
custom_target(
|
||||
_gzname,
|
||||
|
||||
Reference in New Issue
Block a user