diff options
Diffstat (limited to 'sverilog_utils.py')
-rw-r--r-- | sverilog_utils.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/sverilog_utils.py b/sverilog_utils.py new file mode 100644 index 0000000..d2b26b6 --- /dev/null +++ b/sverilog_utils.py @@ -0,0 +1,30 @@ +import logging +import pprint +from pathlib import Path + +from constants import csrs, csrs32 +from shared_utils import InstrDict + +pp = pprint.PrettyPrinter(indent=2) +logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s") + + +def make_sverilog(instr_dict: InstrDict): + names_str = "" + for i in instr_dict: + names_str += f" localparam [31:0] {i.upper().replace('.','_'):<18s} = 32'b{instr_dict[i]['encoding'].replace('-','?')};\n" + names_str += " /* CSR Addresses */\n" + for num, name in csrs + csrs32: + names_str += ( + f" localparam logic [11:0] CSR_{name.upper()} = 12'h{hex(num)[2:]};\n" + ) + + Path("inst.sverilog").write_text( + f""" +/* Automatically generated by parse_opcodes */ +package riscv_instr; +{names_str} +endpackage +""", + encoding="utf-8", + ) |