diff options
-rwxr-xr-x | parse-opcodes | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/parse-opcodes b/parse-opcodes index 7d7ec2d..f336999 100755 --- a/parse-opcodes +++ b/parse-opcodes @@ -798,8 +798,12 @@ def make_chisel(): def print_go_insn(name): print '\tcase A%s:' % name.upper().replace('.', '') - # Yank bits 0-6 of the encoded instruction (i.e., the opcode) and print them. - print '\t\treturn 0x%x' % yank(match[name], 0, 7) + m = match[name] + opcode = yank(m, 0, 7) + funct3 = yank(m, 12, 3) + csr = yank(m, 20, 12) + funct7 = yank(m, 25, 7) + print '\t\treturn &inst{0x%x, 0x%x, 0x%x, 0x%x}' % (opcode, funct3, csr, funct7) def make_go(): print '// Automatically generated by parse-opcodes' @@ -808,14 +812,21 @@ def make_go(): print print 'import "log"' print - print 'func opcode(a int) uint32 {' + print 'type inst struct {' + print '\topcode uint32' + print '\tfunct3 uint32' + print '\tcsr uint32' + print '\tfunct7 uint32' + print '}' + print + print 'func encode(a int16) *inst {' 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 '\treturn nil' print '}' for line in sys.stdin: |