diff --git a/rtl/__rtlmeter_utils.sv b/rtl/__rtlmeter_utils.sv index 0cdee2d..c8da6c6 100644 --- a/rtl/__rtlmeter_utils.sv +++ b/rtl/__rtlmeter_utils.sv @@ -16,6 +16,8 @@ module __rtlmeter_utils; + longint unsigned max_cycles = '1; + initial begin if ($test$plusargs("trace")) begin `ifdef __RTLMETER_TRACE_VCD @@ -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; diff --git a/src/rtlmeter/subcommands/run.py b/src/rtlmeter/subcommands/run.py index af5768c..09ac172 100644 --- a/src/rtlmeter/subcommands/run.py +++ b/src/rtlmeter/subcommands/run.py @@ -1,3 +1,4 @@ +# pylint: disable=R0913,R0917 # Copyright 2025 RTLMeter contributors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -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: @@ -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)) @@ -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: @@ -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: