Skip to content

Commit

Permalink
Add CSR support to go_utils.py
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
markdryan committed Dec 19, 2024
1 parent 9ccb8a7 commit a1e90ca
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion go_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import sys

from constants import csrs
from shared_utils import InstrDict, signed

pp = pprint.PrettyPrinter(indent=2)
Expand Down Expand Up @@ -32,9 +33,14 @@ def make_go(instr_dict: InstrDict):
switch a {
"""

endoffile = """ }
csrs_map_str = """ }
return nil
}
var csrs = map[uint16]string {
"""

endoffile = """}
"""

instr_str = ""
Expand All @@ -49,8 +55,11 @@ def make_go(instr_dict: InstrDict):
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)

0 comments on commit a1e90ca

Please sign in to comment.