Skip to content

Commit 85e3216

Browse files
Add option --depth to kriscv run (#89)
Co-authored-by: devops <devops@runtimeverification.com>
1 parent 60f10e1 commit 85e3216

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.67
1+
0.1.68

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "kriscv"
7-
version = "0.1.67"
7+
version = "0.1.68"
88
description = "K tooling for the RISC-V architecture"
99
authors = [
1010
"Runtime Verification, Inc. <contact@runtimeverification.com>",

src/kriscv/__main__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class KRISCVOpts:
2323
@dataclass
2424
class RunOpts(KRISCVOpts):
2525
input_file: Path
26+
depth: int | None
2627
end_symbol: str | None
2728
zero_init: bool | None
2829

@@ -55,6 +56,7 @@ def _parse_args(args: Sequence[str]) -> KRISCVOpts:
5556
return RunOpts(
5657
temp_dir=ns.temp_dir,
5758
input_file=ns.input_file.resolve(strict=True),
59+
depth=ns.depth if ns.depth is not None and ns.depth >= 0 else None,
5860
end_symbol=ns.end_symbol,
5961
zero_init=ns.zero_init,
6062
)
@@ -71,7 +73,12 @@ def _parse_args(args: Sequence[str]) -> KRISCVOpts:
7173
def _kriscv_run(opts: RunOpts) -> None:
7274
tools = semantics(temp_dir=opts.temp_dir)
7375
regs = dict.fromkeys(range(32), 0) if opts.zero_init else {}
74-
final_conf = tools.run_elf(opts.input_file, regs=regs, end_symbol=opts.end_symbol)
76+
final_conf = tools.run_elf(
77+
opts.input_file,
78+
depth=opts.depth,
79+
regs=regs,
80+
end_symbol=opts.end_symbol,
81+
)
7582
print(tools.kprint.pretty_print(final_conf, sort_collections=True))
7683

7784

@@ -125,6 +132,7 @@ def _arg_parser() -> ArgumentParser:
125132

126133
run_parser = command_parser.add_parser('run', help='execute a RISC-V ELF file', parents=[common_parser])
127134
run_parser.add_argument('input_file', type=Path, metavar='FILE', help='RISC-V ELF file to run')
135+
run_parser.add_argument('-d', '--depth', type=int, help='execution depth (set negative for unbounded execution)')
128136
run_parser.add_argument('--end-symbol', type=str, help='symbol marking the address which terminates execution')
129137
run_parser.add_argument('-z', '--zero-init', action='store_true', help='initialize registers to zero')
130138

src/kriscv/tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def init_config(self, config_vars: dict[str, KInner]) -> KInner:
3838
conf = self.krun.definition.init_config(sort=GENERATED_TOP_CELL)
3939
return Subst(config_vars)(conf)
4040

41-
def run_config(self, config: KInner) -> KInner:
41+
def run_config(self, config: KInner, *, depth: int | None = None) -> KInner:
4242
config_kore = self.krun.kast_to_kore(config, sort=GENERATED_TOP_CELL)
4343
try:
44-
final_config_kore = self.krun.run_pattern(config_kore, check=True)
44+
final_config_kore = self.krun.run_pattern(config_kore, depth=depth, check=True)
4545
except CalledProcessError as e:
4646
path = Path.cwd()
4747
stdout_path = path / 'krun_stdout.txt'
@@ -63,6 +63,7 @@ def run_elf(
6363
self,
6464
elf_file: Path,
6565
*,
66+
depth: int | None = None,
6667
regs: dict[int, int] | None = None,
6768
end_symbol: str | None = None,
6869
) -> KInner:
@@ -79,7 +80,7 @@ def run_elf(
7980
'$PC': elf_parser.entry_point(elf),
8081
'$HALT': halt_cond,
8182
}
82-
return self.run_config(self.init_config(config_vars))
83+
return self.run_config(self.init_config(config_vars), depth=depth)
8384

8485
def get_registers(self, config: KInner) -> dict[int, int]:
8586
_, cells = split_config_from(config)

0 commit comments

Comments
 (0)