Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add per-backend md_selector parameters to booster_kompile #4398

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion pyk/src/pyk/ktool/kompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,24 @@ def _booster_kompile(
cwd: Path | None,
check: bool,
# ---
kwargs: Mapping[str, Any],
kwargs: dict[str, Any],
) -> Path:
llvm_kt = kwargs.get('llvm_kompile_type')
llvm_kt = LLVMKompileType(llvm_kt) if llvm_kt else None
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
Loading