From 380ca2010be253e34ac62dcc8adc50ff12e9582b Mon Sep 17 00:00:00 2001 From: Philipp van Kempen Date: Fri, 1 Mar 2024 08:25:19 +0100 Subject: [PATCH] lint --- seal5/backends/llvmir/writer.py | 2 +- seal5/backends/patterngen/writer.py | 1 - seal5/backends/riscv_gisel_legalizer/writer.py | 6 ++++-- seal5/backends/riscv_isa_info/writer.py | 8 +++----- seal5/flow.py | 16 +++++++++++----- seal5/passes.py | 10 +++++++--- seal5/resources/lit.cfg.py | 4 ++-- seal5/settings.py | 4 ++++ seal5/tools/cdsl2llvm.py | 4 +++- seal5/tools/llvm.py | 2 +- seal5/transform/filter_model/filter.py | 2 +- 11 files changed, 37 insertions(+), 22 deletions(-) diff --git a/seal5/backends/llvmir/writer.py b/seal5/backends/llvmir/writer.py index 2047379a..576d138d 100644 --- a/seal5/backends/llvmir/writer.py +++ b/seal5/backends/llvmir/writer.py @@ -121,7 +121,7 @@ def main(): input_file, output_file, skip_patterns=True, - skip_formats=True + skip_formats=True, ) metrics["n_success"] += 1 except AssertionError: diff --git a/seal5/backends/patterngen/writer.py b/seal5/backends/patterngen/writer.py index 76d23726..fc6b149b 100644 --- a/seal5/backends/patterngen/writer.py +++ b/seal5/backends/patterngen/writer.py @@ -155,7 +155,6 @@ def main(): skip_formats=not args.formats, ext=predicate, mattr=mattr, - ) if output_file.is_file(): metrics["n_success"] += 1 diff --git a/seal5/backends/riscv_gisel_legalizer/writer.py b/seal5/backends/riscv_gisel_legalizer/writer.py index 2f55d188..cab69070 100644 --- a/seal5/backends/riscv_gisel_legalizer/writer.py +++ b/seal5/backends/riscv_gisel_legalizer/writer.py @@ -23,6 +23,7 @@ # if (ST.hasVendorXCvsimd()) { + def type_helper(ty): print("type_helper", ty) ty_ = ty.replace("seal5_", "") @@ -43,7 +44,6 @@ def type_helper(ty): raise RuntimeError(f"Unsupported: {ty}") - def gen_riscv_gisel_legalizer_str(legalizer_settings: RISCVLegalizerSettings): print("legalizer_settings", legalizer_settings) ops = legalizer_settings.ops @@ -167,7 +167,9 @@ def main(): with open(out_path, "w") as f: f.write(content) riscv_gisel_legalizer_patch = NamedPatch( - "llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp", key="riscv_legalizer_info", src_path=out_path + "llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp", + key="riscv_legalizer_info", + src_path=out_path, ) artifacts[None].append(riscv_gisel_legalizer_patch) if args.metrics: diff --git a/seal5/backends/riscv_isa_info/writer.py b/seal5/backends/riscv_isa_info/writer.py index 0c7f5473..676b2adc 100644 --- a/seal5/backends/riscv_isa_info/writer.py +++ b/seal5/backends/riscv_isa_info/writer.py @@ -24,8 +24,8 @@ logger = logging.getLogger("riscv_isa_info") -MAKO_TEMPLATE = " {\"${arch}\", RISCVExtensionVersion{${version_major}, ${version_minor}}}," -MAKO_TEMPLATE_LLVM18 = " {\"${arch}\", {${version_major}, ${version_minor}}}," +MAKO_TEMPLATE = ' {"${arch}", RISCVExtensionVersion{${version_major}, ${version_minor}}},' +MAKO_TEMPLATE_LLVM18 = ' {"${arch}", {${version_major}, ${version_minor}}},' def gen_riscv_isa_info_str(name: str, ext_settings: ExtensionsSettings, llvm_version: LLVMVersion): @@ -140,9 +140,7 @@ def main(): key = "riscv_isa_info_experimental" else: key = "riscv_isa_info" - riscv_isa_info_patch = NamedPatch( - "llvm/lib/Support/RISCVISAInfo.cpp", key=key, src_path=out_path - ) + riscv_isa_info_patch = NamedPatch("llvm/lib/Support/RISCVISAInfo.cpp", key=key, src_path=out_path) artifacts[None].append(riscv_isa_info_patch) if args.metrics: metrics_file = args.metrics diff --git a/seal5/flow.py b/seal5/flow.py index 8a2e5398..89e67693 100644 --- a/seal5/flow.py +++ b/seal5/flow.py @@ -256,7 +256,9 @@ def initialize( sha, version_info = llvm.clone_llvm_repo(self.directory, clone_url, ref=clone_ref, label=self.name) else: if force: - sha, version_info = llvm.clone_llvm_repo(self.directory, clone_url, ref=clone_ref, refresh=True, label=self.name) + sha, version_info = llvm.clone_llvm_repo( + self.directory, clone_url, ref=clone_ref, refresh=True, label=self.name + ) if self.meta_dir.is_dir(): if force is False and not utils.ask_user( "Overwrite existing .seal5 diretcory?", default=False, interactive=interactive @@ -405,12 +407,12 @@ def load(self, files: List[Path], verbose: bool = False, overwrite: bool = False logger.info("Completed load of Seal5 inputs") def build(self, config="release", target="all", verbose: bool = False): - logger.info("Building Seal5 LLVM") + logger.info("Building Seal5 LLVM (%s)", target) llvm_config = self.settings.llvm.configs.get(config, None) assert llvm_config is not None, f"Invalid llvm config: {config}" cmake_options = llvm_config.options llvm.build_llvm(self.directory, self.build_dir / config, cmake_options=cmake_options, target=target) - logger.info("Completed build of Seal5 LLVM") + logger.info("Completed build of Seal5 LLVM (%s)", target) def convert_models(self, verbose: bool = False, inplace: bool = False): assert not inplace @@ -1348,7 +1350,9 @@ def convert_llvmir_to_gmir_splitted(self, verbose: bool = False, inplace: bool = cdsl2llvm_build_dir = str(self.deps_dir / "cdsl2llvm" / "llvm" / "build") cdsl2llvm.convert_ll_to_gmir( # self.deps_dir / "cdsl2llvm" / "llvm" / "build", ll_file, output_file - cdsl2llvm_build_dir, ll_file, output_file + cdsl2llvm_build_dir, + ll_file, + output_file, ) except AssertionError: pass @@ -1587,7 +1591,9 @@ def patch(self, verbose: bool = False, stages: List[PatchStage] = None, force: b self.apply_patch(patch, force=force) logger.info("Completed application of Seal5 patches") - def test(self, debug: bool = False, verbose: bool = False, ignore_error: bool = False, config: Optional[str] = None): + def test( + self, debug: bool = False, verbose: bool = False, ignore_error: bool = False, config: Optional[str] = None + ): logger.info("Testing Seal5 LLVM") if config is None: config = "debug" if debug else "release" diff --git a/seal5/passes.py b/seal5/passes.py index dc7799b2..44a7565b 100644 --- a/seal5/passes.py +++ b/seal5/passes.py @@ -23,7 +23,6 @@ class PassScope(Enum): class Seal5Pass: - def __init__(self, name, pass_type, pass_scope, handler, order=-1, options=None): self.name: str = name self.pass_type: PassType = pass_type @@ -35,7 +34,7 @@ def __init__(self, name, pass_type, pass_scope, handler, order=-1, options=None) @property def is_pending(self): - return self.status in [PassStatus.CREATED] + return self.status in [PassStatus.CREATED, PassStatus.SKIPPED] def skip(self): self.status = PassStatus.SKIPPED @@ -53,7 +52,12 @@ def run(self, *args, **kwargs): raise e -def filter_passes(passes: List[Seal5Pass], pass_name: Optional[str] = None, pass_type: Optional[PassType] = None, pass_scope: Optional[PassScope] = None): +def filter_passes( + passes: List[Seal5Pass], + pass_name: Optional[str] = None, + pass_type: Optional[PassType] = None, + pass_scope: Optional[PassScope] = None, +): # TODO: support regex patters in name ret = [] for pass_ in passes: diff --git a/seal5/resources/lit.cfg.py b/seal5/resources/lit.cfg.py index c3ed654c..94f8f264 100644 --- a/seal5/resources/lit.cfg.py +++ b/seal5/resources/lit.cfg.py @@ -15,7 +15,7 @@ from lit.llvm.subst import ToolSubst # name: The name of this test suite. -config.name = 'LLVM' +config.name = "LLVM" # testFormat: The test format to use to interpret tests. # config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) @@ -23,4 +23,4 @@ # # suffixes: A list of file extensions to treat as test files. This is overriden # # by individual lit.local.cfg files in the test subdirectories. -config.suffixes = ['.ll', '.c', '.test', '.txt', '.s', '.mir', '.yaml'] +config.suffixes = [".ll", ".c", ".test", ".txt", ".s", ".mir", ".yaml"] diff --git a/seal5/settings.py b/seal5/settings.py index ecec9cbc..a714cdd0 100644 --- a/seal5/settings.py +++ b/seal5/settings.py @@ -449,16 +449,19 @@ class LLVMSettings(YAMLSettings): state: Optional[LLVMState] = None configs: Optional[Dict[str, LLVMConfig]] = None + @dataclass class RISCVLegalizerSetting(YAMLSettings): name: Optional[Union[str, List[str]]] = None types: Optional[Union[str, List[str]]] = None onlyif: Optional[Union[str, List[str]]] = None + @dataclass class RISCVLegalizerSettings(YAMLSettings): ops: Optional[List[RISCVLegalizerSetting]] = None + @dataclass class RISCVSettings(YAMLSettings): xlen: Optional[int] = None @@ -481,6 +484,7 @@ class PatternGenSettings(YAMLSettings): class ToolsSettings(YAMLSettings): pattern_gen: Optional[PatternGenSettings] = None + @dataclass class Seal5Settings(YAMLSettings): logging: Optional[LoggingSettings] = None diff --git a/seal5/tools/cdsl2llvm.py b/seal5/tools/cdsl2llvm.py index dd0eb1cb..4051afe0 100644 --- a/seal5/tools/cdsl2llvm.py +++ b/seal5/tools/cdsl2llvm.py @@ -47,7 +47,9 @@ def build_pattern_gen( def get_pattern_gen_patches( - src: Path, temp_dir: Path, verbose: bool = False, + src: Path, + temp_dir: Path, + verbose: bool = False, ): # TODO: copy! artifacts = [] diff --git a/seal5/tools/llvm.py b/seal5/tools/llvm.py index bf4263a9..0869d808 100644 --- a/seal5/tools/llvm.py +++ b/seal5/tools/llvm.py @@ -116,7 +116,7 @@ def build_llvm( def test_llvm(base: Path, build_dir: Path, test_paths: List[str] = [], verbose: bool = False): - env = os.eviron.copy() + env = os.environ.copy() old_path = env["PATH"] env["PATH"] = f"{build_dir}/bin:{old_path}" lit_exe = build_dir / "bin" / "llvm-lit" diff --git a/seal5/transform/filter_model/filter.py b/seal5/transform/filter_model/filter.py index 7c5021fe..f4a3766f 100644 --- a/seal5/transform/filter_model/filter.py +++ b/seal5/transform/filter_model/filter.py @@ -211,7 +211,7 @@ def check_encoding_filter(enc, keep, drop, keep2, drop2): if drop2 and keep2: ret = size not in drop2 and size in keep2 elif keep2: - ret = size in keep2 + ret = size in keep2 elif drop2: ret = size not in drop2 if not ret: