slang::ast::SystemSubroutine class

The base class for built-in system subroutines.

There is one instance of a derived class for each built-in subroutine in the language. System subroutines must be registered with the compilation in order to be findable via name lookup.

Derived classes

class SimpleSystemSubroutine
An implementation of the SystemSubroutine interface that has basic argument types and a well-defined return type.

Public types

enum class WithClauseMode { None, Iterator, Randomize }
Possible ways in which the subroutine may use a with clause.

Constructors, destructors, conversion operators

SystemSubroutine(const std::string& name, SubroutineKind kind) protected
Constructs a new system subroutine instance.

Public functions

auto allowEmptyArgument(size_t argIndex) const -> bool virtual
auto allowClockingArgument(size_t argIndex) const -> bool virtual
auto isArgUnevaluated(size_t argIndex) const -> bool virtual
auto bindArgument(size_t argIndex, const ASTContext& context, const syntax::ExpressionSyntax& syntax, const Args& previousArgs) const -> const Expression& virtual
Allows the subroutine to perform custom argument binding for the given argument index.
auto getEffectiveWidth() const -> std::optional<bitwidth_t> virtual
auto checkArguments(const ASTContext& context, const Args& args, SourceRange range, const Expression* iterOrThis) const -> const Type& pure virtual
Allows the subroutine to perform checking of the arguments in a call expression.
auto eval(EvalContext& context, const Args& args, SourceRange range, const CallExpression::SystemCallInfo& callInfo) const -> ConstantValue pure virtual
Performs constant evaluation of the subroutine, or reports an error if it's not allowed to be called in a constant context.

Public variables

std::string name
The name of the subroutine (including the leading $).
SubroutineKind kind
The kind of subroutine (task or function).
bool hasOutputArgs
True if the subroutine has output (or ref / inout) args, and false otherwise.
WithClauseMode withClauseMode
The way in which the subroutine may use a with clause.

Protected static functions

static auto unevaluatedContext(const ASTContext& sourceContext) -> ASTContext
static auto registerLValue(const Expression& expr, const ASTContext& context) -> bool
Helper method to register the given expression as an lvalue.

Protected functions

auto kindStr() const -> std::string_view
auto badArg(const ASTContext& context, const Expression& arg) const -> const Type&
Reports an error for a bad argument expression.
auto notConst(EvalContext& context, SourceRange range) const -> bool
Reports an error indicating that the subroutine is not allowed in a constant context.
auto noHierarchical(EvalContext& context, const Expression& expr) const -> bool
Checks for and reports an error if a hierarhical name is used in the given expression.
auto checkArgCount(const ASTContext& context, bool isMethod, const Args& args, SourceRange callRange, size_t min, size_t max) const -> bool
Checks that the number of provided arguments is allowed for the subroutine, and reports an appropriate error if not.

Enum documentation

enum class slang::ast::SystemSubroutine::WithClauseMode

Possible ways in which the subroutine may use a with clause.

Enumerators
None

The subroutine does not use a with clause.

Iterator

The subroutine is an iterator method.

Randomize

The subroutine is a randomize method.

Function documentation

bool slang::ast::SystemSubroutine::allowEmptyArgument(size_t argIndex) const virtual

Returns true if the subroutine allows an empty argument to be passed for the given argument index.

bool slang::ast::SystemSubroutine::allowClockingArgument(size_t argIndex) const virtual

Returns true if the subroutine allows a clocking event to be passed for the given argument index.

bool slang::ast::SystemSubroutine::isArgUnevaluated(size_t argIndex) const virtual

Returns true if the given argument is unevaluated by the subroutine, and false otherwise.

std::optional<bitwidth_t> slang::ast::SystemSubroutine::getEffectiveWidth() const virtual

Returns the effective width of the return value of the subroutine.

This is used to reduce false-positive width conversion warnings for subroutines defined to return something like an int when in reality they can only ever return 1 or 0.

static ASTContext slang::ast::SystemSubroutine::unevaluatedContext(const ASTContext& sourceContext) protected

Returns a modified AST context that indicates it is in an unevaluated context.

std::string_view slang::ast::SystemSubroutine::kindStr() const protected

Returns a string that says "task" or "function" depending on the kind of subroutine this is.