aboutsummaryrefslogtreecommitdiff
path: root/chisel_utils.py
diff options
context:
space:
mode:
authorTim Hutt <timothy.hutt@codasip.com>2024-11-05 14:32:12 +0000
committerGitHub <noreply@github.com>2024-11-05 06:32:12 -0800
commit359a94356dba415cbd945e56126a326c59878e56 (patch)
treea1cbe073146a64c049db60f615acf6e1c2a94ad8 /chisel_utils.py
parent6bb00f9056db133a1bea48d2377316f49fb187df (diff)
downloadriscv-opcodes-359a94356dba415cbd945e56126a326c59878e56.zip
riscv-opcodes-359a94356dba415cbd945e56126a326c59878e56.tar.gz
riscv-opcodes-359a94356dba415cbd945e56126a326c59878e56.tar.bz2
Enable Pylint in CI and fix its errors (#311)
* Remove wildcard imports Use explicit imports rather than wildcards. This is more maintainable. * Enable Pylint in CI and fix its errors The main fixes were: * Specify encoding for all file opens. By default it depends on environment variables which is bad. * Use `with` to open files. Otherwise they don't necessarily get closed. There were also a few minor things like using `enumerate`, not using objects as default arguments, etc. In some cases I slightly refactored the code.
Diffstat (limited to 'chisel_utils.py')
-rw-r--r--chisel_utils.py30
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()
+ )