From 84335b958015c2b15266cfbcc1b0a87b2d035c30 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 20 May 2018 08:36:39 -0400 Subject: [PATCH] Verilated: Cleanup command line parsing. Backport from pending v4 change. --- bin/verilator | 10 ++++++---- include/verilated.cpp | 40 +++++++++++++++++++++++++++++++++++++++- include/verilated.h | 3 ++- include/verilated_imp.h | 33 ++++++--------------------------- 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/bin/verilator b/bin/verilator index 42afcd3d1..f7376a484 100755 --- a/bin/verilator +++ b/bin/verilator @@ -249,8 +249,8 @@ To get started, jump down to "EXAMPLE C++ EXECUTION". =head1 ARGUMENT SUMMARY -This is a short summary of the arguments to Verilator. See the detailed -descriptions in the next sections for more information. +This is a short summary of the arguments to Verilator itself. See the +detailed descriptions in L for more information. {file.v} Verilog package, module and top module filenames {file.c/cc/cpp} Optional C++ files to compile in @@ -381,7 +381,9 @@ descriptions in the next sections for more information. -y Directory to search for modules -=head1 ARGUMENTS +=head1 VERILATION ARGUMENTS + +The following are the arguments that may be passed to Verilator itself. =over 4 @@ -1376,7 +1378,7 @@ not otherwise initialized. --x-initial=unique, the default, initializes variables using a function, which determines the value to use each initialization. This gives greatest -flexibility and allows finding reset bugs. See L +flexibility and allows finding reset bugs. See L. --x-initial=fast, is best for performance, and initializes all variables to a state Verilator determines is optimal. This may allow further code diff --git a/include/verilated.cpp b/include/verilated.cpp index 215a5f137..d3a9a5d73 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -42,7 +42,7 @@ VL_THREAD_LOCAL Verilated::ThreadLocal Verilated::t_s; struct Verilated::CommandArgValues Verilated::s_args = {0, NULL}; -VerilatedImp VerilatedImp::s_s; +VerilatedImp VerilatedImp::s_s; //=========================================================================== // User definable functions @@ -1740,6 +1740,44 @@ void Verilated::endOfEvalGuts(VerilatedEvalMsgQueue* evalMsgQp) VL_MT_SAFE { } #endif +//=========================================================================== +// VerilatedImp:: Methods + +void VerilatedImp::internalsDump() VL_MT_SAFE { + VerilatedLockGuard lock(s_s.m_argMutex); + VL_PRINTF_MT("internalsDump:\n"); + versionDump(); + VL_PRINTF_MT(" Argv:"); + for (ArgVec::const_iterator it=s_s.m_argVec.begin(); it!=s_s.m_argVec.end(); ++it) { + VL_PRINTF_MT(" %s",it->c_str()); + } + VL_PRINTF_MT("\n"); + scopesDump(); + exportsDump(); + userDump(); +} +void VerilatedImp::versionDump() VL_MT_SAFE { + VL_PRINTF_MT(" Version: %s %s\n", + Verilated::productName(), Verilated::productVersion()); +} + +void VerilatedImp::commandArgs(int argc, const char** argv) VL_EXCLUDES(s_s.m_argMutex) { + VerilatedLockGuard lock(s_s.m_argMutex); + s_s.m_argVec.clear(); // Always clear + commandArgsAddGuts(argc, argv); +} +void VerilatedImp::commandArgsAdd(int argc, const char** argv) VL_EXCLUDES(s_s.m_argMutex) { + VerilatedLockGuard lock(s_s.m_argMutex); + commandArgsAddGuts(argc, argv); +} +void VerilatedImp::commandArgsAddGuts(int argc, const char** argv) VL_REQUIRES(s_s.m_argMutex) { + if (!s_s.m_argVecLoaded) s_s.m_argVec.clear(); + for (int i=0; i(argv)); } + static void commandArgs(int argc, char** argv) VL_MT_SAFE { + commandArgs(argc, const_cast(argv)); } static void commandArgsAdd(int argc, const char** argv); static CommandArgValues* getCommandArgs() VL_MT_SAFE { return &s_args; } /// Match plusargs with a given prefix. Returns static char* valid only for a single call diff --git a/include/verilated_imp.h b/include/verilated_imp.h index 621eef154..505a25fdd 100644 --- a/include/verilated_imp.h +++ b/include/verilated_imp.h @@ -212,31 +212,14 @@ public: // But only for verilated*.cpp private: VL_UNCOPYABLE(VerilatedImp); public: - static void internalsDump() VL_MT_SAFE { - VerilatedLockGuard lock(s_s.m_argMutex); - VL_PRINTF_MT("internalsDump:\n"); - VL_PRINTF_MT(" Argv:"); - for (ArgVec::const_iterator it=s_s.m_argVec.begin(); it!=s_s.m_argVec.end(); ++it) { - VL_PRINTF_MT(" %s",it->c_str()); - } - VL_PRINTF_MT("\n"); - VL_PRINTF_MT(" Version: %s %s\n", Verilated::productName(), Verilated::productVersion()); - scopesDump(); - exportsDump(); - userDump(); - } + // METHODS - debug + static void internalsDump() VL_MT_SAFE; + static void versionDump() VL_MT_SAFE; // METHODS - arguments public: - static void commandArgs(int argc, const char** argv) VL_EXCLUDES(s_s.m_argMutex) { - VerilatedLockGuard lock(s_s.m_argMutex); - s_s.m_argVec.clear(); // Always clear - commandArgsAddGuts(argc, argv); - } - static void commandArgsAdd(int argc, const char** argv) VL_EXCLUDES(s_s.m_argMutex) { - VerilatedLockGuard lock(s_s.m_argMutex); - commandArgsAddGuts(argc, argv); - } + static void commandArgs(int argc, const char** argv) VL_EXCLUDES(s_s.m_argMutex); + static void commandArgsAdd(int argc, const char** argv) VL_EXCLUDES(s_s.m_argMutex); static std::string argPlusMatch(const char* prefixp) VL_EXCLUDES(s_s.m_argMutex) { VerilatedLockGuard lock(s_s.m_argMutex); // Note prefixp does not include the leading "+" @@ -255,11 +238,7 @@ public: return ""; } private: - static void commandArgsAddGuts(int argc, const char** argv) VL_REQUIRES(s_s.m_argMutex) { - if (!s_s.m_argVecLoaded) s_s.m_argVec.clear(); - for (int i=0; i