From b4ee8fb021db8da5db24f4147a25d60cd1d22339 Mon Sep 17 00:00:00 2001 From: MikePopoloski Date: Fri, 8 Mar 2024 22:20:44 -0500 Subject: [PATCH] Add LanguageVersion enum, --std driver option to set it (currently does nothing), rename Version.h -> VersionInfo.h --- bindings/python/CompBindings.cpp | 5 +++++ bindings/python/UtilBindings.cpp | 2 +- docs/command-line-ref.dox | 7 +++++++ include/slang/driver/Driver.h | 7 +++++++ include/slang/util/LanguageVersion.h | 15 +++++++++++++++ include/slang/util/{Version.h => VersionInfo.h} | 2 +- source/CMakeLists.txt | 6 +++--- source/driver/Driver.cpp | 16 ++++++++++++++++ source/parsing/Preprocessor.cpp | 2 +- .../util/{Version.cpp.in => VersionInfo.cpp.in} | 4 ++-- tools/driver/slang_main.cpp | 2 +- tools/netlist/netlist.cpp | 2 +- tools/reflect/src/reflect.cpp | 2 +- tools/tidy/src/tidy.cpp | 2 +- 14 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 include/slang/util/LanguageVersion.h rename include/slang/util/{Version.h => VersionInfo.h} (97%) rename source/util/{Version.cpp.in => VersionInfo.cpp.in} (92%) diff --git a/bindings/python/CompBindings.cpp b/bindings/python/CompBindings.cpp index f07d8059b..e9fb85aa5 100644 --- a/bindings/python/CompBindings.cpp +++ b/bindings/python/CompBindings.cpp @@ -166,6 +166,10 @@ void registerCompilation(py::module_& m) { .def_readwrite("expandEnvVars", &CommandLine::ParseOptions::expandEnvVars) .def_readwrite("ignoreDuplicates", &CommandLine::ParseOptions::ignoreDuplicates); + py::enum_(m, "LanguageVersion") + .value("v1800_2017", LanguageVersion::v1800_2017) + .value("v1800_2023", LanguageVersion::v1800_2023); + py::class_(m, "Driver") .def(py::init<>()) .def_readonly("sourceManager", &Driver::sourceManager) @@ -173,6 +177,7 @@ void registerCompilation(py::module_& m) { .def_readonly("diagClient", &Driver::diagClient) .def_readonly("sourceLoader", &Driver::sourceLoader) .def_readonly("syntaxTrees", &Driver::syntaxTrees) + .def_readwrite("languageVersion", &Driver::languageVersion) .def("addStandardArgs", &Driver::addStandardArgs) .def( "parseCommandLine", diff --git a/bindings/python/UtilBindings.cpp b/bindings/python/UtilBindings.cpp index 3ea4a164c..db2cb1349 100644 --- a/bindings/python/UtilBindings.cpp +++ b/bindings/python/UtilBindings.cpp @@ -18,7 +18,7 @@ #include "slang/text/SourceManager.h" #include "slang/util/Bag.h" #include "slang/util/BumpAllocator.h" -#include "slang/util/Version.h" +#include "slang/util/VersionInfo.h" namespace fs = std::filesystem; diff --git a/docs/command-line-ref.dox b/docs/command-line-ref.dox index 68aa6c775..26417550d 100644 --- a/docs/command-line-ref.dox +++ b/docs/command-line-ref.dox @@ -17,6 +17,13 @@ Display slang version information and exit. Don't print non-essential output status. +`--std (1800-2017 | 1800-2023 | latest)` + +Sets the version of the SystemVerilog language to use. This changes how the code is parsed +and elaborated and which language features are available to use. The current default is +1800-2017, though this may change in the future. Using "latest" will use the latest available +version, currently 1800-2023. + `positional arguments` Paths to files (using @ref file-patterns "file patterns") that should be included in the compilation. diff --git a/include/slang/driver/Driver.h b/include/slang/driver/Driver.h index 8cf2bfe63..ee8a569b9 100644 --- a/include/slang/driver/Driver.h +++ b/include/slang/driver/Driver.h @@ -13,6 +13,7 @@ #include "slang/text/SourceManager.h" #include "slang/util/Bag.h" #include "slang/util/CommandLine.h" +#include "slang/util/LanguageVersion.h" #include "slang/util/OS.h" #include "slang/util/Util.h" @@ -74,9 +75,15 @@ class SLANG_EXPORT Driver { /// A list of syntax trees that have been parsed. std::vector> syntaxTrees; + /// The version of the SystemVerilog language to use. + LanguageVersion languageVersion = LanguageVersion::v1800_2017; + /// A container for various options that can be parsed and applied /// to the compilation process. struct SLANG_EXPORT Options { + /// The version of the SystemVerilog language to use. + std::optional languageVersion; + /// @name Preprocessing /// @{ diff --git a/include/slang/util/LanguageVersion.h b/include/slang/util/LanguageVersion.h new file mode 100644 index 000000000..ffb3a5cc6 --- /dev/null +++ b/include/slang/util/LanguageVersion.h @@ -0,0 +1,15 @@ +//------------------------------------------------------------------------------ +//! @file LanguageVersion.h +//! @brief Enum specify SystemVerilog language versions +// +// SPDX-FileCopyrightText: Michael Popoloski +// SPDX-License-Identifier: MIT +//------------------------------------------------------------------------------ +#pragma once + +namespace slang { + +/// Specifies SystemVerilog language versions. +enum class LanguageVersion { v1800_2017, v1800_2023 }; + +} // namespace slang diff --git a/include/slang/util/Version.h b/include/slang/util/VersionInfo.h similarity index 97% rename from include/slang/util/Version.h rename to include/slang/util/VersionInfo.h index e92e9871f..9d0899b14 100644 --- a/include/slang/util/Version.h +++ b/include/slang/util/VersionInfo.h @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -//! @file Version.h +//! @file VersionInfo.h //! @brief Library build-time version information // // SPDX-FileCopyrightText: Michael Popoloski diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 6197cc441..13b6aeedf 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -32,8 +32,8 @@ add_custom_command( COMMENT "Generating syntax") # Generate version header -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/util/Version.cpp.in - ${CMAKE_CURRENT_BINARY_DIR}/Version.cpp @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/util/VersionInfo.cpp.in + ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.cpp @ONLY) # -------- Primary library target add_library( @@ -42,7 +42,7 @@ add_library( ${CMAKE_CURRENT_BINARY_DIR}/SyntaxClone.cpp ${CMAKE_CURRENT_BINARY_DIR}/DiagCode.cpp ${CMAKE_CURRENT_BINARY_DIR}/TokenKind.cpp - ${CMAKE_CURRENT_BINARY_DIR}/Version.cpp + ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.cpp ${CMAKE_CURRENT_BINARY_DIR}/slang/diagnostics/AllDiags.h diagnostics/DiagnosticClient.cpp diagnostics/DiagnosticEngine.cpp diff --git a/source/driver/Driver.cpp b/source/driver/Driver.cpp index 54cd3ba29..d153a26cd 100644 --- a/source/driver/Driver.cpp +++ b/source/driver/Driver.cpp @@ -45,6 +45,10 @@ Driver::Driver() : diagEngine(sourceManager), sourceLoader(sourceManager) { } void Driver::addStandardArgs() { + cmdLine.add("--std", options.languageVersion, + "The version of the SystemVerilog language to use", + "(1800-2017 | 1800-2023 | latest)"); + // Include paths cmdLine.add( "-I,--include-directory,+incdir", @@ -414,6 +418,18 @@ bool Driver::processOptions() { OS::setStdoutColorsEnabled(true); } + if (options.languageVersion.has_value()) { + if (options.languageVersion == "1800-2017") + languageVersion = LanguageVersion::v1800_2017; + else if (options.languageVersion == "1800-2023" || options.languageVersion == "latest") + languageVersion = LanguageVersion::v1800_2023; + else { + printError( + fmt::format("invalid value for --std option: '{}'", *options.languageVersion)); + return false; + } + } + if (options.compat.has_value()) { if (options.compat == "vcs") { auto vcsCompatFlags = {CompilationFlags::AllowHierarchicalConst, diff --git a/source/parsing/Preprocessor.cpp b/source/parsing/Preprocessor.cpp index 24e6fb2c5..8997bb2f5 100644 --- a/source/parsing/Preprocessor.cpp +++ b/source/parsing/Preprocessor.cpp @@ -13,7 +13,7 @@ #include "slang/text/SourceManager.h" #include "slang/util/BumpAllocator.h" #include "slang/util/String.h" -#include "slang/util/Version.h" +#include "slang/util/VersionInfo.h" namespace slang::parsing { diff --git a/source/util/Version.cpp.in b/source/util/VersionInfo.cpp.in similarity index 92% rename from source/util/Version.cpp.in rename to source/util/VersionInfo.cpp.in index 21600ddc0..d42298524 100644 --- a/source/util/Version.cpp.in +++ b/source/util/VersionInfo.cpp.in @@ -1,11 +1,11 @@ //------------------------------------------------------------------------------ -// Version.cpp +// VersionInfo.cpp // Input file for build-time version source generation // // SPDX-FileCopyrightText: Michael Popoloski // SPDX-License-Identifier: MIT //------------------------------------------------------------------------------ -#include "slang/util/Version.h" +#include "slang/util/VersionInfo.h" using std::string_view; using namespace std::literals; diff --git a/tools/driver/slang_main.cpp b/tools/driver/slang_main.cpp index 8c74cadeb..0c72f0df0 100644 --- a/tools/driver/slang_main.cpp +++ b/tools/driver/slang_main.cpp @@ -18,7 +18,7 @@ #include "slang/text/Json.h" #include "slang/util/String.h" #include "slang/util/TimeTrace.h" -#include "slang/util/Version.h" +#include "slang/util/VersionInfo.h" using namespace slang; using namespace slang::ast; diff --git a/tools/netlist/netlist.cpp b/tools/netlist/netlist.cpp index 050d3e671..831732b1b 100644 --- a/tools/netlist/netlist.cpp +++ b/tools/netlist/netlist.cpp @@ -28,7 +28,7 @@ #include "slang/util/String.h" #include "slang/util/TimeTrace.h" #include "slang/util/Util.h" -#include "slang/util/Version.h" +#include "slang/util/VersionInfo.h" using namespace slang; using namespace slang::ast; diff --git a/tools/reflect/src/reflect.cpp b/tools/reflect/src/reflect.cpp index ea7dac24f..fd6394b4d 100644 --- a/tools/reflect/src/reflect.cpp +++ b/tools/reflect/src/reflect.cpp @@ -12,7 +12,7 @@ #include #include "slang/driver/Driver.h" -#include "slang/util/Version.h" +#include "slang/util/VersionInfo.h" using namespace slang; diff --git a/tools/tidy/src/tidy.cpp b/tools/tidy/src/tidy.cpp index 5568ab1fa..01374714b 100644 --- a/tools/tidy/src/tidy.cpp +++ b/tools/tidy/src/tidy.cpp @@ -16,7 +16,7 @@ #include "slang/ast/Compilation.h" #include "slang/diagnostics/TextDiagnosticClient.h" #include "slang/driver/Driver.h" -#include "slang/util/Version.h" +#include "slang/util/VersionInfo.h" /// Performs a search for the .slang-tidy file on the current directory. If the file is not found, /// tries on the parent directory until the root.