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.
This commit is contained in:
Tim Hutt
2024-11-05 14:32:12 +00:00
committed by GitHub
parent 6bb00f9056
commit 359a94356d
13 changed files with 225 additions and 163 deletions

View File

@@ -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()
)