66
77from pyk .cli .utils import bug_report_arg
88from pyk .cterm import CTerm , cterm_symbolic
9- from pyk .kast .inner import KApply , KInner , KSequence , Subst
9+ from pyk .kast .inner import KApply , KInner , KSequence , KSort , Subst
1010from pyk .kast .manip import split_config_from
11+ from pyk .kast .prelude .string import stringToken
1112from pyk .kcfg import KCFG
1213from pyk .kcfg .explore import KCFGExplore
1314from pyk .kcfg .semantics import DefaultSemantics
1718from pyk .proof .reachability import APRProof , APRProver
1819from pyk .proof .show import APRProofNodePrinter
1920
21+ from .kparse import KParse
2022from .parse .parser import Parser
2123from .rust .cargo import cargo_get_smir_json
22- from .tools import Tools
2324
2425if TYPE_CHECKING :
2526 from collections .abc import Iterator
2627 from pathlib import Path
2728 from typing import Final
2829
30+ from pyk .kore .syntax import Pattern
2931 from pyk .utils import BugReport
3032
3133 from .options import ProveRSOpts
3234
3335_LOGGER : Final = logging .getLogger (__name__ )
3436
3537
36- class KMIR (KProve , KRun ):
38+ class KMIR (KProve , KRun , KParse ):
3739 llvm_library_dir : Path | None
3840 bug_report : BugReport | None
3941
@@ -43,6 +45,7 @@ def __init__(
4345 self .bug_report = bug_report_arg (bug_report ) if bug_report is not None else None
4446 KProve .__init__ (self , definition_dir , bug_report = self .bug_report )
4547 KRun .__init__ (self , definition_dir , bug_report = self .bug_report )
48+ KParse .__init__ (self , definition_dir )
4649 self .llvm_library_dir = llvm_library_dir
4750
4851 class Symbols :
@@ -59,11 +62,27 @@ def kcfg_explore(self, label: str | None = None) -> Iterator[KCFGExplore]:
5962 ) as cts :
6063 yield KCFGExplore (cts , kcfg_semantics = KMIRSemantics ())
6164
65+ def make_init_config (
66+ self , parsed_smir : KInner , start_symbol : KInner | str = 'main' , sort : str = 'GeneratedTopCell'
67+ ) -> KInner :
68+ if isinstance (start_symbol , str ):
69+ start_symbol = stringToken (start_symbol )
70+
71+ subst = Subst ({'$PGM' : parsed_smir , '$STARTSYM' : start_symbol })
72+ init_config = subst .apply (self .definition .init_config (KSort (sort )))
73+ return init_config
74+
75+ def run_parsed (self , parsed_smir : KInner , start_symbol : KInner | str = 'main' , depth : int | None = None ) -> Pattern :
76+ init_config = self .make_init_config (parsed_smir , start_symbol )
77+ init_kore = self .kast_to_kore (init_config , KSort ('GeneratedTopCell' ))
78+ result = self .run_pattern (init_kore , depth = depth )
79+
80+ return result
81+
6282 def apr_proof_from_kast (
6383 self , id : str , kmir_kast : KInner , sort : str = 'GeneratedTopCell' , proof_dir : Path | None = None
6484 ) -> APRProof :
65- tools = Tools (self .definition_dir )
66- config = tools .make_init_config (kmir_kast , 'main' , sort = sort )
85+ config = self .make_init_config (kmir_kast , 'main' , sort = sort )
6786 config_with_cell_vars , _ = split_config_from (config )
6887
6988 lhs = CTerm (config )
0 commit comments