mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-09 10:34:58 -06:00
target/hexagon: Use argparse in all python scripts
QOL commit, all the various gen_* python scripts take a large set arguments where order is implicit. Using argparse we also get decent error messages if a field is missing or too many are added. Signed-off-by: Anton Johansson <anjo@rev.ng> Reviewed-by: Brian Cain <brian.cain@oss.qualcomm.com> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
This commit is contained in:
parent
f0db9f5759
commit
e295796726
13 changed files with 109 additions and 47 deletions
|
@ -78,11 +78,13 @@ def gen_analyze_func(f, tag, regs, imms):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
hex_common.read_common_files()
|
args = hex_common.parse_common_args(
|
||||||
|
"Emit functions analyzing register accesses"
|
||||||
|
)
|
||||||
tagregs = hex_common.get_tagregs()
|
tagregs = hex_common.get_tagregs()
|
||||||
tagimms = hex_common.get_tagimms()
|
tagimms = hex_common.get_tagimms()
|
||||||
|
|
||||||
with open(sys.argv[-1], "w") as f:
|
with open(args.out, "w") as f:
|
||||||
f.write("#ifndef HEXAGON_ANALYZE_FUNCS_C_INC\n")
|
f.write("#ifndef HEXAGON_ANALYZE_FUNCS_C_INC\n")
|
||||||
f.write("#define HEXAGON_ANALYZE_FUNCS_C_INC\n\n")
|
f.write("#define HEXAGON_ANALYZE_FUNCS_C_INC\n\n")
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
import iset
|
import iset
|
||||||
import hex_common
|
import hex_common
|
||||||
|
import argparse
|
||||||
|
|
||||||
encs = {
|
encs = {
|
||||||
tag: "".join(reversed(iset.iset[tag]["enc"].replace(" ", "")))
|
tag: "".join(reversed(iset.iset[tag]["enc"].replace(" ", "")))
|
||||||
|
@ -191,8 +192,18 @@ def gen_decodetree_file(f, class_to_decode):
|
||||||
f.write(f"{tag}\t{enc_str} @{tag}\n")
|
f.write(f"{tag}\t{enc_str} @{tag}\n")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Emit opaque macro calls with instruction semantics"
|
||||||
|
)
|
||||||
|
parser.add_argument("semantics", help="semantics file")
|
||||||
|
parser.add_argument("class_to_decode", help="instruction class to decode")
|
||||||
|
parser.add_argument("out", help="output file")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
hex_common.read_semantics_file(args.semantics)
|
||||||
|
with open(args.out, "w") as f:
|
||||||
|
gen_decodetree_file(f, args.class_to_decode)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
hex_common.read_semantics_file(sys.argv[1])
|
main()
|
||||||
class_to_decode = sys.argv[2]
|
|
||||||
with open(sys.argv[3], "w") as f:
|
|
||||||
gen_decodetree_file(f, class_to_decode)
|
|
||||||
|
|
|
@ -102,12 +102,13 @@ def gen_helper_function(f, tag, tagregs, tagimms):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
hex_common.read_common_files()
|
args = hex_common.parse_common_args(
|
||||||
|
"Emit helper function definitions for each instruction"
|
||||||
|
)
|
||||||
tagregs = hex_common.get_tagregs()
|
tagregs = hex_common.get_tagregs()
|
||||||
tagimms = hex_common.get_tagimms()
|
tagimms = hex_common.get_tagimms()
|
||||||
|
|
||||||
output_file = sys.argv[-1]
|
with open(args.out, "w") as f:
|
||||||
with open(output_file, "w") as f:
|
|
||||||
for tag in hex_common.tags:
|
for tag in hex_common.tags:
|
||||||
## Skip the priv instructions
|
## Skip the priv instructions
|
||||||
if "A_PRIV" in hex_common.attribdict[tag]:
|
if "A_PRIV" in hex_common.attribdict[tag]:
|
||||||
|
|
|
@ -52,12 +52,13 @@ def gen_helper_prototype(f, tag, tagregs, tagimms):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
hex_common.read_common_files()
|
args = hex_common.parse_common_args(
|
||||||
|
"Emit helper function prototypes for each instruction"
|
||||||
|
)
|
||||||
tagregs = hex_common.get_tagregs()
|
tagregs = hex_common.get_tagregs()
|
||||||
tagimms = hex_common.get_tagimms()
|
tagimms = hex_common.get_tagimms()
|
||||||
|
|
||||||
output_file = sys.argv[-1]
|
with open(args.out, "w") as f:
|
||||||
with open(output_file, "w") as f:
|
|
||||||
for tag in hex_common.tags:
|
for tag in hex_common.tags:
|
||||||
## Skip the priv instructions
|
## Skip the priv instructions
|
||||||
if "A_PRIV" in hex_common.attribdict[tag]:
|
if "A_PRIV" in hex_common.attribdict[tag]:
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
|
import argparse
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
import hex_common
|
import hex_common
|
||||||
|
@ -43,13 +44,19 @@ import hex_common
|
||||||
## them are inputs ("in" prefix), while some others are outputs.
|
## them are inputs ("in" prefix), while some others are outputs.
|
||||||
##
|
##
|
||||||
def main():
|
def main():
|
||||||
hex_common.read_semantics_file(sys.argv[1])
|
parser = argparse.ArgumentParser(
|
||||||
|
"Emit instruction implementations that can be fed to idef-parser"
|
||||||
|
)
|
||||||
|
parser.add_argument("semantics", help="semantics file")
|
||||||
|
parser.add_argument("out", help="output file")
|
||||||
|
args = parser.parse_args()
|
||||||
|
hex_common.read_semantics_file(args.semantics)
|
||||||
hex_common.calculate_attribs()
|
hex_common.calculate_attribs()
|
||||||
hex_common.init_registers()
|
hex_common.init_registers()
|
||||||
tagregs = hex_common.get_tagregs()
|
tagregs = hex_common.get_tagregs()
|
||||||
tagimms = hex_common.get_tagimms()
|
tagimms = hex_common.get_tagimms()
|
||||||
|
|
||||||
with open(sys.argv[-1], "w") as f:
|
with open(args.out, "w") as f:
|
||||||
f.write('#include "macros.h.inc"\n\n')
|
f.write('#include "macros.h.inc"\n\n')
|
||||||
|
|
||||||
for tag in hex_common.tags:
|
for tag in hex_common.tags:
|
||||||
|
|
|
@ -21,16 +21,23 @@ import sys
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
import hex_common
|
import hex_common
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
hex_common.read_semantics_file(sys.argv[1])
|
parser = argparse.ArgumentParser(
|
||||||
|
"Emit opaque macro calls containing instruction attributes"
|
||||||
|
)
|
||||||
|
parser.add_argument("semantics", help="semantics file")
|
||||||
|
parser.add_argument("out", help="output file")
|
||||||
|
args = parser.parse_args()
|
||||||
|
hex_common.read_semantics_file(args.semantics)
|
||||||
hex_common.calculate_attribs()
|
hex_common.calculate_attribs()
|
||||||
|
|
||||||
##
|
##
|
||||||
## Generate all the attributes associated with each instruction
|
## Generate all the attributes associated with each instruction
|
||||||
##
|
##
|
||||||
with open(sys.argv[-1], "w") as f:
|
with open(args.out, "w") as f:
|
||||||
for tag in hex_common.tags:
|
for tag in hex_common.tags:
|
||||||
f.write(
|
f.write(
|
||||||
f"OP_ATTRIB({tag},ATTRIBS("
|
f"OP_ATTRIB({tag},ATTRIBS("
|
||||||
|
|
|
@ -21,15 +21,22 @@ import sys
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
import hex_common
|
import hex_common
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
hex_common.read_semantics_file(sys.argv[1])
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Emit opaque macro calls with instruction names"
|
||||||
|
)
|
||||||
|
parser.add_argument("semantics", help="semantics file")
|
||||||
|
parser.add_argument("out", help="output file")
|
||||||
|
args = parser.parse_args()
|
||||||
|
hex_common.read_semantics_file(args.semantics)
|
||||||
|
|
||||||
##
|
##
|
||||||
## Generate a list of all the opcodes
|
## Generate a list of all the opcodes
|
||||||
##
|
##
|
||||||
with open(sys.argv[-1], "w") as f:
|
with open(args.out, "w") as f:
|
||||||
for tag in hex_common.tags:
|
for tag in hex_common.tags:
|
||||||
f.write(f"OPCODE({tag}),\n")
|
f.write(f"OPCODE({tag}),\n")
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import sys
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
import hex_common
|
import hex_common
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -96,11 +97,17 @@ def spacify(s):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
hex_common.read_semantics_file(sys.argv[1])
|
parser = argparse.ArgumentParser(
|
||||||
|
"Emit opaque macro calls with information for printing string representations of instrucions"
|
||||||
|
)
|
||||||
|
parser.add_argument("semantics", help="semantics file")
|
||||||
|
parser.add_argument("out", help="output file")
|
||||||
|
args = parser.parse_args()
|
||||||
|
hex_common.read_semantics_file(args.semantics)
|
||||||
|
|
||||||
immext_casere = re.compile(r"IMMEXT\(([A-Za-z])")
|
immext_casere = re.compile(r"IMMEXT\(([A-Za-z])")
|
||||||
|
|
||||||
with open(sys.argv[-1], "w") as f:
|
with open(args.out, "w") as f:
|
||||||
for tag in hex_common.tags:
|
for tag in hex_common.tags:
|
||||||
if not hex_common.behdict[tag]:
|
if not hex_common.behdict[tag]:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -21,15 +21,22 @@ import sys
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
import hex_common
|
import hex_common
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
hex_common.read_semantics_file(sys.argv[1])
|
parser = argparse.ArgumentParser(
|
||||||
|
"Emit opaque macro calls with instruction semantics"
|
||||||
|
)
|
||||||
|
parser.add_argument("semantics", help="semantics file")
|
||||||
|
parser.add_argument("out", help="output file")
|
||||||
|
args = parser.parse_args()
|
||||||
|
hex_common.read_semantics_file(args.semantics)
|
||||||
hex_common.calculate_attribs()
|
hex_common.calculate_attribs()
|
||||||
tagregs = hex_common.get_tagregs()
|
tagregs = hex_common.get_tagregs()
|
||||||
tagimms = hex_common.get_tagimms()
|
tagimms = hex_common.get_tagimms()
|
||||||
|
|
||||||
with open(sys.argv[-1], "w") as f:
|
with open(args.out, "w") as f:
|
||||||
f.write("#ifndef HEXAGON_FUNC_TABLE_H\n")
|
f.write("#ifndef HEXAGON_FUNC_TABLE_H\n")
|
||||||
f.write("#define HEXAGON_FUNC_TABLE_H\n\n")
|
f.write("#define HEXAGON_FUNC_TABLE_H\n\n")
|
||||||
|
|
||||||
|
|
|
@ -108,15 +108,16 @@ def gen_def_tcg_func(f, tag, tagregs, tagimms):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
is_idef_parser_enabled = hex_common.read_common_files()
|
args = hex_common.parse_common_args(
|
||||||
|
"Emit functions calling generated code implementing instruction semantics (helpers, idef-parser)"
|
||||||
|
)
|
||||||
tagregs = hex_common.get_tagregs()
|
tagregs = hex_common.get_tagregs()
|
||||||
tagimms = hex_common.get_tagimms()
|
tagimms = hex_common.get_tagimms()
|
||||||
|
|
||||||
output_file = sys.argv[-1]
|
with open(args.out, "w") as f:
|
||||||
with open(output_file, "w") as f:
|
|
||||||
f.write("#ifndef HEXAGON_TCG_FUNCS_H\n")
|
f.write("#ifndef HEXAGON_TCG_FUNCS_H\n")
|
||||||
f.write("#define HEXAGON_TCG_FUNCS_H\n\n")
|
f.write("#define HEXAGON_TCG_FUNCS_H\n\n")
|
||||||
if is_idef_parser_enabled:
|
if args.idef_parser:
|
||||||
f.write('#include "idef-generated-emitter.h.inc"\n\n')
|
f.write('#include "idef-generated-emitter.h.inc"\n\n')
|
||||||
|
|
||||||
for tag in hex_common.tags:
|
for tag in hex_common.tags:
|
||||||
|
|
|
@ -24,6 +24,7 @@ import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
import iset
|
import iset
|
||||||
import hex_common
|
import hex_common
|
||||||
|
import argparse
|
||||||
|
|
||||||
encs = {
|
encs = {
|
||||||
tag: "".join(reversed(iset.iset[tag]["enc"].replace(" ", "")))
|
tag: "".join(reversed(iset.iset[tag]["enc"].replace(" ", "")))
|
||||||
|
@ -136,8 +137,19 @@ def gen_trans_funcs(f):
|
||||||
"""))
|
"""))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
hex_common.read_semantics_file(sys.argv[1])
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Emit trans_*() functions to be called by " \
|
||||||
|
"instruction decoder"
|
||||||
|
)
|
||||||
|
parser.add_argument("semantics", help="semantics file")
|
||||||
|
parser.add_argument("out", help="output file")
|
||||||
|
args = parser.parse_args()
|
||||||
|
hex_common.read_semantics_file(args.semantics)
|
||||||
hex_common.init_registers()
|
hex_common.init_registers()
|
||||||
with open(sys.argv[2], "w") as f:
|
with open(args.out, "w") as f:
|
||||||
gen_trans_funcs(f)
|
gen_trans_funcs(f)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
@ -21,6 +21,7 @@ import sys
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import argparse
|
||||||
|
|
||||||
behdict = {} # tag ->behavior
|
behdict = {} # tag ->behavior
|
||||||
semdict = {} # tag -> semantics
|
semdict = {} # tag -> semantics
|
||||||
|
@ -1181,22 +1182,20 @@ def helper_args(tag, regs, imms):
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def read_common_files():
|
def parse_common_args(desc):
|
||||||
read_semantics_file(sys.argv[1])
|
parser = argparse.ArgumentParser(desc)
|
||||||
read_overrides_file(sys.argv[2])
|
parser.add_argument("semantics", help="semantics file")
|
||||||
read_overrides_file(sys.argv[3])
|
parser.add_argument("overrides", help="overrides file")
|
||||||
## Whether or not idef-parser is enabled is
|
parser.add_argument("overrides_vec", help="vector overrides file")
|
||||||
## determined by the number of arguments to
|
parser.add_argument("out", help="output file")
|
||||||
## this script:
|
parser.add_argument("--idef-parser",
|
||||||
##
|
help="file of instructions translated by idef-parser")
|
||||||
## 4 args. -> not enabled,
|
args = parser.parse_args()
|
||||||
## 5 args. -> idef-parser enabled.
|
read_semantics_file(args.semantics)
|
||||||
##
|
read_overrides_file(args.overrides)
|
||||||
## The 5:th arg. then holds a list of the successfully
|
read_overrides_file(args.overrides_vec)
|
||||||
## parsed instructions.
|
if args.idef_parser:
|
||||||
is_idef_parser_enabled = len(sys.argv) > 5
|
read_idef_parser_enabled_file(args.idef_parser)
|
||||||
if is_idef_parser_enabled:
|
|
||||||
read_idef_parser_enabled_file(sys.argv[4])
|
|
||||||
calculate_attribs()
|
calculate_attribs()
|
||||||
init_registers()
|
init_registers()
|
||||||
return is_idef_parser_enabled
|
return args
|
||||||
|
|
|
@ -346,7 +346,7 @@ if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
|
||||||
# Setup input and dependencies for the next step, this depends on whether or
|
# Setup input and dependencies for the next step, this depends on whether or
|
||||||
# not idef-parser is enabled
|
# not idef-parser is enabled
|
||||||
helper_dep = [semantics_generated, idef_generated_tcg_c, idef_generated_tcg]
|
helper_dep = [semantics_generated, idef_generated_tcg_c, idef_generated_tcg]
|
||||||
helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h, idef_generated_list]
|
helper_in = [semantics_generated, gen_tcg_h, gen_tcg_hvx_h, '--idef-parser', idef_generated_list]
|
||||||
else
|
else
|
||||||
# Setup input and dependencies for the next step, this depends on whether or
|
# Setup input and dependencies for the next step, this depends on whether or
|
||||||
# not idef-parser is enabled
|
# not idef-parser is enabled
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue