diff --git a/docs/guide/exe_verilator.rst b/docs/guide/exe_verilator.rst index 87f9db880..99c4bd0ec 100644 --- a/docs/guide/exe_verilator.rst +++ b/docs/guide/exe_verilator.rst @@ -125,9 +125,12 @@ Summary: After generating the SystemC/C++ code, Verilator will invoke the toolchain to build the model library (and executable when :vlopt:`--exe` - is also used). Verilator manages the build itself, and for this --build + is also used). Verilator manages the build itself, and for this --build requires GNU Make to be available on the platform. + :vlopt:`--build` cannot be specified when using :vlopt:`-E`, + :vlopt:`--dpi-hdr-only`, :vlopt:`--lint-only`, or :vlopt:`--xml-only`. + .. option:: --build-dep-bin Rarely needed. When a dependency (.d) file is created, this filename diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 47ac50329..39e74fa95 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -806,6 +806,24 @@ void V3Options::notify() { cmdfl->v3error("--make cannot be used together with --build. Suggest see manual"); } + // m_build, m_preprocOnly, m_dpiHdrOnly, m_lintOnly, and m_xmlOnly are mutually exclusive + std::vector backendFlags; + if (m_build) { + if (m_binary) backendFlags.push_back("--binary"); + else backendFlags.push_back("--build"); + } + if (m_preprocOnly) backendFlags.push_back("-E"); + if (m_dpiHdrOnly) backendFlags.push_back("--dpi-hdr-only"); + if (m_lintOnly) backendFlags.push_back("--lint-only"); + if (m_xmlOnly) backendFlags.push_back("--xml-only"); + if (backendFlags.size() > 1) { + std::string backendFlagsString = backendFlags.front(); + for (size_t i = 1; i < backendFlags.size(); i++) { + backendFlagsString += ", " + backendFlags[i]; + } + v3error("The following cannot be used together: " + backendFlagsString + ". Suggest see manual"); + } + if (m_exe && !v3Global.opt.libCreate().empty()) { cmdfl->v3error("--exe cannot be used together with --lib-create. Suggest see manual"); } @@ -1081,6 +1099,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char FileLine::globalWarnOff(V3ErrorCode::E_UNSUPPORTED, true); }); DECL_OPTION("-binary", CbCall, [this]() { + m_binary = true; m_build = true; m_exe = true; m_main = true; diff --git a/src/V3Options.h b/src/V3Options.h index f68c32d11..dc2d011a8 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -223,6 +223,7 @@ private: bool m_autoflush = false; // main switch: --autoflush bool m_bboxSys = false; // main switch: --bbox-sys bool m_bboxUnsup = false; // main switch: --bbox-unsup + bool m_binary = false; // main switch: --binary bool m_build = false; // main switch: --build bool m_cmake = false; // main switch: --make cmake bool m_context = true; // main switch: --Wcontext @@ -442,6 +443,7 @@ public: bool autoflush() const { return m_autoflush; } bool bboxSys() const { return m_bboxSys; } bool bboxUnsup() const { return m_bboxUnsup; } + bool binary() const { return m_binary; } bool build() const { return m_build; } string buildDepBin() const { return m_buildDepBin; } void buildDepBin(const string& flag) { m_buildDepBin = flag; } diff --git a/test_regress/t/t_flag_only_bad.out b/test_regress/t/t_flag_only_bad.out new file mode 100755 index 000000000..ae416db51 --- /dev/null +++ b/test_regress/t/t_flag_only_bad.out @@ -0,0 +1,2 @@ +%Error: The following cannot be used together: --binary, -E, --dpi-hdr-only, --lint-only, --xml-only. Suggest see manual +%Error: Exiting due to diff --git a/test_regress/t/t_flag_only_bad.pl b/test_regress/t/t_flag_only_bad.pl new file mode 100755 index 000000000..6fb0c0314 --- /dev/null +++ b/test_regress/t/t_flag_only_bad.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(vlt => 1); +top_filename("t/t_flag_main.v"); + +compile( + verilator_make_cmake => 0, + verilator_make_gmake => 0, + verilator_flags2 => ["--binary -E --dpi-hdr-only --lint-only --xml-only -Wall"], + fails => 1, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_flag_only_bad2.out b/test_regress/t/t_flag_only_bad2.out new file mode 100755 index 000000000..f67b538ce --- /dev/null +++ b/test_regress/t/t_flag_only_bad2.out @@ -0,0 +1,2 @@ +%Error: The following cannot be used together: --build, -E, --dpi-hdr-only, --lint-only, --xml-only. Suggest see manual +%Error: Exiting due to diff --git a/test_regress/t/t_flag_only_bad2.pl b/test_regress/t/t_flag_only_bad2.pl new file mode 100755 index 000000000..34c252411 --- /dev/null +++ b/test_regress/t/t_flag_only_bad2.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(vlt => 1); +top_filename("t/t_flag_main.v"); + +compile( + verilator_make_cmake => 0, + verilator_make_gmake => 0, + verilator_flags2 => ["--build -E -Wno-fatal --dpi-hdr-only --lint-only --xml-only"], + fails => 1, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_flag_only_bad3.out b/test_regress/t/t_flag_only_bad3.out new file mode 100755 index 000000000..de3cf93a8 --- /dev/null +++ b/test_regress/t/t_flag_only_bad3.out @@ -0,0 +1,2 @@ +%Error: The following cannot be used together: --dpi-hdr-only, --lint-only, --xml-only. Suggest see manual +%Error: Exiting due to diff --git a/test_regress/t/t_flag_only_bad3.pl b/test_regress/t/t_flag_only_bad3.pl new file mode 100755 index 000000000..f21368eec --- /dev/null +++ b/test_regress/t/t_flag_only_bad3.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(vlt => 1); +top_filename("t/t_flag_main.v"); + +compile( + verilator_make_cmake => 0, + verilator_make_gmake => 0, + verilator_flags2 => ["-Wall --lint-only -Wno-fatal --dpi-hdr-only --xml-only"], + fails => 1, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_lint_eofline.pl b/test_regress/t/t_lint_eofline.pl index be8639453..709ff432e 100755 --- a/test_regress/t/t_lint_eofline.pl +++ b/test_regress/t/t_lint_eofline.pl @@ -26,7 +26,7 @@ top_filename("$Self->{obj_dir}/t_lint_eofline_bad.v"); gen($Self->{top_filename}); lint( - verilator_flags2 => ["--lint-only -Wall -Wno-DECLFILENAME -E"], + verilator_flags2 => ["-E -Wall -Wno-DECLFILENAME"], expect_filename => $Self->{golden_filename}, );