mirror of
https://github.com/riscv/riscv-opcodes.git
synced 2025-05-08 10:45:47 +08:00
Add CSR encodings for Go and remove call to Go fmt (#329)
* Don't run go fmt error in go_utils.py go_utils.py currently runs go fmt to pretty print the generated inst.go file. Unfortunately, this call to go fmt always fails as inst.go contains an internal import and go fmt is being run out of tree. Here we remove the code that attempts to format inst.go resulting in a clean run of go_utils.py without any errors. The generated file, inst.go, can be formatted when it's copied into the Go source tree, prior to its submission to the Golang project. * Add CSR support to go_utils.py go_utils.py now generates a Go map that maps CSR numbers to CSR names. The resulting map is written into inst.go for use by the Go assembler.
This commit is contained in:
parent
34e1d8194f
commit
3c73392134
17
go_utils.py
17
go_utils.py
@ -1,8 +1,8 @@
|
||||
import logging
|
||||
import pprint
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from constants import csrs
|
||||
from shared_utils import InstrDict, signed
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=2)
|
||||
@ -32,9 +32,14 @@ func encode(a obj.As) *inst {
|
||||
switch a {
|
||||
"""
|
||||
|
||||
endoffile = """ }
|
||||
csrs_map_str = """ }
|
||||
return nil
|
||||
}
|
||||
|
||||
var csrs = map[uint16]string {
|
||||
"""
|
||||
|
||||
endoffile = """}
|
||||
"""
|
||||
|
||||
instr_str = ""
|
||||
@ -49,13 +54,11 @@ func encode(a obj.As) *inst {
|
||||
instr_str += f""" case A{i.upper().replace("_","")}:
|
||||
return &inst{{ {hex(opcode)}, {hex(funct3)}, {hex(rs1)}, {hex(rs2)}, {signed(csr,12)}, {hex(funct7)} }}
|
||||
"""
|
||||
for num, name in sorted(csrs, key=lambda row: row[0]):
|
||||
csrs_map_str += f'{hex(num)} : "{name.upper()}",\n'
|
||||
|
||||
with open("inst.go", "w", encoding="utf-8") as file:
|
||||
file.write(prelude)
|
||||
file.write(instr_str)
|
||||
file.write(csrs_map_str)
|
||||
file.write(endoffile)
|
||||
|
||||
try:
|
||||
subprocess.run(["go", "fmt", "inst.go"], check=True)
|
||||
except: # pylint: disable=bare-except
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user