slang::driver::Driver class

A top-level class that handles argument parsing, option preparation, and invoking various parts of the slang compilation process.

This is exposed as a convenience wrapper around the various components that could otherwise be used on their own.

A typical compilation flow using the driver looks as follows:

Driver driver;
driver.addStandardArgs();
if (!driver.parseCommandLine(someStr)) { ...error }
if (!driver.processOptions()) { ...error }
if (!driver.parseAllSources()) { ...error }

auto compilation = driver.createCompilation();
if (!driver.reportCompilation(*compilation)) { ...error }
else { ...success }

Public types

struct Options
A container for various options that can be parsed and applied to the compilation process.

Constructors, destructors, conversion operators

Driver()
Constructs a new instance of the Driver class.

Public functions

void addStandardArgs()
Adds standard command line arguments to the cmdLine object.
template<typename TArgs>
auto parseCommandLine(int argc, TArgs argv) -> bool
Parses command line arguments from the given C-style argument list.
auto parseCommandLine(std::string_view argList, CommandLine::ParseOptions parseOptions = {}) -> bool
Parses command line arguments from the given string.
auto processCommandFiles(std::string_view pattern, bool makeRelative, bool separateUnit) -> bool
Processes the given command file(s) for more options.
auto processOptions() -> bool
Processes and applies all configured options.
auto runPreprocessor(bool includeComments, bool includeDirectives, bool obfuscateIds, bool useFixedObfuscationSeed = false) -> bool
Runs the preprocessor on all loaded buffers and outputs the result to stdout.
void reportMacros()
Prints all macros from all loaded buffers to stdout.
auto parseAllSources() -> bool
Parses all loaded buffers into syntax trees and appends the resulting trees to the syntaxTrees list.
auto createOptionBag() const -> Bag
Creates an options bag from all of the currently set options.
auto createCompilation() -> std::unique_ptr<ast::Compilation>
Creates a compilation object from all of the current loaded state of the driver.
auto reportParseDiags() -> bool
Reports all parsing diagnostics found in all of the syntaxTrees.
auto reportCompilation(ast::Compilation& compilation, bool quiet) -> bool
Reports the result of compilation.

Public variables

CommandLine cmdLine
The command line object that will be used to parse arguments if the parseCommandLine method is called.
SourceManager sourceManager
The source manager that holds all loaded source files.
DiagnosticEngine diagEngine
The diagnostics engine that will be used to report diagnostics.
std::shared_ptr<TextDiagnosticClient> diagClient
The diagnostics client that will be used to render diagnostics.
SourceLoader sourceLoader
The object that handles loading and parsing source files.
std::vector<std::shared_ptr<syntax::SyntaxTree>> syntaxTrees
A list of syntax trees that have been parsed.
LanguageVersion languageVersion
The version of the SystemVerilog language to use.

Function documentation

void slang::driver::Driver::addStandardArgs()

Adds standard command line arguments to the cmdLine object.

If not called, no arguments will be added by default, though the user can still add their own custom arguments if desired.

template<typename TArgs>
bool slang::driver::Driver::parseCommandLine(int argc, TArgs argv)

Parses command line arguments from the given C-style argument list.

This is templated to support both char and wchar_t arg lists. Any errors encountered will be printed to stderr.

bool slang::driver::Driver::parseCommandLine(std::string_view argList, CommandLine::ParseOptions parseOptions = {})

Parses command line arguments from the given string.

Any errors encountered will be printed to stderr.

bool slang::driver::Driver::processCommandFiles(std::string_view pattern, bool makeRelative, bool separateUnit)

Processes the given command file(s) for more options.

Parameters
pattern a file path pattern indicating the command file(s) to process.
makeRelative indicates whether paths in the file are relative to the file itself or to the current working directory.
separateUnit if true, the file is a separate compilation unit listing; options within it apply only to that unit and not the broader compilation.
Returns true on success and false if errors were encountered.

Any errors encountered will be printed to stderr.

bool slang::driver::Driver::processOptions()

Processes and applies all configured options.

Returns true on success and false if errors were encountered.

bool slang::driver::Driver::runPreprocessor(bool includeComments, bool includeDirectives, bool obfuscateIds, bool useFixedObfuscationSeed = false)

Runs the preprocessor on all loaded buffers and outputs the result to stdout.

Parameters
includeComments If true, comments will be included in the output.
includeDirectives If true, preprocessor directives will be included in the output.
obfuscateIds If true, identifiers will be obfuscated by replacing them with randomized alphanumeric strings.
useFixedObfuscationSeed If true, obfuscated identifiers will be generated with a fixed randomization seed, meaning they will be the same every time the program is run. Used for testing.
Returns true on success and false if errors were encountered.

Any errors encountered will be printed to stderr.

bool slang::driver::Driver::parseAllSources()

Parses all loaded buffers into syntax trees and appends the resulting trees to the syntaxTrees list.

Returns true on success and false if errors were encountered.

bool slang::driver::Driver::reportParseDiags()

Reports all parsing diagnostics found in all of the syntaxTrees.

Returns true on success and false if errors were encountered.

bool slang::driver::Driver::reportCompilation(ast::Compilation& compilation, bool quiet)

Reports the result of compilation.

Returns true if compilation succeeded and false if errors were encountered.

If quiet is set to true, non-essential output will be suppressed.