From e566b5a4f5388fac0368f3327f556fd44ed3c8d8 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 9 Sep 2024 20:18:54 -0400 Subject: [PATCH] Change .vlt config files to be read before .v files (#5185). --- Changes | 1 + docs/guide/exe_verilator.rst | 8 ++++++-- src/V3Global.cpp | 7 +++++++ src/V3Options.cpp | 3 +++ src/V3Options.h | 3 +++ test_regress/t/t_vlt_match_error_1.out | 4 ---- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index 7b279a9d4..f71caa82f 100644 --- a/Changes +++ b/Changes @@ -17,6 +17,7 @@ Verilator 5.029 devel **Minor:** +* Change .vlt config files to be read before .v files (#5185). [David Moberg] * Support IEEE-compliant intra-assign delays (#3711) (#5441). [Krzysztof Bieganski, Antmicro Ltd.] * Support unconstrained randomization for unions (#5395) (#5396). [Yilou Wang] * Support appending to queue via `[]` (#5421). [Krzysztof Bieganski, Antmicro Ltd.] diff --git a/docs/guide/exe_verilator.rst b/docs/guide/exe_verilator.rst index fe70225cd..b46ca1c33 100644 --- a/docs/guide/exe_verilator.rst +++ b/docs/guide/exe_verilator.rst @@ -1909,8 +1909,12 @@ Configuration Files In addition to the command line, warnings and other features for the :command:`verilator` command may be controlled with configuration files, -typically named with the .vlt extension (what makes it a configuration file -is the :option:`\`verilator_config` directive). An example: +typically named with the `.vlt` extension (what makes it a configuration +file is the :option:`\`verilator_config` directive). These files, when +named `.vlt`, are read before source code files; if this behavior is +undesired, name the config file with a `.v` suffix. + +An example: .. code-block:: sv diff --git a/src/V3Global.cpp b/src/V3Global.cpp index 5f0a76ac7..bb4170898 100644 --- a/src/V3Global.cpp +++ b/src/V3Global.cpp @@ -58,6 +58,13 @@ void V3Global::readFiles() { V3Parse parser{v3Global.rootp(), &filter, &parseSyms}; + // Read .vlt files + const V3StringSet& vltFiles = v3Global.opt.vltFiles(); + for (const string& filename : vltFiles) { + parser.parseFile(new FileLine{FileLine::commandLineFilename()}, filename, false, + "Cannot find file containing .vlt file: "); + } + // Parse the std package if (v3Global.opt.std()) { parser.parseFile(new FileLine{V3Options::getStdPackagePath()}, diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 0c033487b..0c22a4b6e 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -395,6 +395,7 @@ void V3Options::addVFile(const string& filename) { // in a specific order and multiple of them. m_vFiles.push_back(filename); } +void V3Options::addVltFile(const string& filename) { m_vltFiles.insert(filename); } void V3Options::addForceInc(const string& filename) { m_forceIncs.push_back(filename); } void V3Options::addLineArg(const string& arg) { m_impp->m_lineArgs.push_back(arg); } @@ -1772,6 +1773,8 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, || suffixed(filename, ".o") // || suffixed(filename, ".so")) { V3Options::addLdLibs(filename); + } else if (suffixed(filename, ".vlt")) { + V3Options::addVltFile(filename); } else { V3Options::addVFile(filename); } diff --git a/src/V3Options.h b/src/V3Options.h index c15440de4..bd2a40d1c 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -210,6 +210,7 @@ private: V3StringSet m_clockers; // argument: Verilog -clk signals V3StringSet m_noClockers; // argument: Verilog -noclk signals V3StringList m_vFiles; // argument: Verilog files to read + V3StringSet m_vltFiles; // argument: Verilator config files to read V3StringList m_forceIncs; // argument: -FI DebugLevelMap m_debugLevel; // argument: --debugi- DebugLevelMap m_dumpLevel; // argument: --dumpi- @@ -444,6 +445,7 @@ public: void addClocker(const string& signame); void addNoClocker(const string& signame); void addVFile(const string& filename); + void addVltFile(const string& filename); void addForceInc(const string& filename); bool available() const VL_MT_SAFE { return m_available; } void ccSet(); @@ -638,6 +640,7 @@ public: const V3StringList& makeFlags() const { return m_makeFlags; } const V3StringSet& libraryFiles() const { return m_libraryFiles; } const V3StringList& vFiles() const { return m_vFiles; } + const V3StringSet& vltFiles() const { return m_vltFiles; } const V3StringList& forceIncs() const { return m_forceIncs; } bool hasParameter(const string& name); diff --git a/test_regress/t/t_vlt_match_error_1.out b/test_regress/t/t_vlt_match_error_1.out index ffd388fbb..1971bca8e 100644 --- a/test_regress/t/t_vlt_match_error_1.out +++ b/test_regress/t/t_vlt_match_error_1.out @@ -1,7 +1,3 @@ -%Error-PKGNODECL: t/t_vlt_match_error.v:17:12: Package/class 'hi' not found, and needs to be predeclared (IEEE 1800-2023 26.3) - 17 | import hi::*; - | ^~ - ... For error description see https://verilator.org/warn/PKGNODECL?v=latest %Error: t/t_vlt_match_error.v:17:12: Importing from missing package 'hi' 17 | import hi::*; | ^~