Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSR encodings for Go and remove call to Go fmt #329

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions go_utils.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -32,9 +32,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,13 +54,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)

try:
subprocess.run(["go", "fmt", "inst.go"], check=True)
except: # pylint: disable=bare-except
pass
Loading