slang::ast::LSPUtilities class

A collection of utility methods for working with LSP expressions.

An LSP expression is the longest static prefix of an expression that can be used to identify a particular driver of a variable. For example, in the expression a.b[3].c.d[2:0], if all of the selects are constant, then the entire expression is the LSP. If instead we had a.b[i].c.d[2:0], then the LSP would be a.b[i].

Public static functions

static void stringifyLSP(const Expression& expr, EvalContext& evalContext, FormatBuffer& buffer)
Converts an LSP expression to a human-friendly string representation.
static std::optional<DriverBitRange> getBounds(const Expression& lsp, EvalContext& evalContext, const Type& rootType)
Computes bounds for a driver given its longest static prefix expression.
template<typename TCallback>
static void visitLSPs(const Expression& expr, EvalContext& evalContext, TCallback&& func, bool isLValue = true)
Visits the longest static prefix expressions for all of the operands in the given expression using the provided callback function.
template<typename TCallback>
static void visitComponents(const Expression& longestStaticPrefix, bool includeRoot, TCallback&& callback)
Visits the components of the provided LSP expression, starting from the outer expressions and invoking the callback for each sub-expression in the path.
static void expandIndirectLSPs(BumpAllocator& alloc, const Expression& expr, EvalContext& evalContext, LSPCallback callback, bool isLValue = true)
Visits the longest static prefix expressions for all of the operands in the given expression using the provided callback function.

Function documentation

static std::optional<DriverBitRange> slang::ast::LSPUtilities::getBounds(const Expression& lsp, EvalContext& evalContext, const Type& rootType)

Computes bounds for a driver given its longest static prefix expression.

template<typename TCallback>
static void slang::ast::LSPUtilities::visitComponents(const Expression& longestStaticPrefix, bool includeRoot, TCallback&& callback)

Visits the components of the provided LSP expression, starting from the outer expressions and invoking the callback for each sub-expression in the path.

static void slang::ast::LSPUtilities::expandIndirectLSPs(BumpAllocator& alloc, const Expression& expr, EvalContext& evalContext, LSPCallback callback, bool isLValue = true)

Visits the longest static prefix expressions for all of the operands in the given expression using the provided callback function.

Parameters
alloc The allocator to use for any AST nodes that need to be created to represent expanded selections.
expr
evalContext
callback
isLValue

Unlike visitLSPs, this method will expand indirect references such as modport port connections and ref port connections.