From 660a1004db4683c6fa2618ce2b81e4d464d4b3d1 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Thu, 9 Jun 2022 20:27:12 +0800 Subject: update Go generator (#124) --- parse.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/parse.py b/parse.py index 97961e2..5bc7b26 100755 --- a/parse.py +++ b/parse.py @@ -838,8 +838,11 @@ def make_c(instr_dict): enc_file.close() def make_go(instr_dict): - prelude = '''// Code generated by parse_opcodes -go; DO NOT EDIT. + args = " ".join(sys.argv) + prelude = f'''// Code generated by {args}; DO NOT EDIT.''' + + prelude += ''' package riscv import "cmd/internal/obj" @@ -855,10 +858,12 @@ type inst struct { func encode(a obj.As) *inst { switch a { ''' + endoffile = ''' } return nil } ''' + instr_str = '' for i in instr_dict: enc_match = int(instr_dict[i]['match'],0) @@ -876,6 +881,12 @@ func encode(a obj.As) *inst { file.write(instr_str) file.write(endoffile) + try: + import subprocess + subprocess.run(["go", "fmt", "inst.go"]) + except: + pass + def signed(value, width): if 0 <= value < (1<<(width-1)): return value @@ -891,7 +902,12 @@ if __name__ == "__main__": if i in extensions: extensions.remove(i) print(f'Extensions selected : {extensions}') - instr_dict = create_inst_dict(extensions) + + include_pseudo = False + if "-go" in sys.argv[1:]: + include_pseudo = True + + instr_dict = create_inst_dict(extensions, include_pseudo) with open('instr_dict.yaml', 'w') as outfile: yaml.dump(instr_dict, outfile, default_flow_style=False) instr_dict = collections.OrderedDict(sorted(instr_dict.items())) -- cgit v1.1