-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose function evaluation from KLLVM bindings (#4242)
Transfer of: * runtimeverification/pyk#784 Related: * runtimeverification/llvm-backend#943 Co-authored-by: Tamás Tóth <[email protected]> Co-authored-by: Scott Guest <[email protected]>
- Loading branch information
1 parent
5e08b77
commit 0d3368d
Showing
2 changed files
with
55 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
import pyk.kllvm.load # noqa: F401 | ||
from pyk.kllvm import parser | ||
from pyk.testing import RuntimeTest | ||
|
||
from ..utils import K_FILES | ||
|
||
if TYPE_CHECKING: | ||
from pyk.kllvm.runtime import Runtime | ||
|
||
|
||
EVALUATE_TEST_DATA = ( | ||
('1 + 2', r"""Lbl'UndsPlus'Int'Unds'{}(\dv{SortInt{}}("1"),\dv{SortInt{}}("2"))""", r'\dv{SortInt{}}("3")'), | ||
('1 * 2', r"""Lbl'UndsStar'Int'Unds'{}(\dv{SortInt{}}("1"),\dv{SortInt{}}("2"))""", r'\dv{SortInt{}}("2")'), | ||
( | ||
'1 + (2 * 3)', | ||
r""" | ||
Lbl'UndsPlus'Int'Unds'{}( | ||
\dv{SortInt{}}("1"), | ||
Lbl'UndsStar'Int'Unds'{}(\dv{SortInt{}}("2"), \dv{SortInt{}}("3")) | ||
) | ||
""", | ||
r'\dv{SortInt{}}("7")', | ||
), | ||
) | ||
|
||
|
||
class TestEvaluate(RuntimeTest): | ||
KOMPILE_MAIN_FILE = K_FILES / 'imp.k' | ||
|
||
@pytest.mark.parametrize( | ||
'test_id,pattern_text,expected', | ||
EVALUATE_TEST_DATA, | ||
ids=[test_id for test_id, *_ in EVALUATE_TEST_DATA], | ||
) | ||
def test_simplify(self, runtime: Runtime, test_id: str, pattern_text: str, expected: str) -> None: | ||
# Given | ||
pattern = parser.parse_pattern(pattern_text) | ||
|
||
# When | ||
actual = runtime.evaluate(pattern) | ||
|
||
# Then | ||
assert str(actual) == expected |