Skip to content

Commit

Permalink
update Go generator (riscv#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengzhuo authored Jun 9, 2022
1 parent 2bc2275 commit 660a100
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -855,10 +858,12 @@ def make_go(instr_dict):
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)
Expand All @@ -876,6 +881,12 @@ def make_go(instr_dict):
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
Expand All @@ -891,7 +902,12 @@ def signed(value, width):
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()))
Expand Down

0 comments on commit 660a100

Please sign in to comment.