diff --git a/Changes b/Changes index 5502f48a7..d0f057a5e 100644 --- a/Changes +++ b/Changes @@ -20,6 +20,7 @@ Verilator 4.227 devel **Minor:** * Support IEEE constant signal strengths (#3601). [Ryszard Rozak/Antmicro] +* Add --main to generate main() C++ (previously was experimental only). * Fix thread saftey in SystemC VL_ASSIGN_SBW/WSB (#3494) (#3513). [Mladen Slijepcevic] * Fix crash in gate optimization of circular logic (#3543). [Bill Flynn] * Fix arguments in non-static method call (#3547) (#3582). [Gustav Svensk] diff --git a/bin/verilator b/bin/verilator index 62f7be232..74c5b49c6 100755 --- a/bin/verilator +++ b/bin/verilator @@ -343,6 +343,7 @@ detailed descriptions of these arguments. --lint-only Lint, but do not make output --make Generate scripts for specified build tool -MAKEFLAGS Arguments to pass to make during --build + --main Generate C++ main() --max-num-width Maximum number width (default: 64K) --Mdir Name of output object directory --MMD Create .d dependency files diff --git a/docs/guide/exe_verilator.rst b/docs/guide/exe_verilator.rst index 0348c4db2..8d2ccda86 100644 --- a/docs/guide/exe_verilator.rst +++ b/docs/guide/exe_verilator.rst @@ -709,6 +709,15 @@ Summary: (e.g. ``-MAKEFLAGS -l -MAKEFLAGS -k``). Use of this option should not be required for simple builds using the host toolchain. +.. option:: --main + + Generates a top-level C++ main() file that supports parsing arguments, + but does not drive any inputs. This is sufficient to use for top-level + SystemVerilog designs that has no inputs, and does not need the C++ to + do any time advancement. + + Implies :vlopt:`--cc` if no other output mode was provided. + .. option:: --max-num-width Set the maximum number literal width (e.g. in 1024'd22 this it the diff --git a/src/V3Options.cpp b/src/V3Options.cpp index e1f194e8b..474cc3e57 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -435,6 +435,11 @@ string V3Options::allArgsStringForHierBlock(bool forTop) const { return out; } +void V3Options::ccSet() { // --cc + m_outFormatOk = true; + m_systemC = false; +} + //###################################################################### // File searching @@ -719,9 +724,10 @@ bool V3Options::systemCFound() { // V3 Options notification methods void V3Options::notify() { - FileLine* const cmdfl = new FileLine(FileLine::commandLineFilename()); - // Notify that all arguments have been passed and final modification can be made. + FileLine* const cmdfl = new FileLine{FileLine::commandLineFilename()}; + + if (!outFormatOk() && v3Global.opt.main()) ccSet(); // --main implies --cc if not provided if (!outFormatOk() && !cdc() && !dpiHdrOnly() && !lintOnly() && !preprocOnly() && !xmlOnly()) { v3fatal("verilator: Need --cc, --sc, --cdc, --dpi-hdr-only, --lint-only, " "--xml-only or --E option"); @@ -1002,10 +1008,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char DECL_OPTION("-build", Set, &m_build); DECL_OPTION("-CFLAGS", CbVal, callStrSetter(&V3Options::addCFlags)); - DECL_OPTION("-cc", CbCall, [this]() { - m_outFormatOk = true; - m_systemC = false; - }); + DECL_OPTION("-cc", CbCall, [this]() { ccSet(); }); DECL_OPTION("-cdc", OnOff, &m_cdc); DECL_OPTION("-clk", CbVal, callStrSetter(&V3Options::addClocker)); DECL_OPTION("-no-clk", CbVal, callStrSetter(&V3Options::addNoClocker)); @@ -1175,7 +1178,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char m_makeDir = valp; addIncDirFallback(m_makeDir); // Need to find generated files there too }); - DECL_OPTION("-main", OnOff, &m_main).undocumented(); // Future + DECL_OPTION("-main", OnOff, &m_main); DECL_OPTION("-make", CbVal, [this, fl](const char* valp) { if (!strcmp(valp, "cmake")) { m_cmake = true; diff --git a/src/V3Options.h b/src/V3Options.h index 8637277bb..190d4c7ab 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -410,8 +410,9 @@ public: void addNoClocker(const string& signame); void addVFile(const string& filename); void addForceInc(const string& filename); - void notify(); bool available() const { return m_available; } + void ccSet(); + void notify(); // ACCESSORS (options) bool preprocOnly() const { return m_preprocOnly; } diff --git a/test_regress/t/t_flag_main.pl b/test_regress/t/t_flag_main.pl index 381004460..57041562f 100755 --- a/test_regress/t/t_flag_main.pl +++ b/test_regress/t/t_flag_main.pl @@ -11,6 +11,9 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di scenarios(simulator => 1); compile( + verilator_flags => [# Custom as don't want -cc + "-Mdir $Self->{obj_dir}", + "--debug-check", ], verilator_flags2 => ['--exe --build --main'], verilator_make_cmake => 0, verilator_make_gmake => 0,