From 556c881376b21c27e7fa11a7847552aa219a7d7d Mon Sep 17 00:00:00 2001 From: Philipp van Kempen Date: Fri, 1 Mar 2024 12:31:41 +0100 Subject: [PATCH] more linting --- seal5/backends/coredsl2/writer.py | 2 +- seal5/backends/riscv_gisel_legalizer/writer.py | 2 +- seal5/backends/viewer_seal5/treegen.py | 4 ++-- seal5/backends/viewer_seal5/utils.py | 12 +----------- seal5/backends/viewer_seal5/viewer.py | 6 +++--- seal5/flow.py | 5 +++-- .../coredsl2_seal5/architecture_model_builder.py | 6 +++--- .../coredsl2_seal5/behavior_model_builder.py | 6 +++--- seal5/frontends/coredsl2_seal5/expr_interpreter.py | 1 - seal5/frontends/coredsl2_seal5/load_order.py | 2 +- seal5/frontends/coredsl2_seal5/parser.py | 10 ++++++---- seal5/resources/lit.cfg.py | 8 -------- seal5/settings.py | 3 ++- seal5/transform/detect_inouts/visitor.py | 2 +- seal5/transform/detect_side_effects/visitor.py | 1 - seal5/transform/eliminate_mod_rfs/visitor.py | 2 +- seal5/transform/eliminate_rd_cmp_zero/visitor.py | 2 +- seal5/transform/explicit_truncations/visitor.py | 2 +- seal5/transform/filter_model/filter.py | 1 - seal5/transform/infer_types/visitor.py | 11 +++++------ seal5/transform/process_settings/transform.py | 2 +- seal5/transform/simplify_trivial_slices/visitor.py | 5 +++-- 22 files changed, 39 insertions(+), 56 deletions(-) diff --git a/seal5/backends/coredsl2/writer.py b/seal5/backends/coredsl2/writer.py index 7397376d..ea0cc5db 100644 --- a/seal5/backends/coredsl2/writer.py +++ b/seal5/backends/coredsl2/writer.py @@ -16,7 +16,7 @@ from typing import Union from . import visitor -from m2isar.metamodel import arch, patch_model, behav +from m2isar.metamodel import arch, patch_model logger = logging.getLogger("coredsl2_writer") diff --git a/seal5/backends/riscv_gisel_legalizer/writer.py b/seal5/backends/riscv_gisel_legalizer/writer.py index cab69070..00b5de99 100644 --- a/seal5/backends/riscv_gisel_legalizer/writer.py +++ b/seal5/backends/riscv_gisel_legalizer/writer.py @@ -17,7 +17,7 @@ from m2isar.metamodel import arch from seal5.index import NamedPatch, write_index_yaml -from seal5.settings import ExtensionsSettings, RISCVLegalizerSettings +from seal5.settings import RISCVLegalizerSettings logger = logging.getLogger("riscv_gisel_legalizer") diff --git a/seal5/backends/viewer_seal5/treegen.py b/seal5/backends/viewer_seal5/treegen.py index aaac0746..6800cfd4 100644 --- a/seal5/backends/viewer_seal5/treegen.py +++ b/seal5/backends/viewer_seal5/treegen.py @@ -8,9 +8,9 @@ """Generate a ttk.Treeview representation of a M2-ISA-R model structure.""" -import tkinter as tk +# import tkinter as tk -from ...metamodel import arch, behav +from ...metamodel import behav from .utils import TreeGenContext # pylint: disable=unused-argument diff --git a/seal5/backends/viewer_seal5/utils.py b/seal5/backends/viewer_seal5/utils.py index c30731d5..4de68f63 100644 --- a/seal5/backends/viewer_seal5/utils.py +++ b/seal5/backends/viewer_seal5/utils.py @@ -9,23 +9,13 @@ """Utility stuff for M2-ISA-R viewer""" from typing import TYPE_CHECKING -from anytree import Node, RenderTree +from anytree import Node if TYPE_CHECKING: import tkinter as tk from tkinter import ttk -class TreeGenContext: - """Data keeping class for recursive TreeView generation""" - - def push(self, new_id): - self.parent_stack.append(new_id) - - def pop(self): - return self.parent_stack.pop() - - class TreeGenContext: def __init__(self, parent=None) -> None: if parent: diff --git a/seal5/backends/viewer_seal5/viewer.py b/seal5/backends/viewer_seal5/viewer.py index 9b116b58..be702693 100644 --- a/seal5/backends/viewer_seal5/viewer.py +++ b/seal5/backends/viewer_seal5/viewer.py @@ -20,7 +20,6 @@ from m2isar.backends.viewer_seal5.utils import TkTreeGenContext, TextTreeGenContext from ...metamodel import arch, patch_model -from ...metamodel.utils.expr_preprocessor import process_attributes, process_functions, process_instructions from . import treegen logger = logging.getLogger("viewer") @@ -105,7 +104,8 @@ def main(): if args.text: set_node = Node("Set", parent=sets_node, value=set_name) # add constants to tree - consts_node = Node("Constants", parent=set_node) + # consts_node = Node("Constants", parent=set_node) + # TODO else: set_id = tree.insert("", tk.END, text=set_name) @@ -304,7 +304,7 @@ def main(): if args.text: print("============================") - text = "" + # text = "" for pre, fill, node in RenderTree(root): suffix = "" if hasattr(node, "value"): diff --git a/seal5/flow.py b/seal5/flow.py index 6d4ae547..6dcf2078 100644 --- a/seal5/flow.py +++ b/seal5/flow.py @@ -311,7 +311,6 @@ def setup( "LLVM_TARGETS_TO_BUILD": ["RISCV"], } ) - # llvm_config = LLVMConfig(options={"CMAKE_BUILD_TYPE": "Debug", "LLVM_BUILD_TOOLS": False, "LLVM_ENABLE_ASSERTIONS": False, "LLVM_OPTIMIZED_TABLEGEN": True, "LLVM_ENABLE_PROJECT": [], "LLVM_TARGETS_TO_BUILD": ["RISCV"]}) cmake_options = llvm_config.options cdsl2llvm.build_pattern_gen( self.deps_dir / "cdsl2llvm", @@ -1300,7 +1299,9 @@ def gen_riscv_gisel_legalizer_patch(self, verbose: bool = False): # if ext is None: # fallback to set_name # ext = set_name.replace("_", "") # try: - # cdsl2llvm.run_pattern_gen(self.deps_dir / "cdsl2llvm" / "llvm" / "build", input_file, output_file, skip_patterns=False, skip_formats=False, ext=ext) + # cdsl2llvm.run_pattern_gen(self.deps_dir / "cdsl2llvm" / "llvm" / "build", + # input_file, output_file, + # skip_patterns=False, skip_formats=False, ext=ext) # except AssertionError: # pass # # errs.append((insn_name, str(ex))) diff --git a/seal5/frontends/coredsl2_seal5/architecture_model_builder.py b/seal5/frontends/coredsl2_seal5/architecture_model_builder.py index c086470e..2261632d 100644 --- a/seal5/frontends/coredsl2_seal5/architecture_model_builder.py +++ b/seal5/frontends/coredsl2_seal5/architecture_model_builder.py @@ -247,12 +247,12 @@ def visitParameter_declaration(self, ctx: CoreDSL2Parser.Parameter_declarationCo # type is required, name and array size optional type_ = self.visit(ctx.type_) name = None - size = None + # size = None if ctx.decl: if ctx.decl.name: name = ctx.decl.name.text if ctx.decl.size: - size = [self.visit(obj) for obj in ctx.decl.size] + ctx.decl.size = [self.visit(obj) for obj in ctx.decl.size] p = arch.FnParam(name, type_._width, arch.DataType.S if type_.signed else arch.DataType.U) return p @@ -292,7 +292,7 @@ def visitDeclaration(self, ctx: CoreDSL2Parser.DeclarationContext): # extract storage type, qualifiers and attributes storage = [self.visit(obj) for obj in ctx.storage] - qualifiers = [self.visit(obj) for obj in ctx.qualifiers] + ctx.qualifiers = [self.visit(obj) for obj in ctx.qualifiers] attributes = dict([self.visit(obj) for obj in ctx.attributes]) # extract data type diff --git a/seal5/frontends/coredsl2_seal5/behavior_model_builder.py b/seal5/frontends/coredsl2_seal5/behavior_model_builder.py index 551f3d5c..4c978ffb 100644 --- a/seal5/frontends/coredsl2_seal5/behavior_model_builder.py +++ b/seal5/frontends/coredsl2_seal5/behavior_model_builder.py @@ -108,9 +108,9 @@ def visitDeclaration(self, ctx: CoreDSL2Parser.DeclarationContext): """ # extract variable qualifiers, currently unused - storage = [self.visit(obj) for obj in ctx.storage] - qualifiers = [self.visit(obj) for obj in ctx.qualifiers] - attributes = [self.visit(obj) for obj in ctx.attributes] + # storage = [self.visit(obj) for obj in ctx.storage] + # qualifiers = [self.visit(obj) for obj in ctx.qualifiers] + # attributes = [self.visit(obj) for obj in ctx.attributes] type_ = self.visit(ctx.type_) diff --git a/seal5/frontends/coredsl2_seal5/expr_interpreter.py b/seal5/frontends/coredsl2_seal5/expr_interpreter.py index 34ea365e..bdb9b5d5 100644 --- a/seal5/frontends/coredsl2_seal5/expr_interpreter.py +++ b/seal5/frontends/coredsl2_seal5/expr_interpreter.py @@ -8,7 +8,6 @@ """Very crude expression evaluation functions for use during model generation.""" -from m2isar import M2ValueError from m2isar.metamodel import arch, behav diff --git a/seal5/frontends/coredsl2_seal5/load_order.py b/seal5/frontends/coredsl2_seal5/load_order.py index 71d4162d..534d7b3f 100644 --- a/seal5/frontends/coredsl2_seal5/load_order.py +++ b/seal5/frontends/coredsl2_seal5/load_order.py @@ -8,7 +8,7 @@ from antlr4 import ParserRuleContext -from m2isar import M2DuplicateError, M2NameError +from m2isar import M2DuplicateError from .parser_gen import CoreDSL2Parser, CoreDSL2Visitor diff --git a/seal5/frontends/coredsl2_seal5/parser.py b/seal5/frontends/coredsl2_seal5/parser.py index 1d6caf69..b65c7b3d 100644 --- a/seal5/frontends/coredsl2_seal5/parser.py +++ b/seal5/frontends/coredsl2_seal5/parser.py @@ -31,7 +31,7 @@ def main(): args = parser.parse_args() - app_dir = pathlib.Path(__file__).parent.resolve() + # app_dir = pathlib.Path(__file__).parent.resolve() logging.basicConfig(level=getattr(logging, args.log.upper())) logger = logging.getLogger("parser") @@ -68,7 +68,7 @@ def main(): temp_save = {} # models: "dict[str, arch.CoreDef]" = {} - models: "dict[str arch.InstructionSet]" = {} + models: "dict[str, arch.InstructionSet]" = {} patch_model(expr_interpreter) @@ -81,7 +81,7 @@ def main(): s = [s] print("s", s) except M2Error as e: - logger.critical("Error building architecture model of core %s: %s", core_name, e) + logger.critical("Error building architecture model of core", e) for orig, overwritten in arch_builder._overwritten_instrs: logger.warning( @@ -150,7 +150,9 @@ def main(): op = behav_builder.visit(attr_op) ops.append(op) except M2Error as e: - logger.critical('error processing attribute "%s" of memory "%s": %s', attr_name, fn_def.name, e) + logger.critical( + 'error processing attribute "%s" of memory "%s": %s', attr_name, mem_def.name, e + ) sys.exit(1) mem_def.attributes[attr_name] = ops diff --git a/seal5/resources/lit.cfg.py b/seal5/resources/lit.cfg.py index 94f8f264..c5d61933 100644 --- a/seal5/resources/lit.cfg.py +++ b/seal5/resources/lit.cfg.py @@ -2,17 +2,9 @@ # Configuration file for the 'lit' test runner. -import os -import sys -import re -import platform -import subprocess - import lit.util import lit.formats from lit.llvm import llvm_config -from lit.llvm.subst import FindTool -from lit.llvm.subst import ToolSubst # name: The name of this test suite. config.name = "LLVM" diff --git a/seal5/settings.py b/seal5/settings.py index a714cdd0..7d2366eb 100644 --- a/seal5/settings.py +++ b/seal5/settings.py @@ -468,7 +468,8 @@ class RISCVSettings(YAMLSettings): features: Optional[List[str]] = None # Used for baseline extensions, tune and legalizer + pattern gen # default: zicsr,m,(32/64bit),fast-unaligned-access - # others: zmmul,a,f,d,zfh,zfinx,zdinx,c,zba,zbb,zbc,zbs,zca,zcb,zcd,zcmp,zce,e,no-optimized-zero-stride-load,no-default-unroll,... + # others: zmmul,a,f,d,zfh,zfinx,zdinx,c,zba,zbb,zbc,zbs,zca,zcb,zcd + # zcmp,zce,e,no-optimized-zero-stride-load,no-default-unroll,... transform_info: Optional[Dict[str, Optional[Union[bool, int]]]] = None # options: see ttiimpl_notes.txt # TODO: processor/pipeline/mcpu/tune -> ProcessorSettings diff --git a/seal5/transform/detect_inouts/visitor.py b/seal5/transform/detect_inouts/visitor.py index ddfad266..82438c60 100644 --- a/seal5/transform/detect_inouts/visitor.py +++ b/seal5/transform/detect_inouts/visitor.py @@ -8,7 +8,7 @@ """TODO""" -from m2isar.metamodel import arch, behav +from m2isar.metamodel import behav # pylint: disable=unused-argument diff --git a/seal5/transform/detect_side_effects/visitor.py b/seal5/transform/detect_side_effects/visitor.py index 2ea077a7..82259725 100644 --- a/seal5/transform/detect_side_effects/visitor.py +++ b/seal5/transform/detect_side_effects/visitor.py @@ -8,7 +8,6 @@ """TODO""" -from m2isar import flatten from m2isar.metamodel import arch, behav # pylint: disable=unused-argument diff --git a/seal5/transform/eliminate_mod_rfs/visitor.py b/seal5/transform/eliminate_mod_rfs/visitor.py index b9b8a1d2..60ff4e69 100644 --- a/seal5/transform/eliminate_mod_rfs/visitor.py +++ b/seal5/transform/eliminate_mod_rfs/visitor.py @@ -8,7 +8,7 @@ """TODO""" -from m2isar.metamodel import arch, behav +from m2isar.metamodel import behav # pylint: disable=unused-argument diff --git a/seal5/transform/eliminate_rd_cmp_zero/visitor.py b/seal5/transform/eliminate_rd_cmp_zero/visitor.py index 210a51a4..dcf19244 100644 --- a/seal5/transform/eliminate_rd_cmp_zero/visitor.py +++ b/seal5/transform/eliminate_rd_cmp_zero/visitor.py @@ -8,7 +8,7 @@ """TODO""" -from m2isar.metamodel import arch, behav +from m2isar.metamodel import behav # pylint: disable=unused-argument diff --git a/seal5/transform/explicit_truncations/visitor.py b/seal5/transform/explicit_truncations/visitor.py index 37df7dbe..29e63c80 100644 --- a/seal5/transform/explicit_truncations/visitor.py +++ b/seal5/transform/explicit_truncations/visitor.py @@ -20,10 +20,10 @@ type directly to the :class:`IntLiteral` and discard the type conversion """ import logging +from m2isar.metamodel import behav logger = logging.getLogger(__name__) -from m2isar.metamodel import arch, behav # pylint: disable=unused-argument diff --git a/seal5/transform/filter_model/filter.py b/seal5/transform/filter_model/filter.py index f4a3766f..e1acbea8 100644 --- a/seal5/transform/filter_model/filter.py +++ b/seal5/transform/filter_model/filter.py @@ -182,7 +182,6 @@ def opcodes_helper(x): # input("456") def check_filter(name, keep, drop): - print("check_filter", name, keep, drop) if drop and keep: return name not in drop and name in keep elif keep: diff --git a/seal5/transform/infer_types/visitor.py b/seal5/transform/infer_types/visitor.py index 8f3ffbcb..c492fbfa 100644 --- a/seal5/transform/infer_types/visitor.py +++ b/seal5/transform/infer_types/visitor.py @@ -20,13 +20,12 @@ type directly to the :class:`IntLiteral` and discard the type conversion """ import logging - -logger = logging.getLogger(__name__) - from copy import copy from m2isar.metamodel import arch, behav +logger = logging.getLogger(__name__) + # pylint: disable=unused-argument @@ -151,12 +150,12 @@ def slice_operation(self: behav.SliceOperation, context): if not isinstance(self.left, behav.IntLiteral): logger.warning("Can not infer type of non-static slice operation. Skipping...") return self - l = self.left.value + lval = self.left.value if not isinstance(self.right, behav.IntLiteral): logger.warning("Can not infer type of non-static slice operation. Skipping...") return self - r = self.right.value - width = l - r + 1 if l > r else r - l + 1 + rval = self.right.value + width = lval - rval + 1 if lval > rval else rval - lval + 1 ty_ = copy(ty) ty_._width = width self.inferred_type = ty_ diff --git a/seal5/transform/process_settings/transform.py b/seal5/transform/process_settings/transform.py index ed3e219c..e761a928 100644 --- a/seal5/transform/process_settings/transform.py +++ b/seal5/transform/process_settings/transform.py @@ -14,7 +14,7 @@ import pickle from typing import Union -from m2isar.metamodel import arch, patch_model +from m2isar.metamodel import arch from seal5.settings import Seal5Settings, ExtensionsSettings diff --git a/seal5/transform/simplify_trivial_slices/visitor.py b/seal5/transform/simplify_trivial_slices/visitor.py index aaf54768..b9f1c9fa 100644 --- a/seal5/transform/simplify_trivial_slices/visitor.py +++ b/seal5/transform/simplify_trivial_slices/visitor.py @@ -20,10 +20,10 @@ type directly to the :class:`IntLiteral` and discard the type conversion """ import logging +from m2isar.metamodel import arch, behav logger = logging.getLogger(__name__) -from m2isar.metamodel import arch, behav # pylint: disable=unused-argument @@ -77,7 +77,8 @@ def slice_operation(self: behav.SliceOperation, context): return behav.Group(self.expr) # if self.right.value == 0: - # return behav.TypeConv(arch.DataType.S if self.expr.inferred_type.signed else arch.DataType.U, target_width, self.expr) + # return behav.TypeConv(arch.DataType.S if self.expr.inferred_type.signed + # else arch.DataType.U, target_width, self.expr) return self