From a680cf8190dd8f0ac3980f63e89097225629ed71 Mon Sep 17 00:00:00 2001 From: Juan C Date: Fri, 21 Jun 2024 18:26:46 +0200 Subject: [PATCH] Add `ignore-warnings` kompile option --- pyk/src/pyk/__main__.py | 2 ++ pyk/src/pyk/cli/args.py | 5 +++++ pyk/src/pyk/ktool/kompile.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/pyk/src/pyk/__main__.py b/pyk/src/pyk/__main__.py index 17d7cfc441a..0d514d27e22 100644 --- a/pyk/src/pyk/__main__.py +++ b/pyk/src/pyk/__main__.py @@ -315,6 +315,7 @@ def exec_kompile(options: KompileCommandOptions) -> None: 'gen_glr_bison_parser': options.gen_glr_bison_parser, 'bison_lists': options.bison_lists, 'outer_parsed_json': options.outer_parsed_json, + 'ignore_warnings': options.ignore_warnings, } if options.backend == KompileBackend.LLVM: kompile_dict['ccopts'] = options.ccopts @@ -346,6 +347,7 @@ def exec_kompile(options: KompileCommandOptions) -> None: warnings=options.warnings, warnings_to_errors=options.warnings_to_errors, no_exc_wrap=options.no_exc_wrap, + ignore_warnings=options.ignore_warnings, ) except RuntimeError as err: _, _, _, _, cpe = err.args diff --git a/pyk/src/pyk/cli/args.py b/pyk/src/pyk/cli/args.py index 356a17a5a57..16693eeb333 100644 --- a/pyk/src/pyk/cli/args.py +++ b/pyk/src/pyk/cli/args.py @@ -206,6 +206,7 @@ class KompileOptions(Options): bison_lists: bool no_exc_wrap: bool outer_parsed_json: bool + ignore_warnings: list[str] | None @staticmethod def default() -> dict[str, Any]: @@ -230,6 +231,7 @@ def default() -> dict[str, Any]: 'bison_lists': False, 'no_exc_wrap': False, 'outer_parsed_json': False, + 'ignore_warnings': None, } @staticmethod @@ -475,6 +477,9 @@ def kompile_args(self) -> ArgumentParser: action='store_true', help='Do not wrap the output on the CLI.', ) + args.add_argument( + '--ignore-warnings', dest='ignore_warnings', default=None, action='append', help='Ignore provided warnings' + ) return args @cached_property diff --git a/pyk/src/pyk/ktool/kompile.py b/pyk/src/pyk/ktool/kompile.py index 17c9b6d4bf8..3f6ba129eba 100644 --- a/pyk/src/pyk/ktool/kompile.py +++ b/pyk/src/pyk/ktool/kompile.py @@ -63,6 +63,7 @@ def kompile( verbose: bool = False, cwd: Path | None = None, check: bool = True, + ignore_warnings: Iterable[str] | None = None, # --- **kwargs: Any, ) -> Path: @@ -83,6 +84,7 @@ def kompile( cwd=cwd, check=check, kwargs=kwargs, + ignore_warnings=ignore_warnings, ) kwargs['backend'] = KompileBackend(pyk_backend.value) if pyk_backend else None @@ -100,6 +102,7 @@ def kompile( verbose=verbose, cwd=cwd, check=check, + ignore_warnings=ignore_warnings, ) @@ -116,6 +119,7 @@ def _booster_kompile( verbose: bool, cwd: Path | None, check: bool, + ignore_warnings: Iterable[str] | None, # --- kwargs: Mapping[str, Any], ) -> Path: @@ -150,6 +154,7 @@ def kompile_llvm() -> None: verbose=verbose, cwd=cwd, check=check, + ignore_warnings=ignore_warnings, ) def kompile_haskell() -> None: @@ -165,6 +170,7 @@ def kompile_haskell() -> None: verbose=verbose, cwd=cwd, check=check, + ignore_warnings=ignore_warnings, ) with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor: @@ -279,6 +285,7 @@ def __call__( check: bool = True, bug_report: BugReport | None = None, outer_parsed_json: bool = False, + ignore_warnings: Iterable[str] | None = None, ) -> Path: check_file_path(abs_or_rel_to(self.base_args.main_file, cwd or Path())) for include_dir in self.base_args.include_dirs: @@ -320,6 +327,9 @@ def __call__( if outer_parsed_json: args += ['--outer-parsed-json'] + if ignore_warnings: + args += ['-Wno', ', '.join(ignore_warnings)] + try: proc_res = run_process(args, logger=_LOGGER, cwd=cwd, check=check) except CalledProcessError as err: @@ -512,6 +522,7 @@ class KompileArgs: coverage: bool bison_lists: bool outer_parsed_json: bool + ignore_warnings: Iterable[str] | None def __init__( self, @@ -531,6 +542,7 @@ def __init__( coverage: bool = False, bison_lists: bool = False, outer_parsed_json: bool = False, + ignore_warnings: Iterable[str] | None = None, ): main_file = Path(main_file) include_dirs = tuple(sorted(Path(include_dir) for include_dir in include_dirs)) @@ -551,6 +563,7 @@ def __init__( object.__setattr__(self, 'coverage', coverage) object.__setattr__(self, 'bison_lists', bison_lists) object.__setattr__(self, 'outer_parsed_json', outer_parsed_json) + object.__setattr__(self, 'ignore_warnings', ignore_warnings) def args(self) -> list[str]: args = [str(self.main_file)] @@ -597,6 +610,9 @@ def args(self) -> list[str]: if self.outer_parsed_json: args += ['--outer-parsed-json'] + if self.ignore_warnings: + args += ['-Wno', ', '.join(self.ignore_warnings)] + return args