diff options
author | Meng Zhuo <mengzhuo@users.noreply.github.com> | 2022-06-09 20:27:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-09 05:27:12 -0700 |
commit | 660a1004db4683c6fa2618ce2b81e4d464d4b3d1 (patch) | |
tree | 2bda27ee53327c65bb0b00c2c6b48f87b7d0e4cf | |
parent | 2bc227547742e65ba8c64c6e6c573e49bfe72e7e (diff) | |
download | riscv-opcodes-660a1004db4683c6fa2618ce2b81e4d464d4b3d1.zip riscv-opcodes-660a1004db4683c6fa2618ce2b81e4d464d4b3d1.tar.gz riscv-opcodes-660a1004db4683c6fa2618ce2b81e4d464d4b3d1.tar.bz2 |
update Go generator (#124)
-rwxr-xr-x | parse.py | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -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())) |