class
#include <slang/ast/Compilation.h>
Compilation A centralized location for creating and caching symbols. This includes creating symbols from syntax nodes as well as fabricating them synthetically. Common symbols such as built in types are exposed here as well.
Base classes
- class slang::BumpAllocator
Public functions
- auto getOptions() const -> const CompilationOptions&
- Gets the set of options used to construct the compilation.
-
void addSyntaxTree(std::shared_ptr<syntax::
SyntaxTree> tree) -
auto getSyntaxTrees() const -> std::span<const std::shared_ptr<syntax::
SyntaxTree>> - Gets the set of syntax trees that have been added to the compilation.
-
auto getCompilationUnit(const syntax::
CompilationUnitSyntax& syntax) const -> const CompilationUnitSymbol* - auto getCompilationUnits() const -> std::span<const CompilationUnitSymbol*const>
- Gets the set of compilation units that have been added to the compilation.
- auto getRoot() -> const RootSymbol&
- auto isFinalized() const -> bool
- Indicates whether the design has been compiled and can no longer accept modifications.
- auto getDefinition(std::string_view name, const Scope& scope) const -> const Definition*
-
auto getDefinition(const syntax::
ModuleDeclarationSyntax& syntax) const -> const Definition* - Gets the definition for the given syntax node, or nullptr if it does not exist.
-
void createDefinition(const Scope& scope,
LookupLocation location,
const syntax::
ModuleDeclarationSyntax& syntax) - Creates a new definition in the given scope based on the given syntax.
- auto getPackage(std::string_view name) const -> const PackageSymbol*
- Gets the package with the give name, or null if there is no such package.
- auto getStdPackage() const -> const PackageSymbol&
- Gets the built-in 'std' package.
-
auto createPackage(const Scope& scope,
const syntax::
ModuleDeclarationSyntax& syntax) -> const PackageSymbol& - Creates a new package in the given scope based on the given syntax.
- auto getPrimitive(std::string_view name) const -> const PrimitiveSymbol*
- Gets the primitive with the given name, or null if there is no such primitive.
-
auto createPrimitive(const Scope& scope,
const syntax::
UdpDeclarationSyntax& syntax) -> const PrimitiveSymbol& - Creates a new primitive in the given scope based on the given syntax.
- void addGateType(const PrimitiveSymbol& primitive)
- Registers a built-in gate symbol.
- auto getGateType(std::string_view name) const -> const PrimitiveSymbol*
- Gets the built-in gate type with the given name, or null if there is no such gate.
- void addSystemSubroutine(std::unique_ptr<SystemSubroutine> subroutine)
- Registers a system subroutine handler, which can be accessed by compiled code.
- void addSystemSubroutine(const SystemSubroutine& subroutine)
- void addSystemMethod(SymbolKind typeKind, std::unique_ptr<SystemSubroutine> method)
- Registers a type-based system method handler, which can be accessed by compiled code.
- void addSystemMethod(SymbolKind typeKind, const SystemSubroutine& subroutine)
- auto getSystemSubroutine(std::string_view name) const -> const SystemSubroutine*
- auto getSystemMethod(SymbolKind typeKind, std::string_view name) const -> const SystemSubroutine*
- void setAttributes(const Symbol& symbol, std::span<const AttributeSymbol*const> attributes)
- Sets the attributes associated with the given symbol.
- void setAttributes(const Statement& stmt, std::span<const AttributeSymbol*const> attributes)
- Sets the attributes associated with the given statement.
- void setAttributes(const Expression& expr, std::span<const AttributeSymbol*const> attributes)
- Sets the attributes associated with the given expression.
- void setAttributes(const PortConnection& conn, std::span<const AttributeSymbol*const> attributes)
- Sets the attributes associated with the given port connection.
- auto getAttributes(const Symbol& symbol) const -> std::span<const AttributeSymbol*const>
- Gets the attributes associated with the given symbol.
- auto getAttributes(const Statement& stmt) const -> std::span<const AttributeSymbol*const>
- Gets the attributes associated with the given statement.
- auto getAttributes(const Expression& expr) const -> std::span<const AttributeSymbol*const>
- Gets the attributes associated with the given expression.
- auto getAttributes(const PortConnection& conn) const -> std::span<const AttributeSymbol*const>
- Gets the attributes associated with the given port connection.
- void notePackageExportCandidate(const PackageSymbol& packageScope, const Symbol& symbol)
- auto findPackageExportCandidate(const PackageSymbol& packageScope, std::string_view name) const -> const Symbol*
-
void noteBindDirective(const syntax::
BindDirectiveSyntax& syntax, const Scope& scope) - void noteInstanceWithDefBind(const Symbol& instance)
-
void noteDPIExportDirective(const syntax::
DPIExportSyntax& syntax, const Scope& scope) -
void addOutOfBlockDecl(const Scope& scope,
const syntax::
ScopedNameSyntax& name, const syntax:: SyntaxNode& syntax, SymbolIndex index) -
auto findOutOfBlockDecl(const Scope& scope,
std::string_view className,
std::string_view declName) const -> std::tuple<const syntax::
SyntaxNode*, SymbolIndex, bool*> - void addExternInterfaceMethod(const SubroutineSymbol& method)
- void noteDefaultClocking(const Scope& scope, const Symbol& clocking, SourceRange range)
- Notes that there is a default clocking block associated with the specified scope.
-
void noteDefaultClocking(const ASTContext& context,
const syntax::
DefaultClockingReferenceSyntax& syntax) - Notes that there is a default clocking block associated with the specified scope.
- auto getDefaultClocking(const Scope& scope) const -> const Symbol*
- void noteGlobalClocking(const Scope& scope, const Symbol& clocking, SourceRange range)
- Notes that there is a global clocking block associated with the specified scope.
- auto getGlobalClocking(const Scope& scope) const -> const Symbol*
- void noteDefaultDisable(const Scope& scope, const Expression& expr)
- Notes that there is a default disable associated with the specified scope.
- auto getDefaultDisable(const Scope& scope) const -> const Expression*
-
void noteReference(const syntax::
SyntaxNode& node, bool isLValue = false) - void noteReference(const Symbol& symbol, bool isLValue = false)
-
auto isReferenced(const syntax::
SyntaxNode& node) const -> std::pair<bool, bool> - void noteNameConflict(const Symbol& symbol)
-
auto parseName(std::string_view name) -> const syntax::
NameSyntax& -
auto tryParseName(std::string_view name,
Diagnostics& diags) -> const syntax::
NameSyntax& - auto createScriptScope() -> CompilationUnitSymbol&
- auto getSourceManager() const -> const SourceManager*
- auto getParseDiagnostics() -> const Diagnostics&
- Gets the diagnostics produced during lexing, preprocessing, and syntax parsing.
- auto getSemanticDiagnostics() -> const Diagnostics&
- auto getAllDiagnostics() -> const Diagnostics&
- Gets all of the diagnostics produced during compilation.
- void addDiagnostics(const Diagnostics& diagnostics)
- Adds a set of diagnostics to the compilation's list of semantic diagnostics.
- auto getDefaultTimeScale() const -> std::optional<TimeScale>
- Gets the default time scale to use when none is specified in the source code.
- auto getBitType() const -> const Type&
- Various built-in type symbols for easy access.
- auto getWireNetType() const -> const NetType&
- auto allocConstant(ConstantValue&& value) -> ConstantValue*
- Allocates space for a constant value in the pool of constants.
- auto allocSymbolMap() -> SymbolMap*
- Allocates a symbol map.
- auto allocPointerMap() -> PointerMap*
- Allocates a pointer map.
-
template<typename... Args>auto allocGenericClass(Args && ... args) -> GenericClassDefSymbol*
- Allocates a generic class symbol.
- void forceElaborate(const Symbol& symbol)
Function documentation
void slang:: ast:: Compilation:: addSyntaxTree(std::shared_ptr<syntax:: SyntaxTree> tree)
Adds a syntax tree to the compilation. If the compilation has already been finalized by calling getRoot this call will throw an exception.
const CompilationUnitSymbol* slang:: ast:: Compilation:: getCompilationUnit(const syntax:: CompilationUnitSyntax& syntax) const
Gets the compilation unit for the given syntax node. The compilation unit must have already been added to the compilation previously via a call to addSyntaxTree
const RootSymbol& slang:: ast:: Compilation:: getRoot()
Gets the root of the design. The first time you call this method all top-level instances will be elaborated and the compilation finalized. After that you can no longer make any modifications to the compilation object; any attempts to do so will result in an exception.
const Definition* slang:: ast:: Compilation:: getDefinition(std::string_view name,
const Scope& scope) const
Gets the definition with the given name, or null if there is no such definition. This takes into account the given scope so that nested definitions are found before more global ones.
void slang:: ast:: Compilation:: addSystemSubroutine(const SystemSubroutine& subroutine)
Registers an externally owned system subroutine handler, which can be accessed by compiled code.
void slang:: ast:: Compilation:: addSystemMethod(SymbolKind typeKind,
const SystemSubroutine& subroutine)
Registers an externally owned type-based system method handler, which can be accessed by compiled code.
const SystemSubroutine* slang:: ast:: Compilation:: getSystemSubroutine(std::string_view name) const
Gets a system subroutine with the given name, or null if there is no such subroutine registered.
const SystemSubroutine* slang:: ast:: Compilation:: getSystemMethod(SymbolKind typeKind,
std::string_view name) const
Gets a system method for the specified type with the given name, or null if there is no such method registered.
void slang:: ast:: Compilation:: notePackageExportCandidate(const PackageSymbol& packageScope,
const Symbol& symbol)
Notes that the given symbol was imported into the current scope via a package import, and further that the current scope is within a package declaration. These symbols are candidates for being exported from this package.
const Symbol* slang:: ast:: Compilation:: findPackageExportCandidate(const PackageSymbol& packageScope,
std::string_view name) const
Tries to find a symbol that can be exported from the given package to satisfy an import of a given name from that package. Returns nullptr if no such symbol can be found.
void slang:: ast:: Compilation:: noteBindDirective(const syntax:: BindDirectiveSyntax& syntax,
const Scope& scope)
Notes the presence of a bind directive. These can be later checked during scope elaboration to include the newly bound instances.
void slang:: ast:: Compilation:: noteInstanceWithDefBind(const Symbol& instance)
Notes an instance that contains a bind directive targeting a global definition. These are later checked for correctness of type params.
void slang:: ast:: Compilation:: noteDPIExportDirective(const syntax:: DPIExportSyntax& syntax,
const Scope& scope)
Notes the presence of a DPI export directive. These will be checked for correctness but are otherwise unused by SystemVerilog code.
void slang:: ast:: Compilation:: addOutOfBlockDecl(const Scope& scope,
const syntax:: ScopedNameSyntax& name,
const syntax:: SyntaxNode& syntax,
SymbolIndex index)
Tracks the existence of an out-of-block declaration (method or constraint) in the given scope. This can later be retrieved by calling findOutOfBlockDecl().
std::tuple<const syntax:: SyntaxNode*, SymbolIndex, bool*> slang:: ast:: Compilation:: findOutOfBlockDecl(const Scope& scope,
std::string_view className,
std::string_view declName) const
Searches for an out-of-block declaration in the given scope with declName for a className class. Returns a tuple of syntax pointer and symbol index in the defining scope, along with a pointer that should be set to true if the resulting decl is considered "used". If not found, the syntax pointer will be null.
void slang:: ast:: Compilation:: addExternInterfaceMethod(const SubroutineSymbol& method)
Tracks the existence of an extern interface method implementation. These are later elaborated by the compilation to hook up connections to their interface prototypes.
const Symbol* slang:: ast:: Compilation:: getDefaultClocking(const Scope& scope) const
Finds an applicable default clocking block for the given scope, or returns nullptr if no default clocking is in effect.
const Symbol* slang:: ast:: Compilation:: getGlobalClocking(const Scope& scope) const
Finds an applicable global clocking block for the given scope, or returns nullptr if no global clocking is in effect.
const Expression* slang:: ast:: Compilation:: getDefaultDisable(const Scope& scope) const
Finds an applicable default disable expression for the given scope, or returns nullptr if no such declaration is in effect.
void slang:: ast:: Compilation:: noteReference(const syntax:: SyntaxNode& node,
bool isLValue = false)
Notes that the given syntax node is "referenced" somewhere in the AST. This is used to diagnose unused variables, nets, etc. The isLValue parameter is used to tell whether a value is only assigned or whether it's also read somewhere.
void slang:: ast:: Compilation:: noteReference(const Symbol& symbol,
bool isLValue = false)
Notes that the given symbol is "referenced" somewhere in the AST. This is used to diagnose unused variables, nets, etc. The isLValue parameter is used to tell whether a value is only assigned or whether it's also read somewhere.
std::pair<bool, bool> slang:: ast:: Compilation:: isReferenced(const syntax:: SyntaxNode& node) const
Checks whether the given syntax node has been referenced in the AST thus far. The result is a pair, the first item of which is true if the node has been used as a non-lvalue, and the second of which is true if the node has been used as an lvalue. The second item is only relevant for nodes where it makes sense; e.g. variables and nets.
void slang:: ast:: Compilation:: noteNameConflict(const Symbol& symbol)
Notes that the given symbol has a name conflict in its parent scope. This will cause appropriate errors to be issued.
const syntax:: NameSyntax& slang:: ast:: Compilation:: parseName(std::string_view name)
A convenience method for parsing a name string and turning it into a set of syntax nodes. This is mostly for testing and API purposes; normal compilation never does this. Throws an exception if there are errors parsing the name.
const syntax:: NameSyntax& slang:: ast:: Compilation:: tryParseName(std::string_view name,
Diagnostics& diags)
A convenience method for parsing a name string and turning it into a set of syntax nodes. This is mostly for testing and API purposes. Errors are added to the provided diagnostics bag.
CompilationUnitSymbol& slang:: ast:: Compilation:: createScriptScope()
Creates a new compilation unit within the design that can be modified dynamically, which is useful in runtime scripting scenarios. Note that this call will succeed even if the design has been finalized, but in that case any instantiations in the script scope won't affect which modules are determined to be top-level instances.
const SourceManager* slang:: ast:: Compilation:: getSourceManager() const
Gets the source manager associated with the compilation. If no syntax trees have been added to the design this method will return null.
const Diagnostics& slang:: ast:: Compilation:: getSemanticDiagnostics()
Gets the diagnostics produced during semantic analysis, including the creation of symbols, type checking, and name lookup. Note that this will finalize the compilation, including forcing the evaluation of any symbols or expressions that were still waiting for lazy evaluation.
const NetType& slang:: ast:: Compilation:: getWireNetType() const
Get the 'wire' built in net type. The rest of the built-in net types are rare enough that we don't bother providing dedicated accessors for them.
void slang:: ast:: Compilation:: forceElaborate(const Symbol& symbol)
Forces the given symbol and all children underneath it in the hierarchy to be elaborated and any relevant diagnostics to be issued.