Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rtl/__rtlmeter_utils.sv
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

module __rtlmeter_utils;

longint unsigned max_cycles = '1;

initial begin
if ($test$plusargs("trace")) begin
`ifdef __RTLMETER_TRACE_VCD
Expand All @@ -32,10 +34,19 @@ module __rtlmeter_utils;
$stop;
`endif
end
if ($value$plusargs("max_cycles=%d", max_cycles)) begin
$display("RTLMeter: Running only %0d initial cycles", max_cycles);
end
end

longint unsigned cycles = 0;
always @(posedge $root.`__RTLMETER_MAIN_CLOCK) ++cycles;
always @(negedge $root.`__RTLMETER_MAIN_CLOCK) begin
if (cycles >= max_cycles) begin
$display("RTLMeter: +max_cycles reached, exiting");
$finish;
end
end

final begin
integer fd;
Expand Down
12 changes: 8 additions & 4 deletions src/rtlmeter/subcommands/run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=R0913,R0917
# Copyright 2025 RTLMeter contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -40,6 +41,7 @@ def addHooks(
dir: str,
startNode: CNode,
endNode: CNode,
noPostHook: bool,
) -> Tuple[CNode, CNode]:
# If prep hook is given, run it before everything else
if descr.prepHook is not None:
Expand All @@ -48,8 +50,8 @@ def addHooks(
node = cgraph.addNode(f"{descr.case} - Prep hook", dir, step, lambda: runcmd([hook], step))
cgraph.addEdge(node, startNode)
startNode = node
# If post hook is given, run it after everything else
if descr.postHook is not None:
# If post hook is given, run it after everything else, unless explicitly told not to
if descr.postHook is not None and not noPostHook:
hook = descr.postHook
step = "postHook"
node = cgraph.addNode(f"{descr.case} - Post hook", dir, step, lambda: runcmd([hook], step))
Expand All @@ -65,7 +67,7 @@ def compile(
# Compilation
startNode, endNode = sim.compile(cgraph, descr, compileDir, extraArgs)
# Add prep and post hooks
startNode, endNode = addHooks(cgraph, descr, compileDir, startNode, endNode)
startNode, endNode = addHooks(cgraph, descr, compileDir, startNode, endNode, False)

# Before anything else, link resource files for compilation
def linkFiles() -> bool:
Expand Down Expand Up @@ -96,10 +98,12 @@ def linkFiles() -> bool:
def execute(
cgraph: CGraph, descr: ExecuteDescriptor, compileDir: str, executeDir: str, extraArgs: List[str]
) -> Tuple[CNode, CNode]:
# Suppress post hook if has +max_cycles argument as run will not terminate normally
hasMaxCycles = any(map(lambda _: _.startswith("+max_cycles="), extraArgs))
# Execution
startNode, endNode = sim.execute(cgraph, descr, compileDir, executeDir, extraArgs)
# Add prep and post hooks
startNode, endNode = addHooks(cgraph, descr, executeDir, startNode, endNode)
startNode, endNode = addHooks(cgraph, descr, executeDir, startNode, endNode, hasMaxCycles)

# Before anything else, link resource files for execution
def linkFiles() -> bool:
Expand Down
Loading