24 : Ctx(Ctx),
P(
P), S(
Parent,
P, Stk, Ctx, this), Result(Result) {
34 return llvm::make_error<ByteCodeGenError>(*BailLocation);
42 return llvm::make_error<ByteCodeGenError>(*BailLocation);
55 auto *B =
new (Memory.get())
Block(D,
false);
69 unsigned Off = Locals.size();
70 Locals.insert({Off, std::move(Memory)});
98 CurrentLabel = ActiveLabel =
Label;
105 CurrentLabel =
Label;
109template <PrimType OpType>
bool EvalEmitter::emitRet(
const SourceInfo &Info) {
113 return ReturnValue<T>(S.
Stk.
pop<T>(), Result);
116bool EvalEmitter::emitRetVoid(
const SourceInfo &Info) {
return true; }
118bool EvalEmitter::emitRetValue(
const SourceInfo &Info) {
123 Ty = AT->getValueType();
126 auto *
Record = Ptr.getRecord();
127 assert(
Record &&
"Missing record descriptor");
130 if (RT->getDecl()->isUnion()) {
135 QualType FieldTy = F.Decl->getType();
137 if (std::optional<PrimType> T = Ctx.
classify(FieldTy)) {
140 Ok &= Composite(FieldTy, FP,
Value);
153 for (
unsigned I = 0; I < NF; ++I) {
159 if (std::optional<PrimType> T = Ctx.
classify(FieldTy)) {
162 Ok &= Composite(FieldTy, FP,
Value);
166 for (
unsigned I = 0; I < NB; ++I) {
170 Ok &= Composite(BaseTy, BP, R.getStructBase(I));
173 for (
unsigned I = 0; I < NV; ++I) {
177 Ok &= Composite(VirtBaseTy, VP, R.getStructBase(NB + I));
183 const size_t NumElems = Ptr.getNumElems();
184 QualType ElemTy = AT->getElementType();
188 for (
unsigned I = 0; I < NumElems; ++I) {
191 if (std::optional<PrimType> T = Ctx.
classify(ElemTy)) {
194 Ok &= Composite(ElemTy, EP.
narrow(), Slot);
199 llvm_unreachable(
"invalid value to return");
204 return Composite(Ptr.getType(), Ptr, Result);
207bool EvalEmitter::emitGetPtrLocal(uint32_t I,
const SourceInfo &Info) {
211 Block *B = getLocal(I);
216template <PrimType OpType>
217bool EvalEmitter::emitGetLocal(uint32_t I,
const SourceInfo &Info) {
223 Block *B = getLocal(I);
228template <PrimType OpType>
229bool EvalEmitter::emitSetLocal(uint32_t I,
const SourceInfo &Info) {
235 Block *B = getLocal(I);
236 *
reinterpret_cast<T *
>(B->
data()) = S.
Stk.
pop<T>();
243bool EvalEmitter::emitDestroy(uint32_t I,
const SourceInfo &Info) {
260#include "Opcodes.inc"
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
#define TYPE_SWITCH(Expr, B)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
APValue & getArrayInitializedElt(unsigned I)
APValue & getStructField(unsigned i)
QualType getRecordType(const RecordDecl *Decl) const
This represents one expression.
Represents a member of a struct/union/class.
A (possibly-)qualified type.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Encodes a location in the source.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
const T * getAs() const
Member-template getAs<specific type>'.
Represents a variable declaration or definition.
A memory block, either on the stack or in the heap.
void invokeCtor()
Invokes the constructor.
char * rawData()
Returns a pointer to the raw data, including metadata.
char * data()
Returns a pointer to the stored data.
Pointer into the code segment.
Holds all information required to evaluate constexpr code in a module.
ASTContext & getASTContext() const
Returns the AST context.
std::optional< PrimType > classify(QualType T) const
Classifies an expression.
bool jump(const LabelTy &Label)
virtual bool visitExpr(const Expr *E)=0
Methods implemented by the compiler.
EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk, APValue &Result)
bool jumpFalse(const LabelTy &Label)
Local createLocal(Descriptor *D)
Callback for registering a local.
void emitLabel(LabelTy Label)
Define a label.
bool fallthrough(const LabelTy &Label)
LabelTy getLabel()
Create a label.
llvm::Expected< bool > interpretDecl(const VarDecl *VD)
llvm::Expected< bool > interpretExpr(const Expr *E)
llvm::SmallVector< SmallVector< Local, 8 >, 2 > Descriptors
Local descriptors.
virtual bool visitDecl(const VarDecl *VD)=0
bool jumpTrue(const LabelTy &Label)
Emits jumps.
Frame storing local variables.
Stack frame storing temporaries and parameters.
T pop()
Returns the value from the top of the stack and removes it.
void push(Tys &&... Args)
Constructs a value in place on the top of the stack.
InterpStack & Stk
Temporary stack.
InterpFrame * Current
The current frame.
void deallocate(Block *B)
Deallocates a pointer.
A pointer to a memory block, live or dead.
Pointer narrow() const
Restricts the scope of an array element pointer.
Pointer atIndex(unsigned Idx) const
Offsets a pointer inside an array.
bool isActive() const
Checks if the object is active.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
T & deref() const
Dereferences the pointer, if it's live.
The program contains and links the bytecode for all functions.
Structure/Class descriptor.
unsigned getNumBases() const
const Field * getField(const FieldDecl *FD) const
Returns a field.
const Base * getVirtualBase(const RecordDecl *RD) const
Returns a virtual base descriptor.
unsigned getNumFields() const
unsigned getNumVirtualBases() const
llvm::iterator_range< const_field_iter > fields() const
const Base * getBase(const RecordDecl *FD) const
Returns a base descriptor.
Describes the statement/declaration an opcode was generated from.
Interface for the VM to interact with the AST walker's context.
Describes a memory block created by an allocation site.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
Inline descriptor embedded in structures and arrays.
unsigned IsActive
Flag indicating if the field is the active member of a union.
unsigned IsBase
Flag indicating if the field is an embedded base class.
unsigned Offset
Offset inside the structure/array.
unsigned IsInitialized
For primitive fields, it indicates if the field was initialized.
unsigned IsConst
Flag indicating if the storage is constant or not.
unsigned IsFieldMutable
Flag indicating if the field is mutable (if in a record).
Mapping from primitive types to their representation.
Describes a record field.
Information about a local's storage.
unsigned Offset
Offset of the local in frame.