-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exporting
get_requires
utils function (runtimeverification/pyk#1056)
This PR introduces a new file, `utils.py`, which should contain auxiliary functions that need to be converted from and to llvm but don't set any field on an object. In this context we're using a function from llvm backend's [pattern_matching.cpp](https://github.com/runtimeverification/llvm-backend/blob/e2f583a05b9bf362deabd58f8acc1ce534aaf4c4/lib/ast/pattern_matching.cpp#L174) to avoid reimplement it in Python. This function is exported as Pyhton binding in this [PR](runtimeverification/llvm-backend#1019), and therefore, the current PR can only be merged after we merge the LLVM Backend one. --------- Co-authored-by: devops <[email protected]>
- Loading branch information
1 parent
0321cdb
commit 0820fb8
Showing
5 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.770 | ||
0.1.771 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "pyk" | ||
version = "0.1.770" | ||
version = "0.1.771" | ||
description = "" | ||
authors = [ | ||
"Runtime Verification, Inc. <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from . import convert | ||
|
||
if TYPE_CHECKING: | ||
from ..kore.syntax import Axiom, Pattern | ||
|
||
|
||
def get_requires(axiom: Axiom) -> Pattern: | ||
llvm_axiom = convert.sentence_to_llvm(axiom) | ||
llvm_pattern = llvm_axiom.requires | ||
return convert.llvm_to_pattern(llvm_pattern) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
import pyk.kllvm.load # noqa: F401 | ||
from pyk.kllvm.utils import get_requires | ||
from pyk.kore.parser import KoreParser | ||
|
||
if TYPE_CHECKING: | ||
from typing import Final | ||
|
||
AXIOM_TEST_DATA: Final = ( | ||
( | ||
'axiom1', | ||
r'W{}(VarA : SortInt{},\dv{SortInt{}}("1"))', | ||
r'axiom {} \rewrites{SortGeneratedTopCell{}}(\and{SortGeneratedTopCell{}}(X{}(Y{}(kseq{}(inj{SortInt{}, SortKItem{}}(VarA : SortInt{}),dotk{}())), Z : SortGeneratedCounterCell{}),\equals{SortBool{}, SortGeneratedTopCell{}}(W{}(VarA : SortInt{},\dv{SortInt{}}("1")),\dv{SortBool{}}("true"))),\and{SortGeneratedTopCell{}}(X{}(Y{}(kseq{}(inj{SortInt{}, SortKItem{}}(\dv{SortInt{}}("1")),dotk{}())),),\top{SortGeneratedTopCell{}}())) []', | ||
), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'test_id,kore_requires,kore_axiom', AXIOM_TEST_DATA, ids=[test_id for test_id, *_ in AXIOM_TEST_DATA] | ||
) | ||
def test_get_requires(test_id: str, kore_requires: str, kore_axiom: str) -> None: | ||
# Given | ||
axiom = KoreParser(kore_axiom).axiom() | ||
expected_requires = KoreParser(kore_requires).pattern() | ||
|
||
# When | ||
actual_requires = get_requires(axiom) | ||
|
||
# Then | ||
assert actual_requires == expected_requires |