From 7c8ff1d19c79400d0e0d5abb3adc7c6e404b120d Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 11 Nov 2024 08:30:07 -0500 Subject: [PATCH] Add `--no-std-package` as subset-alias of `--no-std`. --- Changes | 1 + bin/verilator | 3 ++- docs/guide/exe_verilator.rst | 8 +++++++- src/V3Global.cpp | 2 +- src/V3Options.cpp | 5 +++-- src/V3Options.h | 4 ++-- test_regress/t/t_no_std_pkg_bad.py | 20 ++++++++++++++++++++ 7 files changed, 36 insertions(+), 7 deletions(-) create mode 100755 test_regress/t/t_no_std_pkg_bad.py diff --git a/Changes b/Changes index a5effd1d4..c958b258a 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,7 @@ Verilator 5.031 devel * Support queue's assignment `push_back/push_front('{})` (#5585) (#5586). [Yilou Wang] * Support basic constrained random for multi-dimensional dynamic array and queue (#5591). [Yilou Wang] * Support `pure constraint`. +* Add `--no-std-package` as subset-alias of `--no-std`. * Add error on illegal enum base type (#3010). [Iztok Jeras] * Add error on `wait` with missing `.triggered` (#4457). * Add error when improperly storing to parameter (#5147). [Gökçe Aydos] diff --git a/bin/verilator b/bin/verilator index 1ca6d3b8c..fea7d9008 100755 --- a/bin/verilator +++ b/bin/verilator @@ -448,7 +448,8 @@ detailed descriptions of these arguments. --no-skip-identical Disable skipping identical output --stats Create statistics file --stats-vars Provide statistics on variables - --no-std Prevent parsing standard library + --no-std Prevent loading standard files + --no-std-package Prevent parsing standard package --no-stop-fail Do not call $stop when assertion fails --structs-packed Convert all unpacked structures to packed structures -sv Enable SystemVerilog parsing diff --git a/docs/guide/exe_verilator.rst b/docs/guide/exe_verilator.rst index 1ec0efd4e..d6b979c81 100644 --- a/docs/guide/exe_verilator.rst +++ b/docs/guide/exe_verilator.rst @@ -1363,7 +1363,13 @@ Summary: .. option:: --no-std - Prevents parsing standard library. + Prevents parsing standard input files, alias for + :opt:`--no-std-package`. This may be extended to prevent reading other + standardized files in future versions. + +.. option:: --no-std-package + + Prevents parsing standard `std::` package file. .. option:: --no-stop-fail diff --git a/src/V3Global.cpp b/src/V3Global.cpp index bb4170898..924a664e1 100644 --- a/src/V3Global.cpp +++ b/src/V3Global.cpp @@ -66,7 +66,7 @@ void V3Global::readFiles() { } // Parse the std package - if (v3Global.opt.std()) { + if (v3Global.opt.stdPackage()) { parser.parseFile(new FileLine{V3Options::getStdPackagePath()}, V3Options::getStdPackagePath(), false, "Cannot find verilated_std.sv containing built-in std:: definitions: "); diff --git a/src/V3Options.cpp b/src/V3Options.cpp index c55af2780..6d59c99d1 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -1258,7 +1258,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, DECL_OPTION("-json-edit-nums", OnOff, &m_jsonEditNums); DECL_OPTION("-json-ids", OnOff, &m_jsonIds); DECL_OPTION("-E", CbOnOff, [this](bool flag) { - if (flag) m_std = false; + if (flag) m_stdPackage = false; m_preprocOnly = flag; }); DECL_OPTION("-emit-accessors", OnOff, &m_emitAccessors); @@ -1512,7 +1512,8 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, m_statsVars = flag; m_stats |= flag; }); - DECL_OPTION("-std", OnOff, &m_std); + DECL_OPTION("-std", CbOnOff, [this](bool flag) { m_stdPackage = flag; }); + DECL_OPTION("-std-package", OnOff, &m_stdPackage); DECL_OPTION("-stop-fail", OnOff, &m_stopFail); DECL_OPTION("-structs-packed", OnOff, &m_structsPacked); DECL_OPTION("-sv", CbCall, [this]() { m_defaultLanguage = V3LangCode::L1800_2023; }); diff --git a/src/V3Options.h b/src/V3Options.h index 67f66cd18..74de94871 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -279,7 +279,7 @@ private: bool m_relativeIncludes = false; // main switch: --relative-includes bool m_reportUnoptflat = false; // main switch: --report-unoptflat bool m_savable = false; // main switch: --savable - bool m_std = true; // main switch: --std + bool m_stdPackage = true; // main switch: --std-package bool m_structsPacked = false; // main switch: --structs-packed bool m_systemC = false; // main switch: --sc: System C instead of simple C++ bool m_stats = false; // main switch: --stats @@ -465,7 +465,7 @@ public: bool savable() const VL_MT_SAFE { return m_savable; } bool stats() const { return m_stats; } bool statsVars() const { return m_statsVars; } - bool std() const { return m_std; } + bool stdPackage() const { return m_stdPackage; } bool structsPacked() const { return m_structsPacked; } bool assertOn() const { return m_assert; } // assertOn as __FILE__ may be defined bool assertCaseOn() const { return m_assertCase || m_assert; } diff --git a/test_regress/t/t_no_std_pkg_bad.py b/test_regress/t/t_no_std_pkg_bad.py new file mode 100755 index 000000000..84dacb568 --- /dev/null +++ b/test_regress/t/t_no_std_pkg_bad.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2024 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 + +import vltest_bootstrap + +test.scenarios('simulator') +test.top_filename = "t/t_no_std_bad.v" +test.golden_filename = "t/t_no_std_bad.out" + +test.lint(fails=True, + verilator_flags2=["--no-std-package", "--exe --main --timing -Wall"], + expect_filename=test.golden_filename) + +test.passes()