Skip to content

Commit

Permalink
Add per-backend md_selector parameters to booster_kompile
Browse files Browse the repository at this point in the history
  • Loading branch information
tothtamas28 committed May 28, 2024
1 parent c464ac4 commit 6af5e42
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pyk/src/pyk/ktool/kompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@ def _booster_kompile(
if llvm_kt and llvm_kt is not LLVMKompileType.C:
raise ValueError(f'Unsupported argument value for Booster kompilation: llvm_kompile_type: {llvm_kt.value}')

llvm_md_selector, haskell_md_selector = _group_md_selector(**kwargs)
kwargs.pop('md_selector', None)
llvm_args, haskell_args = _group_args(kwargs)

llvm_args['backend'] = KompileBackend.LLVM
llvm_args['llvm_kompile_type'] = LLVMKompileType.C
llvm_args['md_selector'] = llvm_md_selector
llvm_kompile = LLVMKompile.from_dict(llvm_args)

haskell_args['backend'] = KompileBackend.HASKELL
haskell_args['md_selector'] = haskell_md_selector
haskell_kompile = HaskellKompile.from_dict(haskell_args)

main_file = Path(kwargs['main_file'])
Expand Down Expand Up @@ -176,6 +180,23 @@ def kompile_haskell() -> None:
return output_dir


def _group_md_selector(
*,
md_selector: str | None = None,
llvm_md_selector: str | None = None,
haskell_md_selector: str | None = None,
**kwargs: Any,
) -> tuple[str | None, str | None]:
if md_selector:
if llvm_md_selector:
raise ValueError("Parameter llvm_md_selector should not be passed if md_selector is defined")
if haskell_md_selector:
raise ValueError("Parameter haskell_md_selector should not be passed if md_selector is defined")
return md_selector, md_selector

return llvm_md_selector, haskell_md_selector


def _group_args(args: Mapping[str, Any]) -> tuple[dict[str, Any], dict[str, Any]]:
llvm_args = {}
haskell_args = {}
Expand Down

0 comments on commit 6af5e42

Please sign in to comment.