|
8 | 8 | from pyk.kast.outer import KRule, read_kast_definition |
9 | 9 | from pyk.kdist import kdist |
10 | 10 | from pyk.konvert import kast_to_kore |
| 11 | +from pyk.kore.manip import substitute_vars |
| 12 | +from pyk.kore.prelude import generated_top |
| 13 | +from pyk.kore.syntax import App |
11 | 14 | from pyk.ktool.kompile import DefinitionInfo |
12 | 15 | from pyk.ktool.kprove import KProve |
13 | 16 | from pyk.ktool.krun import KRun |
14 | 17 | from pyk.utils import single |
15 | 18 |
|
16 | 19 | if TYPE_CHECKING: |
| 20 | + from collections.abc import Mapping |
17 | 21 | from pathlib import Path |
18 | 22 | from subprocess import CompletedProcess |
19 | 23 | from typing import Any, Final |
20 | 24 |
|
21 | 25 | from pyk.kast.inner import KInner, KSort |
22 | 26 | from pyk.kast.outer import KDefinition, KFlatModule |
| 27 | + from pyk.kore.syntax import EVar, Pattern |
23 | 28 | from pyk.ktool.kompile import KompileBackend |
24 | 29 |
|
25 | 30 | _LOGGER: Final = logging.getLogger(__name__) |
@@ -92,3 +97,29 @@ def parse_lemmas_module(self, module_path: Path, module_name: str) -> KFlatModul |
92 | 97 | concrete_definition = SorobanDefinition(kdist.get('soroban-semantics.llvm')) |
93 | 98 | library_definition = SorobanDefinition(kdist.get('soroban-semantics.llvm-library')) |
94 | 99 | symbolic_definition = SorobanDefinition(kdist.get('soroban-semantics.haskell')) |
| 100 | + |
| 101 | + |
| 102 | +def subst_on_program_cell(template: Pattern, subst_case: Mapping[EVar, Pattern]) -> Pattern: |
| 103 | + """A substitution function that only applies substitutions within the K cell. |
| 104 | + Optimizing the fuzzer by restricting changes to relevant parts of the configuration. |
| 105 | +
|
| 106 | + Args: |
| 107 | + template: The template configuration containing variables in the K cell. |
| 108 | + subst_case: A mapping from variables to their replacement patterns. |
| 109 | + """ |
| 110 | + |
| 111 | + def kasmer_cell(program_cell: Pattern, soroban_cell: Pattern, exit_code_cell: Pattern) -> Pattern: |
| 112 | + return App("Lbl'-LT-'kasmer'-GT-'", args=(program_cell, soroban_cell, exit_code_cell)) |
| 113 | + |
| 114 | + match template: |
| 115 | + case App( |
| 116 | + "Lbl'-LT-'generatedTop'-GT-'", |
| 117 | + args=( |
| 118 | + App("Lbl'-LT-'kasmer'-GT-'", args=(program_cell, soroban_cell, exit_code_cell)), |
| 119 | + generated_counter_cell, |
| 120 | + ), |
| 121 | + ): |
| 122 | + program_cell_ = substitute_vars(program_cell, subst_case) |
| 123 | + return generated_top((kasmer_cell(program_cell_, soroban_cell, exit_code_cell), generated_counter_cell)) |
| 124 | + |
| 125 | + raise ValueError(template) |
0 commit comments