Skip to content

Commit 7b8dda6

Browse files
committed
kevm-pyk/{kevm,__main__}: move srcmap as field of KEVM
1 parent 14e0fcd commit 7b8dda6

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

kevm-pyk/src/kevm_pyk/__main__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,10 @@ def exec_foundry_show(
423423
use_directory.mkdir(parents=True, exist_ok=True)
424424
kcfgs_dir = foundry_out / 'kcfgs'
425425
srcmap_dir = foundry_out / 'srcmaps'
426-
foundry = Foundry(definition_dir, profile=profile, use_directory=use_directory)
427426
kcfg_file = kcfgs_dir / f'{test}.json'
428427
contract = test.split('.')[0]
429428
srcmap_file = srcmap_dir / f'{contract}.json'
430-
srcmap: Optional[Dict[int, str]] = None
431-
if srcmap_file.exists():
432-
with open(srcmap_file, 'r') as sm:
433-
srcmap = {int(k): v for k, v in json.loads(sm.read()).items()}
429+
foundry = Foundry(definition_dir, profile=profile, use_directory=use_directory, srcmap_file=srcmap_file)
434430

435431
def _node_pretty(_ct: CTerm) -> List[str]:
436432
k_cell = foundry.pretty_print(get_cell(_ct.config, 'K_CELL')).replace('\n', ' ')

kevm-pyk/src/kevm_pyk/kevm.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
import sys
34
from pathlib import Path
@@ -25,6 +26,9 @@
2526

2627

2728
class KEVM(KProve, KRun):
29+
30+
srcmap: Optional[Dict[int, str]]
31+
2832
def __init__(
2933
self,
3034
definition_dir: Path,
@@ -33,6 +37,7 @@ def __init__(
3337
profile: bool = False,
3438
kprove_command: str = 'kprove',
3539
krun_command: str = 'krun',
40+
srcmap_file: Optional[Path] = None,
3641
) -> None:
3742
# I'm going for the simplest version here, we can change later if there is an advantage.
3843
# https://stackoverflow.com/questions/9575409/calling-parent-class-init-with-multiple-inheritance-whats-the-right-way
@@ -47,6 +52,10 @@ def __init__(
4752
)
4853
KRun.__init__(self, definition_dir, use_directory=use_directory, profile=profile, command=krun_command)
4954
KEVM._patch_symbol_table(self.symbol_table)
55+
self.srcmap = None
56+
if srcmap_file is not None and srcmap_file.exists():
57+
with open(srcmap_file, 'r') as sm:
58+
self.srcmap = {int(k): v for k, v in json.loads(sm.read()).items()}
5059

5160
@staticmethod
5261
def kompile(
@@ -440,9 +449,17 @@ def __init__(
440449
main_file: Optional[Path] = None,
441450
use_directory: Optional[Path] = None,
442451
profile: bool = False,
452+
srcmap_file: Optional[Path] = None,
443453
) -> None:
444454
# copied from KEVM class and adapted to inherit KPrint instead
445-
KEVM.__init__(self, definition_dir, main_file=main_file, use_directory=use_directory, profile=profile)
455+
KEVM.__init__(
456+
self,
457+
definition_dir,
458+
main_file=main_file,
459+
use_directory=use_directory,
460+
profile=profile,
461+
srcmap_file=srcmap_file,
462+
)
446463
Foundry._patch_symbol_table(self.symbol_table)
447464

448465
class Sorts:

0 commit comments

Comments
 (0)