Add --main to generate main() C++ (previously was experimental only) (#3265).

This commit is contained in:
Wilson Snyder 2022-09-14 20:18:40 -04:00
parent 9efd64ab98
commit 75fd71d7e5
6 changed files with 26 additions and 8 deletions

View File

@ -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]

View File

@ -343,6 +343,7 @@ detailed descriptions of these arguments.
--lint-only Lint, but do not make output
--make <build-tool> Generate scripts for specified build tool
-MAKEFLAGS <flags> Arguments to pass to make during --build
--main Generate C++ main()
--max-num-width <value> Maximum number width (default: 64K)
--Mdir <directory> Name of output object directory
--MMD Create .d dependency files

View File

@ -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 <value>
Set the maximum number literal width (e.g. in 1024'd22 this it the

View File

@ -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;

View File

@ -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; }

View File

@ -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,