slang::parsing::Preprocessor class

Preprocessor - Interface between lexer and parser.

This class handles the messy interface between various source file lexers, include directives, and macro expansion, and the actual SystemVerilog parser that wants a nice coherent stream of tokens to consume.

Public functions

Token next()
Gets the next token in the stream, after applying preprocessor rules.
void pushSource(std::string_view source, std::string_view name = "source")
Push a new source file onto the stack.
void predefine(const std::string& definition, std::string_view name = "<api>")
Predefines the given macro definition.
bool undefine(std::string_view name)
Undefines a previously defined macro.
void undefineAll()
Undefines all currently defined macros.
bool isDefined(std::string_view name)
Checks whether the given macro is defined.
void setKeywordVersion(KeywordVersion version)
Sets the base keyword version for the current compilation unit.
void resetAllDirectives()
Resets the state of all compiler directives; this is equivalent to encountering the.
void pushDesignElementStack()
Increases the preprocessor's view of the depth of parsed design elements, such as modules or interfaces.
void popDesignElementStack()
Decreases the preprocessor's view of the depth of parsed design elements, such as modules or interfaces.
const std::optional<TimeScale>& getTimeScale() const
Gets the currently active time scale value, if any has been set by the user.
TokenKind getDefaultNetType() const
Gets the default net type to use if none is specified.
TokenKind getUnconnectedDrive() const
Gets the currently active drive strength to apply to unconnected nets, if any has been set by the user.
bool getCellDefine() const
Gets the currently active kind of module definition, if any has been set by the user.
KeywordVersion getCurrentKeywordVersion() const
Gets the currently active keyword version in use by the preprocessor.
const SourceLibrary* getCurrentLibrary() const
Gets the currently active source library, or nullptr if none has been set.
SourceManager& getSourceManager() const
Gets the source manager associated with the preprocessor.
BumpAllocator& getAllocator() const
Gets the allocator used by the preprocessor.
Diagnostics& getDiagnostics() const
Gets the diagnostic bag passed to the Preprocessor's constructor.
std::vector<const syntax::DefineDirectiveSyntax*> getDefinedMacros() const
Gets all macros that have been defined thus far in the preprocessor.
std::vector<IncludeMetadata> getIncludeDirectives() const
Gets all include directives that have been encountered thus far in the preprocessor.

Function documentation

void slang::parsing::Preprocessor::predefine(const std::string& definition, std::string_view name = "<api>")

Predefines the given macro definition.

The given definition string is lexed as if it were source text immediately following a `define directive. If any diagnostics are printed for the created text, they will be marked as coming from name.

bool slang::parsing::Preprocessor::undefine(std::string_view name)

Undefines a previously defined macro.

If the macro is not defined, or if you pass the name of an intrinsic macro, this call returns false and does not undefine anything.

bool slang::parsing::Preprocessor::isDefined(std::string_view name)

Checks whether the given macro is defined.

This does not check built-in directives except for the intrinsic macros (LINE, etc).

void slang::parsing::Preprocessor::setKeywordVersion(KeywordVersion version)

Sets the base keyword version for the current compilation unit.

Note that this does not affect the keyword version if the user has explicitly requested a different version via the begin_keywords directive.

void slang::parsing::Preprocessor::resetAllDirectives()

Resets the state of all compiler directives; this is equivalent to encountering the.

`resetall directive in source. Note that this does not include the state of any macros that have been defined.

void slang::parsing::Preprocessor::pushDesignElementStack()

Increases the preprocessor's view of the depth of parsed design elements, such as modules or interfaces.

A parser calls this whenever starting to parse a new design element so that the preprocessor can enforce rules about where directives may appear.

void slang::parsing::Preprocessor::popDesignElementStack()

Decreases the preprocessor's view of the depth of parsed design elements, such as modules or interfaces.

A parser calls this whenever finishing parsing a design element so that the preprocessor can enforce rules about where directives may appear.

TokenKind slang::parsing::Preprocessor::getDefaultNetType() const

Gets the default net type to use if none is specified.

This is set via the `default_nettype directive. If it is set to "none" by the user, this will return TokenKind::Unknown.

TokenKind slang::parsing::Preprocessor::getUnconnectedDrive() const

Gets the currently active drive strength to apply to unconnected nets, if any has been set by the user.

If none is set, this returns TokenKind::Unknown.

bool slang::parsing::Preprocessor::getCellDefine() const

Gets the currently active kind of module definition, if any has been set by the user.

If none is set, this returns false.