clang 23.0.0git
clang::interp::EvalEmitter Class Referenceabstract

An emitter which evaluates opcodes as they are emitted. More...

#include "/work/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/AST/ByteCode/EvalEmitter.h"

Inheritance diagram for clang::interp::EvalEmitter:
[legend]

Public Types

using LabelTy = uint32_t
using AddrTy = uintptr_t
using Local = Scope::Local
using PtrCallback

Public Member Functions

EvaluationResult interpretExpr (const Expr *E, bool ConvertResultToRValue=false, bool DestroyToplevelScope=false)
EvaluationResult interpretDecl (const VarDecl *VD, const Expr *Init, bool CheckFullyInitialized)
EvaluationResult interpretDestructor (const VarDecl *VD, const APValue &Value)
EvaluationResult interpretAsPointer (const Expr *E, PtrCallback PtrCB)
 Interpret the given Expr to a Pointer.
EvaluationResult interpretAsLValuePointer (const Expr *E, PtrCallback PtrCB)
bool interpretCall (const FunctionDecl *FD, const Expr *E)
 Interpret the given expression as if it was in the body of the given function, i.e.
std::optional< boolinterpretWithSubstitutions (const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition)
void cleanup ()
 Clean up all resources.
Public Member Functions inherited from clang::interp::SourceMapper
virtual ~SourceMapper ()
const ExprgetExpr (const Function *F, CodePtr PC) const
 Returns the expression if an opcode belongs to one, null otherwise.
SourceLocation getLocation (const Function *F, CodePtr PC) const
 Returns the location from which an opcode originates.
SourceRange getRange (const Function *F, CodePtr PC) const

Protected Member Functions

 EvalEmitter (Context &Ctx, Program &P, State &Parent, InterpStack &Stk)
virtual ~EvalEmitter ()
void emitLabel (LabelTy Label)
 Define a label.
LabelTy getLabel ()
 Create a label.
virtual bool visitExpr (const Expr *E, bool DestroyToplevelScope)=0
 Methods implemented by the compiler.
virtual bool visitLValueExpr (const Expr *E, bool DestroyToplevelScope)=0
virtual bool visitDeclAndReturn (const VarDecl *VD, const Expr *Init, bool ConstantContext)=0
virtual bool visitDtorCall (const VarDecl *VD, const APValue &Value)=0
virtual bool visitWithSubstitutions (const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This, const Expr *Condition)=0
virtual bool visitFunc (const FunctionDecl *F)=0
virtual bool visit (const Expr *E)=0
virtual bool emitBool (bool V, const Expr *E)=0
bool jumpTrue (const LabelTy &Label, SourceInfo SI)
 Emits jumps.
bool jumpFalse (const LabelTy &Label, SourceInfo SI)
bool jump (const LabelTy &Label, SourceInfo SI)
bool fallthrough (const LabelTy &Label)
bool speculate (const CallExpr *E, const LabelTy &EndLabel)
 Speculative execution.
bool isActive () const
 Since expressions can only jump forward, predicated execution is used to deal with if-else statements.
bool checkingForUndefinedBehavior () const
Local createLocal (Descriptor *D)
 Callback for registering a local.
SourceInfo getSource (const Function *F, CodePtr PC) const override
 Returns the source location of the current opcode.

Protected Attributes

llvm::DenseMap< const ParmVarDecl *, FuncParamParams
 Parameter indices.
llvm::SmallVector< SmallVector< Local, 8 >, 2 > Descriptors
 Local descriptors.
std::optional< SourceInfoLocOverride = std::nullopt

Detailed Description

An emitter which evaluates opcodes as they are emitted.

Definition at line 31 of file EvalEmitter.h.

Member Typedef Documentation

◆ AddrTy

Definition at line 34 of file EvalEmitter.h.

◆ LabelTy

Definition at line 33 of file EvalEmitter.h.

◆ Local

Definition at line 35 of file EvalEmitter.h.

◆ PtrCallback

Initial value:
llvm::function_ref<bool(InterpState &S, CodePtr OpPC, const Pointer &)>
Pointer into the code segment.
Definition Source.h:30
Interpreter context.
Definition InterpState.h:43
A pointer to a memory block, live or dead.
Definition Pointer.h:405

Definition at line 36 of file EvalEmitter.h.

Constructor & Destructor Documentation

◆ EvalEmitter()

EvalEmitter::EvalEmitter ( Context & Ctx,
Program & P,
State & Parent,
InterpStack & Stk )
protected

Definition at line 20 of file EvalEmitter.cpp.

◆ ~EvalEmitter()

EvalEmitter::~EvalEmitter ( )
protectedvirtual

Member Function Documentation

◆ checkingForUndefinedBehavior()

bool clang::interp::EvalEmitter::checkingForUndefinedBehavior ( ) const
inlineprotected

Definition at line 95 of file EvalEmitter.h.

◆ cleanup()

void EvalEmitter::cleanup ( )

Clean up all resources.

Clean up all our resources.

This needs to done in failed evaluations before we call InterpStack::clear(), because there might be a Pointer on the stack pointing into a Block in the EvalEmitter.

Definition at line 35 of file EvalEmitter.cpp.

◆ createLocal()

Scope::Local EvalEmitter::createLocal ( Descriptor * D)
protected

◆ emitBool()

virtual bool clang::interp::EvalEmitter::emitBool ( bool V,
const Expr * E )
protectedpure virtual

References V.

Referenced by speculate().

◆ emitLabel()

void EvalEmitter::emitLabel ( LabelTy Label)
protected

Define a label.

Definition at line 149 of file EvalEmitter.cpp.

◆ fallthrough()

