From b307dca0dcf4fd9be9ddc5c80ead64f12d37c393 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Thu, 21 Jan 2016 15:21:36 -0500 Subject: Support generating Go code Generate Go code for the RISC-V Go port . --- parse-opcodes | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'parse-opcodes') diff --git a/parse-opcodes b/parse-opcodes index ffc1f07..c5427d2 100755 --- a/parse-opcodes +++ b/parse-opcodes @@ -4,6 +4,35 @@ import math import sys import tokenize +# Instructions not used by the RISC-V Go port (and which should therefore not be +# emitted). +GO_UNUSED_INSTRUCTIONS = set(( + 'addiw', + 'csrrc', + 'csrrci', + 'csrrs', + 'csrrsi', + 'csrrw', + 'csrrwi', + 'ebreak', + 'ecall', + 'eret', + 'fcvt.d.s', + 'fcvt.s.d', + 'fsgnjx.d', + 'fsgnjx.s', + 'hrts', + 'lw', + 'mrth', + 'mrts', + 'sfence.vm', + 'slli.rv32', + 'srai.rv32', + 'sret', + 'srli.rv32', + 'wfi', +)) + namelist = [] match = {} mask = {} @@ -767,6 +796,27 @@ def make_chisel(): print ' }' print '}' +def print_go_insn(name): + print '\tcase A%s:' % name.upper().replace('.', '') + print '\t\treturn 0x%x' % yank(match[name], 0, 7) + +def make_go(): + print '// Automatically generated by parse-opcodes' + print + print 'package riscv' + print + print 'import "log"' + print + print 'func opcode(a int) uint32 {' + print '\tswitch a {' + for name in namelist: + if name not in GO_UNUSED_INSTRUCTIONS: + print_go_insn(name) + print '\t}' + print '\tlog.Fatalf("opcode: missing %v (bug in parse-opcodes)", a)' + print '\treturn 0' + print '}' + for line in sys.stdin: line = line.partition('#') tokens = line[0].split() @@ -840,5 +890,7 @@ elif sys.argv[1] == '-chisel': make_chisel() elif sys.argv[1] == '-c': make_c(match,mask) +elif sys.argv[1] == '-go': + make_go() else: assert 0 -- cgit v1.2.3