Skip to content

Commit

Permalink
Exporting get_requires utils function (runtimeverification/pyk#1056)
Browse files Browse the repository at this point in the history
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
Robertorosmaninho and devops authored Apr 4, 2024
1 parent 0321cdb commit 0820fb8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pyk/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
project = 'pyk'
author = 'Runtime Verification, Inc'
copyright = '2024, Runtime Verification, Inc'
version = '0.1.770'
release = '0.1.770'
version = '0.1.771'
release = '0.1.771'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion pyk/package/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.770
0.1.771
2 changes: 1 addition & 1 deletion pyk/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]>",
Expand Down
14 changes: 14 additions & 0 deletions pyk/src/pyk/kllvm/utils.py
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)
35 changes: 35 additions & 0 deletions pyk/src/tests/integration/kllvm/test_utils.py
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

0 comments on commit 0820fb8

Please sign in to comment.