bool EvalEmitter::fallthrough ( const LabelTy & Label)
protected

Definition at line 201 of file EvalEmitter.cpp.

References isActive().

◆ getLabel()

EvalEmitter::LabelTy EvalEmitter::getLabel ( )
protected

Create a label.

Definition at line 151 of file EvalEmitter.cpp.

◆ getSource()

SourceInfo clang::interp::EvalEmitter::getSource ( const Function * F,
CodePtr PC ) const
inlineoverrideprotectedvirtual

Returns the source location of the current opcode.

Implements clang::interp::SourceMapper.

Definition at line 103 of file EvalEmitter.h.

References clang::interp::Function::getSource(), and clang::interp::Function::hasBody().

◆ interpretAsLValuePointer()

EvaluationResult EvalEmitter::interpretAsLValuePointer ( const Expr * E,
PtrCallback PtrCB )

Definition at line 108 of file EvalEmitter.cpp.

References clang::Expr::getExprLoc(), and visitLValueExpr().

◆ interpretAsPointer()

EvaluationResult EvalEmitter::interpretAsPointer ( const Expr * E,
PtrCallback PtrCB )

Interpret the given Expr to a Pointer.

Definition at line 91 of file EvalEmitter.cpp.

References clang::Expr::getExprLoc(), and visitExpr().

◆ interpretCall()

bool EvalEmitter::interpretCall ( const FunctionDecl * FD,
const Expr * E )

Interpret the given expression as if it was in the body of the given function, i.e.

the parameters of the function are available for use.

Definition at line 122 of file EvalEmitter.cpp.

References clang::FunctionDecl::parameters(), Params, and visitExpr().

◆ interpretDecl()

EvaluationResult EvalEmitter::interpretDecl ( const VarDecl * VD,
const Expr * Init,
bool CheckFullyInitialized )

◆ interpretDestructor()

EvaluationResult EvalEmitter::interpretDestructor ( const VarDecl * VD,
const APValue & Value )

Definition at line 76 of file EvalEmitter.cpp.

References clang::interp::Dtor, clang::Decl::getLocation(), and visitDtorCall().

◆ interpretExpr()

EvaluationResult EvalEmitter::interpretExpr ( const Expr * E,
bool ConvertResultToRValue = false,
bool DestroyToplevelScope = false )

◆ interpretWithSubstitutions()

std::optional< bool > EvalEmitter::interpretWithSubstitutions ( const FunctionDecl * Callee,
ArrayRef< const Expr * > Args,
const Expr * This,
const Expr * Condition )

◆ isActive()

bool clang::interp::EvalEmitter::isActive ( ) const
inlineprotected

Since expressions can only jump forward, predicated execution is used to deal with if-else statements.

Definition at line 94 of file EvalEmitter.h.

Referenced by fallthrough(), jump(), jumpFalse(), jumpTrue(), and speculate().

◆ jump()

bool EvalEmitter::jump ( const LabelTy & Label,
SourceInfo SI )
protected

Definition at line 193 of file EvalEmitter.cpp.

References isActive().

◆ jumpFalse()

bool EvalEmitter::jumpFalse ( const LabelTy & Label,
SourceInfo SI )
protected

Definition at line 184 of file EvalEmitter.cpp.

References isActive().

◆ jumpTrue()

bool EvalEmitter::jumpTrue ( const LabelTy & Label,
SourceInfo SI )
protected

Emits jumps.

Definition at line 175 of file EvalEmitter.cpp.

References isActive().

◆ speculate()

◆ visit()

virtual bool clang::interp::EvalEmitter::visit ( const Expr * E)
protectedpure virtual

Referenced by speculate().

◆ visitDeclAndReturn()

virtual bool clang::interp::EvalEmitter::visitDeclAndReturn ( const VarDecl * VD,
const Expr * Init,
bool ConstantContext )
protectedpure virtual

References clang::interp::Init().

Referenced by interpretDecl().

◆ visitDtorCall()

virtual bool clang::interp::EvalEmitter::visitDtorCall ( const VarDecl * VD,
const APValue & Value )
protectedpure virtual

Referenced by interpretDestructor().

◆ visitExpr()

virtual bool clang::interp::EvalEmitter::visitExpr ( const Expr * E,
bool DestroyToplevelScope )
protectedpure virtual

Methods implemented by the compiler.

Referenced by interpretAsPointer(), interpretCall(), and interpretExpr().

◆ visitFunc()

virtual bool clang::interp::EvalEmitter::visitFunc ( const FunctionDecl * F)
protectedpure virtual

◆ visitLValueExpr()

virtual bool clang::interp::EvalEmitter::visitLValueExpr ( const Expr * E,
bool DestroyToplevelScope )
protectedpure virtual

◆ visitWithSubstitutions()

virtual bool clang::interp::EvalEmitter::visitWithSubstitutions ( const FunctionDecl * Callee,
ArrayRef< const Expr * > Args,
const Expr * This,
const Expr * Condition )
protectedpure virtual

Member Data Documentation

◆ Descriptors

llvm::SmallVector<SmallVector<Local, 8>, 2> clang::interp::EvalEmitter::Descriptors
protected

Local descriptors.

Definition at line 110 of file EvalEmitter.h.

◆ LocOverride

std::optional<SourceInfo> clang::interp::EvalEmitter::LocOverride = std::nullopt
protected

Definition at line 111 of file EvalEmitter.h.

◆ Params

llvm::DenseMap<const ParmVarDecl *, FuncParam> clang::interp::EvalEmitter::Params
protected

Parameter indices.

Definition at line 108 of file EvalEmitter.h.

Referenced by interpretCall().


The documentation for this class was generated from the following files: