Skip to content

Commit 73fb317

Browse files
committed
kevm-pyk/{kevm, __main__}: move node short info printer into KEVM class
1 parent 7b8dda6 commit 73fb317

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

kevm-pyk/src/kevm_pyk/__main__.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from pathos.pools import ProcessPool # type: ignore
99
from pyk.cli_utils import dir_path, file_path
1010
from pyk.cterm import CTerm, build_rule
11-
from pyk.kast.inner import KApply, KInner, KRewrite, KToken
12-
from pyk.kast.manip import get_cell, minimize_term, push_down_rewrites
11+
from pyk.kast.inner import KApply, KInner, KRewrite
12+
from pyk.kast.manip import minimize_term, push_down_rewrites
1313
from pyk.kast.outer import KDefinition, KFlatModule, KImport, KRequire, KRule
1414
from pyk.kcfg import KCFG
1515
from pyk.kcfg_viewer.app import KCFGViewer
@@ -428,27 +428,9 @@ def exec_foundry_show(
428428
srcmap_file = srcmap_dir / f'{contract}.json'
429429
foundry = Foundry(definition_dir, profile=profile, use_directory=use_directory, srcmap_file=srcmap_file)
430430

431-
def _node_pretty(_ct: CTerm) -> List[str]:
432-
k_cell = foundry.pretty_print(get_cell(_ct.config, 'K_CELL')).replace('\n', ' ')
433-
if len(k_cell) > 80:
434-
k_cell = k_cell[0:80] + ' ...'
435-
k_str = f'k: {k_cell}'
436-
calldepth_str = f'callDepth: {foundry.pretty_print(get_cell(_ct.config, "CALLDEPTH_CELL"))}'
437-
statuscode_str = f'statusCode: {foundry.pretty_print(get_cell(_ct.config, "STATUSCODE_CELL"))}'
438-
_pc = get_cell(_ct.config, 'PC_CELL')
439-
pc_str = f'pc: {foundry.pretty_print(_pc)}'
440-
ret_strs = [k_str, calldepth_str, statuscode_str, pc_str]
441-
if type(_pc) is KToken and srcmap is not None:
442-
pc = int(_pc.token)
443-
if pc in srcmap:
444-
ret_strs.append(f'srcmap: {srcmap[pc]}')
445-
else:
446-
_LOGGER.warning(f'pc not found in srcmap: {pc}')
447-
return ret_strs
448-
449431
with open(kcfg_file, 'r') as kf:
450432
kcfg = KCFG.from_dict(json.loads(kf.read()))
451-
list(map(print, kcfg.pretty(foundry, minimize=minimize, node_printer=_node_pretty)))
433+
list(map(print, kcfg.pretty(foundry, minimize=minimize, node_printer=foundry.short_info)))
452434
for node_id in nodes:
453435
kast = kcfg.node(node_id).cterm.kast
454436
if minimize:
@@ -549,7 +531,7 @@ def exec_foundry_view_kcfg(foundry_out: Path, test: str, profile: bool, **kwargs
549531
kcfg_file = kcfgs_dir / f'{test}.json'
550532
use_directory.mkdir(parents=True, exist_ok=True)
551533
foundry = Foundry(definition_dir, profile=profile, use_directory=use_directory)
552-
viewer = KCFGViewer(kcfg_file, foundry)
534+
viewer = KCFGViewer(kcfg_file, foundry, node_printer=foundry.short_info)
553535
viewer.run()
554536

555537

kevm-pyk/src/kevm_pyk/kevm.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,24 @@ def concrete_rules() -> List[str]:
186186
'SERIALIZATION.#newAddrCreate2',
187187
]
188188

189+
def short_info(self, cterm: CTerm) -> List[str]:
190+
k_cell = self.pretty_print(get_cell(cterm.config, 'K_CELL')).replace('\n', ' ')
191+
if len(k_cell) > 80:
192+
k_cell = k_cell[0:80] + ' ...'
193+
k_str = f'k: {k_cell}'
194+
calldepth_str = f'callDepth: {self.pretty_print(get_cell(cterm.config, "CALLDEPTH_CELL"))}'
195+
statuscode_str = f'statusCode: {self.pretty_print(get_cell(cterm.config, "STATUSCODE_CELL"))}'
196+
_pc = get_cell(cterm.config, 'PC_CELL')
197+
pc_str = f'pc: {self.pretty_print(_pc)}'
198+
ret_strs = [k_str, calldepth_str, statuscode_str, pc_str]
199+
if type(_pc) is KToken and self.srcmap is not None:
200+
pc = int(_pc.token)
201+
if pc in self.srcmap:
202+
ret_strs.append(f'srcmap: {self.srcmap[pc]}')
203+
else:
204+
_LOGGER.warning(f'pc not found in srcmap: {pc}')
205+
return ret_strs
206+
189207
@staticmethod
190208
def add_invariant(cterm: CTerm) -> CTerm:
191209
config, *constraints = cterm

0 commit comments

Comments
 (0)