diff options
Diffstat (limited to 'parse-opcodes')
-rwxr-xr-x | parse-opcodes | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/parse-opcodes b/parse-opcodes index 0437480..2a5de5b 100755 --- a/parse-opcodes +++ b/parse-opcodes @@ -824,6 +824,45 @@ def make_chisel(): print ' }' print '}' +def signed(value, width): + if 0 <= value < (1<<(width-1)): + return value + else: + return value - (1<<width) + +def print_go_insn(name): + print '\tcase A%s:' % name.upper().replace('.', '') + m = match[name] + opcode = yank(m, 0, 7) + funct3 = yank(m, 12, 3) + rs2 = yank(m, 20, 5) + csr = yank(m, 20, 12) + funct7 = yank(m, 25, 7) + print '\t\treturn &inst{0x%x, 0x%x, 0x%x, %d, 0x%x}, true' % (opcode, funct3, rs2, signed(csr, 12), funct7) + +def make_go(): + print '// Automatically generated by parse-opcodes' + print + print 'package riscv' + print + print 'import "cmd/internal/obj"' + print + print 'type inst struct {' + print '\topcode uint32' + print '\tfunct3 uint32' + print '\trs2 uint32' + print '\tcsr int64' + print '\tfunct7 uint32' + print '}' + print + print 'func encode(a obj.As) (i *inst, ok bool) {' + print '\tswitch a {' + for name in namelist: + print_go_insn(name) + print '\t}' + print '\treturn nil, false' + print '}' + for line in sys.stdin: line = line.partition('#') tokens = line[0].split() @@ -897,5 +936,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 |