Skip to content

Commit

Permalink
Add LanguageVersion enum, --std driver option to set it (currently do…
Browse files Browse the repository at this point in the history
…es nothing), rename Version.h -> VersionInfo.h
  • Loading branch information
MikePopoloski committed Mar 9, 2024
1 parent 9df2ea8 commit b4ee8fb
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 12 deletions.
5 changes: 5 additions & 0 deletions bindings/python/CompBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,18 @@ void registerCompilation(py::module_& m) {
.def_readwrite("expandEnvVars", &CommandLine::ParseOptions::expandEnvVars)
.def_readwrite("ignoreDuplicates", &CommandLine::ParseOptions::ignoreDuplicates);

py::enum_<LanguageVersion>(m, "LanguageVersion")
.value("v1800_2017", LanguageVersion::v1800_2017)
.value("v1800_2023", LanguageVersion::v1800_2023);

py::class_<Driver>(m, "Driver")
.def(py::init<>())
.def_readonly("sourceManager", &Driver::sourceManager)
.def_readonly("diagEngine", &Driver::diagEngine)
.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",
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/UtilBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions docs/command-line-ref.dox
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions include/slang/driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -74,9 +75,15 @@ class SLANG_EXPORT Driver {
/// A list of syntax trees that have been parsed.
std::vector<std::shared_ptr<syntax::SyntaxTree>> 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<std::string> languageVersion;

/// @name Preprocessing
/// @{

Expand Down
15 changes: 15 additions & 0 deletions include/slang/util/LanguageVersion.h
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
//! @file Version.h
//! @file VersionInfo.h
//! @brief Library build-time version information
//
// SPDX-FileCopyrightText: Michael Popoloski
Expand Down
6 changes: 3 additions & 3 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions source/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion source/parsing/Preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 2 additions & 2 deletions source/util/Version.cpp.in → source/util/VersionInfo.cpp.in
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/driver/slang_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/netlist/netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/reflect/src/reflect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <optional>

#include "slang/driver/Driver.h"
#include "slang/util/Version.h"
#include "slang/util/VersionInfo.h"

using namespace slang;

Expand Down
2 changes: 1 addition & 1 deletion tools/tidy/src/tidy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b4ee8fb

Please sign in to comment.