diff options
Diffstat (limited to 'chisel_utils.py')
-rw-r--r-- | chisel_utils.py | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/chisel_utils.py b/chisel_utils.py index 9916b76..34f6ac3 100644 --- a/chisel_utils.py +++ b/chisel_utils.py @@ -1,10 +1,8 @@ import logging import pprint -from constants import * - -# from shared_utils import overlaps, overlap_allowed, extension_overlap_allowed, instruction_overlap_allowed, process_enc_line, same_base_isa, add_segmented_vls_insn, expand_nf_field -from shared_utils import * +from constants import causes, csrs, csrs32 +from shared_utils import InstrDict, instr_dict_2_extensions pp = pprint.PrettyPrinter(indent=2) logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s") @@ -23,7 +21,6 @@ def make_chisel(instr_dict: InstrDict, spinal_hdl: bool = False): if not spinal_hdl: extensions = instr_dict_2_extensions(instr_dict) for e in extensions: - e_instrs = filter(lambda i: instr_dict[i]["extension"][0] == e, instr_dict) if "rv64_" in e: e_format = e.replace("rv64_", "").upper() + "64" elif "rv32_" in e: @@ -33,10 +30,11 @@ def make_chisel(instr_dict: InstrDict, spinal_hdl: bool = False): else: e_format = e.upper() chisel_names += f' val {e_format+"Type"} = Map(\n' - for instr in e_instrs: - tmp_instr_name = '"' + instr.upper().replace(".", "_") + '"' - chisel_names += f' {tmp_instr_name:<18s} -> BitPat("b{instr_dict[instr]["encoding"].replace("-","?")}"),\n' - chisel_names += f" )\n" + for instr_name, instr in instr_dict.items(): + if instr["extension"][0] == e: + tmp_instr_name = '"' + instr_name.upper().replace(".", "_") + '"' + chisel_names += f' {tmp_instr_name:<18s} -> BitPat("b{instr["encoding"].replace("-","?")}"),\n' + chisel_names += " )\n" for num, name in causes: cause_names_str += f' val {name.lower().replace(" ","_")} = {hex(num)}\n' @@ -65,12 +63,11 @@ def make_chisel(instr_dict: InstrDict, spinal_hdl: bool = False): csr_names_str += """ res.toArray }""" - if spinal_hdl: - chisel_file = open("inst.spinalhdl", "w") - else: - chisel_file = open("inst.chisel", "w") - chisel_file.write( - f""" + with open( + "inst.spinalhdl" if spinal_hdl else "inst.chisel", "w", encoding="utf-8" + ) as chisel_file: + chisel_file.write( + f""" /* Automatically generated by parse_opcodes */ object Instructions {{ {chisel_names} @@ -82,5 +79,4 @@ object CSRs {{ {csr_names_str} }} """ - ) - chisel_file.close() + ) |