Skip to content

Commit f0ea5c8

Browse files
committed
kevm-pyk/utils: add byte_offset_to_lines
1 parent 80fd8a0 commit f0ea5c8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

kevm-pyk/src/kevm_pyk/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ def write_cfg(_cfg: KCFG, _cfgpath: Path) -> None:
1919
_LOGGER.info(f'Updated CFG file: {_cfgpath}')
2020

2121

22+
def byte_offset_to_lines(lines: Iterable[str], byte_start: int, byte_width: int) -> Tuple[List[str], int, int]:
23+
text_lines = []
24+
line_start = 0
25+
for l in lines:
26+
if len(l) < byte_start:
27+
byte_start -= len(l) + 1
28+
line_start += 1
29+
else:
30+
break
31+
line_end = line_start
32+
for l in list(lines)[line_start:]:
33+
if byte_start + byte_width < 0:
34+
break
35+
else:
36+
text_lines.append(l)
37+
byte_width -= len(l) + 1
38+
line_end += 1
39+
return (text_lines, line_start, line_end)
40+
41+
2242
def rpc_prove(
2343
kprove: KProve,
2444
cfgid: str,

0 commit comments

Comments
 (0)