From f86f5cb4589e5fcc15b09b5a59be9d63c51dcc6f Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Fri, 31 Mar 2017 14:43:45 -0400 Subject: Support generating Go code (#3) * Support generating Go code Generate Go code for the RISC-V Go port . * Clarify use of yank in Go backend * Go: Also generate funct3, csr, and funct7 encodings * Go: Emit all instructions Changes to the RISC-V Go implementation obviate the need for GO_UNUSED_INSTRUCTIONS. * Go: Print CSRs as signed values * Go: Update parse-opcodes to use obj.As See https://github.com/golang/go/commit/0d9258a830c585. * Go: Return errors out of band * Go: Return 'ok' status instead of 'err' status Also clean up imports. * Go: Make gofmt-clean * Go: Return rs2 value for each instructions Some binary floating-point instructions (ab)use the rs2 value to hold additional instruction data, so we need that data in the Go assembler. --- .gitignore | 1 + Makefile | 3 +++ parse-opcodes | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/.gitignore b/.gitignore index 5b578f1..9512eca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .*.swp inst.chisel +inst.go instr-table.tex priv-instr-table.tex diff --git a/Makefile b/Makefile index 5983051..3220e47 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,9 @@ $(GAS_H) $(XCC_H): $(ALL_OPCODES) parse-opcodes inst.chisel: $(ALL_OPCODES) parse-opcodes cat opcodes opcodes-custom opcodes-pseudo | ./parse-opcodes -chisel > $@ +inst.go: opcodes opcodes-pseudo parse-opcodes + cat opcodes opcodes-pseudo | ./parse-opcodes -go > $@ + instr-table.tex: $(ALL_OPCODES) parse-opcodes cat opcodes opcodes-pseudo | ./parse-opcodes -tex > $@ 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<