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 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 createPackage(const Scope& scope, const ModuleDeclarationSyntax& syntax) -> const PackageSymbol&
Creates a new package in the given scope based on the given syntax.
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)
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)
void addOutOfBlockMethod(const Scope& scope, const FunctionDeclarationSyntax& syntax, SymbolIndex index)
auto findOutOfBlockMethod(const Scope& scope, string_view className, string_view methodName) const -> std::tuple<const FunctionDeclarationSyntax*, SymbolIndex>
auto parseName(string_view name) -> 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.

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 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::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.

void slang::Compilation::addOutOfBlockMethod(const Scope& scope, const FunctionDeclarationSyntax& syntax, SymbolIndex index)

Tracks the existence of an out-of-block metohd definition in the given scope. This can later be retrieved by calling findOutOfBlockMethod().

std::tuple<const FunctionDeclarationSyntax*, SymbolIndex> slang::Compilation::findOutOfBlockMethod(const Scope& scope, string_view className, string_view methodName) const

Searches for an out-of-block method definition in the given scope with name for a className class. Returns a tuple of syntax pointer and symbol index in the defining scope. 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.

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.