From 22ce36012e3406c476ec03704bb95a0c4cf16d46 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 17 Oct 2022 18:18:56 -0400 Subject: [PATCH] Add VERILATOR_TIMING define (#3684) --- docs/guide/extensions.rst | 7 +++++++ src/V3Options.cpp | 3 +++ test_regress/t/t_notiming.v | 4 ++++ test_regress/t/t_timing_events.v | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/docs/guide/extensions.rst b/docs/guide/extensions.rst index e0622beb3..3e0161499 100644 --- a/docs/guide/extensions.rst +++ b/docs/guide/extensions.rst @@ -151,6 +151,13 @@ or "`ifdef`"'s may break other tools. Take remaining text up to the next :option:`\`verilog` mode switch and treat it as Verilator configuration commands. See :ref:`Configuration Files`. +.. option:: `VERILATOR_TIMING + + The VERILATOR_TIMING define is set when :vlopt:`--timing` is used to + allow an "\`ifdef" of code dependent on this feature. Note this define + is not affected by the :option:`timing_off` configuration file option + nor timing metacomments. + .. option:: `verilog Switch back to processing Verilog code after a diff --git a/src/V3Options.cpp b/src/V3Options.cpp index a13c15c48..3ec99660f 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -833,6 +833,9 @@ void V3Options::notify() { if (!m_dumpLevel.count("tree") && m_dumpLevel.count("tree-dot")) { m_dumpLevel["tree"] = m_dumpLevel["tree-dot"]; } + + // Preprocessor defines based on options used + if (timing().isSetTrue()) V3PreShell::defineCmdLine("VERILATOR_TIMING", "1"); } //###################################################################### diff --git a/test_regress/t/t_notiming.v b/test_regress/t/t_notiming.v index 8c822d4d2..649888e1f 100644 --- a/test_regress/t/t_notiming.v +++ b/test_regress/t/t_notiming.v @@ -26,3 +26,7 @@ module t; initial #1 ->e; initial #2 $stop; // timeout endmodule + +`ifdef VERILATOR_TIMING +`error "VERILATOR_TIMING should not be defined with --no-timing" +`endif diff --git a/test_regress/t/t_timing_events.v b/test_regress/t/t_timing_events.v index 583c66808..24065256b 100644 --- a/test_regress/t/t_timing_events.v +++ b/test_regress/t/t_timing_events.v @@ -30,3 +30,7 @@ module t; initial #21 $stop; // timeout endmodule + +`ifndef VERILATOR_TIMING +`error "VERILATOR_TIMING should have been defined as have --timing" +`endif