slang::Compilation class

Contents

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 BumpAllocator

Public functions

auto getOptions() const -> const CompilationOptions&
Gets the set of options used to construct the compilation.
void addSyntaxTree(std::shared_ptr<SyntaxTree> tree)
auto getSyntaxTrees() const -> span<const std::shared_ptr<SyntaxTree>>
Gets the set of syntax trees that have been added to the compilation.
auto getCompilationUnit(const CompilationUnitSyntax& syntax) const -> const CompilationUnitSymbol*
auto getCompilationUnits() const -> span<const CompilationUnitSymbol*const >
Gets the set of compilation units that have been added to the compilation.
auto getRoot() -> const RootSymbol&
auto getDesignTree() -> const DesignTreeNode&
auto isFinalized() const -> bool
Indicates whether the design has been compiled and can no longer accept modifications.
auto getDefinition(string_view name, const Scope& scope) const -> const Definition*
auto getDefinition(string_view name) const -> const Definition*
Gets the top level definition with the given name, or null if there is no such definition.
auto getDefinition(const ModuleDeclarationSyntax& syntax) const -> const Definition*
Gets the definition for the given syntax node, or nullptr if it does not exist.
auto createDefinition(const Scope& scope, LookupLocation location, const ModuleDeclarationSyntax& syntax) -> const Definition&
Creates a new definition in the given scope based on the given syntax.
auto getPackage(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 ModuleDeclarationSyntax& syntax) -> const PackageSymbol&
Creates a new package in the given scope based on the given syntax.
auto getPrimitive(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 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(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 addSystemMethod(SymbolKind typeKind, std::unique_ptr<SystemSubroutine> method)
Registers a type-based system method handler, which can be accessed by compiled code.
auto getSystemSubroutine(string_view name) const -> const SystemSubroutine*
auto getSystemMethod(SymbolKind typeKind, string_view name) const -> const SystemSubroutine*
void setAttributes(const Symbol& symbol, span<const AttributeSymbol*const> attributes)
Sets the attributes associated with the given symbol.
void setAttributes(const Statement& stmt, span<const AttributeSymbol*const> attributes)
Sets the attributes associated with the given statement.
void setAttributes(const Expression& expr, span<const AttributeSymbol*const> attributes)
Sets the attributes associated with the given expression.
auto getAttributes(const Symbol& symbol) const -> span<const AttributeSymbol*const >
Gets the attributes associated with the given symbol.
auto getAttributes(const Statement& stmt) const -> span<const AttributeSymbol*const >
Gets the attributes associated with the given statement.
auto getAttributes(const Expression& expr) const -> span<const AttributeSymbol*const >
Gets the attributes associated with the given expression.
void addInstance(const InstanceSymbol& instance)
void addInstance(const InstanceSymbol& instance, const InstanceBodySymbol& body)
auto getParentInstances(const InstanceBodySymbol& body) const -> span<const InstanceSymbol*const >
Returns the list of instances that share the same instance body.
void noteInterfacePort(const Definition& definition)
auto noteBindDirective(const BindDirectiveSyntax& syntax, const Definition* targetDef) -> bool
void noteDPIExportDirective(const DPIExportSyntax& syntax, const Scope& scope)
void noteUpwardNames(const InstanceBodySymbol& instance)
auto hasUpwardNames(const InstanceBodySymbol& instance) const -> bool
Returns true if the given instance body has at least one upward hierarchical name in it.
void addOutOfBlockDecl(const Scope& scope, const ScopedNameSyntax& name, const SyntaxNode& syntax, SymbolIndex index)
auto findOutOfBlockDecl(const Scope& scope, string_view className, string_view declName) const -> std::tuple<const SyntaxNode*, SymbolIndex, bool*>
auto parseName(string_view name) -> const NameSyntax&
auto tryParseName(string_view name, Diagnostics& diags) -> const 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.
void setDefaultTimeScale(TimeScale timeScale)
Sets the default time scale to use when none is specified in the source code.
auto getDefaultTimeScale() const -> 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 getInstanceCache() -> InstanceCache&
Gets access to the compilation's cache of instantiated modules, interfaces, and programs.
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 setCurrentInstancePath(span<const InstanceSymbol*const> path)
auto getCurrentInstancePath() const -> span<const InstanceSymbol*const >

Function documentation

void slang::Compilation::addSyntaxTree(std::shared_ptr<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::Compilation::getCompilationUnit(const 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::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 DesignTreeNode& slang::Compilation::getDesignTree()

Gets the design tree. Like getRoot this will force elaboration the first time it's called and the compilation will be finalized.

const Definition* slang::Compilation::getDefinition(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.

const SystemSubroutine* slang::Compilation::getSystemSubroutine(string_view name) const

Gets a system subroutine with the given name, or null if there is no such subroutine registered.

const SystemSubroutine* slang::Compilation::getSystemMethod(SymbolKind typeKind, 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::Compilation::addInstance(const InstanceSymbol& instance)

Registers a new instance with the compilation; used to keep track of which instances point to which instance bodies.

void slang::Compilation::addInstance(const InstanceSymbol& instance, const InstanceBodySymbol& body)

Registers a new instance with the compilation; used to keep track of which instances point to which instance bodies.

void slang::Compilation::noteInterfacePort(const Definition& definition)

Notes the fact that the given definition has been used in an interface port. This prevents warning about that interface definition being unused in the design.

bool slang::Compilation::noteBindDirective(const BindDirectiveSyntax& syntax, const Definition* targetDef)

Returns true if this is the first time this directive has been encountered, and false if it's already been elaborated (thus constituting an error).

Notes the presence of a bind directive. The compilation uses this to decide when it has done enough traversal of the hierarchy to have seen all bind directives. If targetDef is non-null, the bind directive applies to all instances of the given definition, which needs special handling.

void slang::Compilation::noteDPIExportDirective(const 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::Compilation::noteUpwardNames(const InstanceBodySymbol& instance)

Notes the fact that the given instance body has one or more upward hierarchical names in its expressions or statements.

void slang::Compilation::addOutOfBlockDecl(const Scope& scope, const ScopedNameSyntax& name, const 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 SyntaxNode*, SymbolIndex, bool*> slang::Compilation::findOutOfBlockDecl(const Scope& scope, string_view className, 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.

const NameSyntax& slang::Compilation::parseName(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 NameSyntax& slang::Compilation::tryParseName(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::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::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::Compilation::getSemanticDiagnostics()

Gets the diagnostics produced during semantic analysis, including the binding 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::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::Compilation::setCurrentInstancePath(span<const InstanceSymbol*const> path)

Sets the hierarchical path of the current instance being elaborated. This state is transistory during elaboration and is used to correctly resolve upward name lookups.

span<const InstanceSymbol*const > slang::Compilation::getCurrentInstancePath() const

Gets the hierarchical path of the current instance being elaborated. This state is transistory during elaboration and is used to correctly resolve upward name lookups.