Skip to content

Commit

Permalink
more linting
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippvK committed Mar 1, 2024
1 parent 47a441f commit 556c881
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 56 deletions.
2 changes: 1 addition & 1 deletion seal5/backends/coredsl2/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion seal5/backends/riscv_gisel_legalizer/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions seal5/backends/viewer_seal5/treegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions seal5/backends/viewer_seal5/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions seal5/backends/viewer_seal5/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -304,7 +304,7 @@ def main():

if args.text:
print("============================")
text = ""
# text = ""
for pre, fill, node in RenderTree(root):
suffix = ""
if hasattr(node, "value"):
Expand Down
5 changes: 3 additions & 2 deletions seal5/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)))
Expand Down
6 changes: 3 additions & 3 deletions seal5/frontends/coredsl2_seal5/architecture_model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions seal5/frontends/coredsl2_seal5/behavior_model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_)

Expand Down
1 change: 0 additions & 1 deletion seal5/frontends/coredsl2_seal5/expr_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

"""Very crude expression evaluation functions for use during model generation."""

from m2isar import M2ValueError
from m2isar.metamodel import arch, behav


Expand Down
2 changes: 1 addition & 1 deletion seal5/frontends/coredsl2_seal5/load_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from antlr4 import ParserRuleContext

from m2isar import M2DuplicateError, M2NameError
from m2isar import M2DuplicateError
from .parser_gen import CoreDSL2Parser, CoreDSL2Visitor


Expand Down
10 changes: 6 additions & 4 deletions seal5/frontends/coredsl2_seal5/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions seal5/resources/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 7 in seal5/resources/lit.cfg.py

View workflow job for this annotation

GitHub Actions / Flake8

seal5/resources/lit.cfg.py#L7

'lit.llvm.llvm_config' imported but unused (F401)
from lit.llvm.subst import FindTool
from lit.llvm.subst import ToolSubst

# name: The name of this test suite.
config.name = "LLVM"

Check failure on line 10 in seal5/resources/lit.cfg.py

View workflow job for this annotation

GitHub Actions / Flake8

seal5/resources/lit.cfg.py#L10

Undefined name 'config' (F821)
Expand Down
3 changes: 2 additions & 1 deletion seal5/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion seal5/transform/detect_inouts/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"""TODO"""

from m2isar.metamodel import arch, behav
from m2isar.metamodel import behav

# pylint: disable=unused-argument

Expand Down
1 change: 0 additions & 1 deletion seal5/transform/detect_side_effects/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

"""TODO"""

from m2isar import flatten
from m2isar.metamodel import arch, behav

# pylint: disable=unused-argument
Expand Down
2 changes: 1 addition & 1 deletion seal5/transform/eliminate_mod_rfs/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"""TODO"""

from m2isar.metamodel import arch, behav
from m2isar.metamodel import behav

# pylint: disable=unused-argument

Expand Down
2 changes: 1 addition & 1 deletion seal5/transform/eliminate_rd_cmp_zero/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"""TODO"""

from m2isar.metamodel import arch, behav
from m2isar.metamodel import behav

# pylint: disable=unused-argument

Expand Down
2 changes: 1 addition & 1 deletion seal5/transform/explicit_truncations/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion seal5/transform/filter_model/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 5 additions & 6 deletions seal5/transform/infer_types/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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_
Expand Down
2 changes: 1 addition & 1 deletion seal5/transform/process_settings/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions seal5/transform/simplify_trivial_slices/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 556c881

Please sign in to comment.