class
#include <slang/parsing/Preprocessor.h>
Preprocessor Contents
- Reference
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
- auto next() -> Token
- Gets the next token in the stream, after applying preprocessor rules.
- void pushSource(string_view source, string_view name = "")
- Push a new source file onto the stack.
- void predefine(const std::string& definition, string_view fileName = "<api>")
- auto undefine(string_view name) -> bool
- void undefineAll()
- Undefines all currently defined macros.
- auto isDefined(string_view name) -> bool
- void setKeywordVersion(KeywordVersion version)
- void resetAllDirectives()
- void pushDesignElementStack()
- void popDesignElementStack()
- auto getTimeScale() const -> const optional<TimeScale>&
- Gets the currently active time scale value, if any has been set by the user.
- auto getDefaultNetType() const -> TokenKind
- auto getUnconnectedDrive() const -> TokenKind
- auto getCurrentKeywordVersion() const -> KeywordVersion
- Gets the currently active keyword version in use by the preprocessor.
- auto getDefinedMacros() const -> std::vector<const DefineDirectiveSyntax*>
- Gets all macros that have been defined thus far in the preprocessor.
Function documentation
void slang:: Preprocessor:: predefine(const std::string& definition,
string_view fileName = "<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 fileName.
bool slang:: Preprocessor:: undefine(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:: Preprocessor:: isDefined(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:: 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:: 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:: 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:: 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:: 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:: 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.