clang 19.0.0git
ByteCodeExprGen.h
Go to the documentation of this file.
1//===--- ByteCodeExprGen.h - Code generator for expressions -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Defines the constexpr bytecode compiler.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_INTERP_BYTECODEEXPRGEN_H
14#define LLVM_CLANG_AST_INTERP_BYTECODEEXPRGEN_H
15
16#include "ByteCodeEmitter.h"
17#include "EvalEmitter.h"
18#include "Pointer.h"
19#include "PrimType.h"
20#include "Record.h"
21#include "clang/AST/Decl.h"
22#include "clang/AST/Expr.h"
25
26namespace clang {
27class QualType;
28
29namespace interp {
30
31template <class Emitter> class LocalScope;
32template <class Emitter> class DestructorScope;
33template <class Emitter> class VariableScope;
34template <class Emitter> class DeclScope;
35template <class Emitter> class OptionScope;
36template <class Emitter> class ArrayIndexScope;
37template <class Emitter> class SourceLocScope;
38
39/// Compilation context for expressions.
40template <class Emitter>
41class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
42 public Emitter {
43protected:
44 // Aliases for types defined in the emitter.
45 using LabelTy = typename Emitter::LabelTy;
46 using AddrTy = typename Emitter::AddrTy;
47
48 /// Current compilation context.
50 /// Program to link to.
52
53public:
54 /// Initializes the compiler and the backend emitter.
55 template <typename... Tys>
56 ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
57 : Emitter(Ctx, P, Args...), Ctx(Ctx), P(P) {}
58
59 // Expression visitors - result returned on interp stack.
60 bool VisitCastExpr(const CastExpr *E);
64 bool VisitParenExpr(const ParenExpr *E);
66 bool VisitLogicalBinOp(const BinaryOperator *E);
68 bool VisitComplexBinOp(const BinaryOperator *E);
70 bool VisitCallExpr(const CallExpr *E);
71 bool VisitBuiltinCallExpr(const CallExpr *E);
75 bool VisitGNUNullExpr(const GNUNullExpr *E);
76 bool VisitCXXThisExpr(const CXXThisExpr *E);
77 bool VisitUnaryOperator(const UnaryOperator *E);
79 bool VisitDeclRefExpr(const DeclRefExpr *E);
83 bool VisitInitListExpr(const InitListExpr *E);
85 bool VisitConstantExpr(const ConstantExpr *E);
87 bool VisitMemberExpr(const MemberExpr *E);
92 bool VisitStringLiteral(const StringLiteral *E);
101 bool VisitTypeTraitExpr(const TypeTraitExpr *E);
103 bool VisitLambdaExpr(const LambdaExpr *E);
104 bool VisitPredefinedExpr(const PredefinedExpr *E);
105 bool VisitCXXThrowExpr(const CXXThrowExpr *E);
109 bool VisitSourceLocExpr(const SourceLocExpr *E);
110 bool VisitOffsetOfExpr(const OffsetOfExpr *E);
112 bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
114 bool VisitChooseExpr(const ChooseExpr *E);
118 bool VisitCXXUuidofExpr(const CXXUuidofExpr *E);
119 bool VisitRequiresExpr(const RequiresExpr *E);
124
125protected:
126 bool visitExpr(const Expr *E) override;
127 bool visitDecl(const VarDecl *VD) override;
128
129protected:
130 /// Emits scope cleanup instructions.
131 void emitCleanup();
132
133 /// Returns a record type from a record or pointer type.
135
136 /// Returns a record from a record or pointer type.
138 Record *getRecord(const RecordDecl *RD);
139
140 // Returns a function for the given FunctionDecl.
141 // If the function does not exist yet, it is compiled.
142 const Function *getFunction(const FunctionDecl *FD);
143
144 std::optional<PrimType> classify(const Expr *E) const {
145 return Ctx.classify(E);
146 }
147 std::optional<PrimType> classify(QualType Ty) const {
148 return Ctx.classify(Ty);
149 }
150
151 /// Classifies a known primitive type.
153 if (auto T = classify(Ty)) {
154 return *T;
155 }
156 llvm_unreachable("not a primitive type");
157 }
158 /// Classifies a known primitive expression.
159 PrimType classifyPrim(const Expr *E) const {
160 if (auto T = classify(E))
161 return *T;
162 llvm_unreachable("not a primitive type");
163 }
164
165 /// Evaluates an expression and places the result on the stack. If the
166 /// expression is of composite type, a local variable will be created
167 /// and a pointer to said variable will be placed on the stack.
168 bool visit(const Expr *E);
169 /// Compiles an initializer. This is like visit() but it will never
170 /// create a variable and instead rely on a variable already having
171 /// been created. visitInitializer() then relies on a pointer to this
172 /// variable being on top of the stack.
173 bool visitInitializer(const Expr *E);
174 /// Evaluates an expression for side effects and discards the result.
175 bool discard(const Expr *E);
176 /// Just pass evaluation on to \p E. This leaves all the parsing flags
177 /// intact.
178 bool delegate(const Expr *E);
179
180 /// Creates and initializes a variable from the given decl.
181 bool visitVarDecl(const VarDecl *VD);
182 /// Visit an APValue.
183 bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E);
184
185 /// Visits an expression and converts it to a boolean.
186 bool visitBool(const Expr *E);
187
188 /// Visits an initializer for a local.
189 bool visitLocalInitializer(const Expr *Init, unsigned I) {
190 if (!this->emitGetPtrLocal(I, Init))
191 return false;
192
194 return false;
195
196 if (!this->emitFinishInit(Init))
197 return false;
198
199 return this->emitPopPtr(Init);
200 }
201
202 /// Visits an initializer for a global.
203 bool visitGlobalInitializer(const Expr *Init, unsigned I) {
204 if (!this->emitGetPtrGlobal(I, Init))
205 return false;
206
208 return false;
209
210 if (!this->emitFinishInit(Init))
211 return false;
212
213 return this->emitPopPtr(Init);
214 }
215
216 /// Visits a delegated initializer.
217 bool visitThisInitializer(const Expr *I) {
218 if (!this->emitThis(I))
219 return false;
220
221 if (!visitInitializer(I))
222 return false;
223
224 return this->emitFinishInitPop(I);
225 }
226
227 bool visitInitList(ArrayRef<const Expr *> Inits, const Expr *E);
228 bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init);
229
230 /// Creates a local primitive value.
231 unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst,
232 bool IsExtended = false);
233
234 /// Allocates a space storing a local given its type.
235 std::optional<unsigned> allocateLocal(DeclTy &&Decl, bool IsExtended = false);
236
237private:
238 friend class VariableScope<Emitter>;
239 friend class LocalScope<Emitter>;
240 friend class DestructorScope<Emitter>;
241 friend class DeclScope<Emitter>;
242 friend class OptionScope<Emitter>;
243 friend class ArrayIndexScope<Emitter>;
244 friend class SourceLocScope<Emitter>;
245
246 /// Emits a zero initializer.
247 bool visitZeroInitializer(PrimType T, QualType QT, const Expr *E);
248 bool visitZeroRecordInitializer(const Record *R, const Expr *E);
249
250 /// Emits an APSInt constant.
251 bool emitConst(const llvm::APSInt &Value, PrimType Ty, const Expr *E);
252 bool emitConst(const llvm::APSInt &Value, const Expr *E);
253 bool emitConst(const llvm::APInt &Value, const Expr *E) {
254 return emitConst(static_cast<llvm::APSInt>(Value), E);
255 }
256
257 /// Emits an integer constant.
258 template <typename T> bool emitConst(T Value, PrimType Ty, const Expr *E);
259 template <typename T> bool emitConst(T Value, const Expr *E);
260
261 llvm::RoundingMode getRoundingMode(const Expr *E) const {
263
264 if (FPO.getRoundingMode() == llvm::RoundingMode::Dynamic)
265 return llvm::RoundingMode::NearestTiesToEven;
266
267 return FPO.getRoundingMode();
268 }
269
270 bool emitPrimCast(PrimType FromT, PrimType ToT, QualType ToQT, const Expr *E);
271 PrimType classifyComplexElementType(QualType T) const {
272 assert(T->isAnyComplexType());
273
274 QualType ElemType = T->getAs<ComplexType>()->getElementType();
275
276 return *this->classify(ElemType);
277 }
278
279 bool emitComplexReal(const Expr *SubExpr);
280 bool emitComplexBoolCast(const Expr *E);
281 bool emitComplexComparison(const Expr *LHS, const Expr *RHS,
282 const BinaryOperator *E);
283
284 bool emitRecordDestruction(const Record *R);
285 bool emitDestruction(const Descriptor *Desc);
286 unsigned collectBaseOffset(const RecordType *BaseType,
287 const RecordType *DerivedType);
288
289protected:
290 /// Variable to storage mapping.
291 llvm::DenseMap<const ValueDecl *, Scope::Local> Locals;
292
293 /// OpaqueValueExpr to location mapping.
294 llvm::DenseMap<const OpaqueValueExpr *, unsigned> OpaqueExprs;
295
296 /// Current scope.
298
299 /// Current argument index. Needed to emit ArrayInitIndexExpr.
300 std::optional<uint64_t> ArrayIndex;
301
302 /// DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
303 const Expr *SourceLocDefaultExpr = nullptr;
304
305 /// Flag indicating if return value is to be discarded.
306 bool DiscardResult = false;
307
308 /// Flag inidicating if we're initializing an already created
309 /// variable. This is set in visitInitializer().
310 bool Initializing = false;
311
312 /// Flag indicating if we're initializing a global variable.
313 bool GlobalDecl = false;
314};
315
316extern template class ByteCodeExprGen<ByteCodeEmitter>;
317extern template class ByteCodeExprGen<EvalEmitter>;
318
319/// Scope chain managing the variable lifetimes.
320template <class Emitter> class VariableScope {
321public:
323 : Ctx(Ctx), Parent(Ctx->VarScope) {
324 Ctx->VarScope = this;
325 }
326
327 virtual ~VariableScope() { Ctx->VarScope = this->Parent; }
328
329 void add(const Scope::Local &Local, bool IsExtended) {
330 if (IsExtended)
331 this->addExtended(Local);
332 else
333 this->addLocal(Local);
334 }
335
336 virtual void addLocal(const Scope::Local &Local) {
337 if (this->Parent)
338 this->Parent->addLocal(Local);
339 }
340
341 virtual void addExtended(const Scope::Local &Local) {
342 if (this->Parent)
343 this->Parent->addExtended(Local);
344 }
345
346 virtual void emitDestruction() {}
347 virtual bool emitDestructors() { return true; }
348 VariableScope *getParent() const { return Parent; }
349
350protected:
351 /// ByteCodeExprGen instance.
353 /// Link to the parent scope.
355};
356
357/// Generic scope for local variables.
358template <class Emitter> class LocalScope : public VariableScope<Emitter> {
359public:
361
362 /// Emit a Destroy op for this scope.
363 ~LocalScope() override {
364 if (!Idx)
365 return;
366 this->Ctx->emitDestroy(*Idx, SourceInfo{});
367 removeStoredOpaqueValues();
368 }
369
370 /// Overriden to support explicit destruction.
371 void emitDestruction() override { destroyLocals(); }
372
373 /// Explicit destruction of local variables.
375 if (!Idx)
376 return true;
377
378 bool Success = this->emitDestructors();
379 this->Ctx->emitDestroy(*Idx, SourceInfo{});
380 removeStoredOpaqueValues();
381 this->Idx = std::nullopt;
382 return Success;
383 }
384
385 void addLocal(const Scope::Local &Local) override {
386 if (!Idx) {
387 Idx = this->Ctx->Descriptors.size();
388 this->Ctx->Descriptors.emplace_back();
389 }
390
391 this->Ctx->Descriptors[*Idx].emplace_back(Local);
392 }
393
394 bool emitDestructors() override {
395 if (!Idx)
396 return true;
397 // Emit destructor calls for local variables of record
398 // type with a destructor.
399 for (Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
400 if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
401 if (!this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{}))
402 return false;
403
404 if (!this->Ctx->emitDestruction(Local.Desc))
405 return false;
406
407 if (!this->Ctx->emitPopPtr(SourceInfo{}))
408 return false;
409 removeIfStoredOpaqueValue(Local);
410 }
411 }
412 return true;
413 }
414
416 if (!Idx)
417 return;
418
419 for (const Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
420 removeIfStoredOpaqueValue(Local);
421 }
422 }
423
425 if (const auto *OVE =
426 llvm::dyn_cast_if_present<OpaqueValueExpr>(Local.Desc->asExpr())) {
427 if (auto It = this->Ctx->OpaqueExprs.find(OVE);
428 It != this->Ctx->OpaqueExprs.end())
429 this->Ctx->OpaqueExprs.erase(It);
430 };
431 }
432
433 /// Index of the scope in the chain.
434 std::optional<unsigned> Idx;
435};
436
437/// Emits the destructors of the variables of \param OtherScope
438/// when this scope is destroyed. Does not create a Scope in the bytecode at
439/// all, this is just a RAII object to emit destructors.
440template <class Emitter> class DestructorScope final {
441public:
442 DestructorScope(LocalScope<Emitter> &OtherScope) : OtherScope(OtherScope) {}
443
444 ~DestructorScope() { OtherScope.emitDestructors(); }
445
446private:
447 LocalScope<Emitter> &OtherScope;
448};
449
450/// Like a regular LocalScope, except that the destructors of all local
451/// variables are automatically emitted when the AutoScope is destroyed.
452template <class Emitter> class AutoScope : public LocalScope<Emitter> {
453public:
455 : LocalScope<Emitter>(Ctx), DS(*this) {}
456
457private:
459};
460
461/// Scope for storage declared in a compound statement.
462template <class Emitter> class BlockScope final : public AutoScope<Emitter> {
463public:
465
466 void addExtended(const Scope::Local &Local) override {
467 // If we to this point, just add the variable as a normal local
468 // variable. It will be destroyed at the end of the block just
469 // like all others.
470 this->addLocal(Local);
471 }
472};
473
474/// Expression scope which tracks potentially lifetime extended
475/// temporaries which are hoisted to the parent scope on exit.
476template <class Emitter> class ExprScope final : public AutoScope<Emitter> {
477public:
479
480 void addExtended(const Scope::Local &Local) override {
481 if (this->Parent)
482 this->Parent->addLocal(Local);
483 }
484};
485
486template <class Emitter> class ArrayIndexScope final {
487public:
488 ArrayIndexScope(ByteCodeExprGen<Emitter> *Ctx, uint64_t Index) : Ctx(Ctx) {
489 OldArrayIndex = Ctx->ArrayIndex;
490 Ctx->ArrayIndex = Index;
491 }
492
493 ~ArrayIndexScope() { Ctx->ArrayIndex = OldArrayIndex; }
494
495private:
497 std::optional<uint64_t> OldArrayIndex;
498};
499
500template <class Emitter> class SourceLocScope final {
501public:
503 : Ctx(Ctx) {
504 assert(DefaultExpr);
505 // We only switch if the current SourceLocDefaultExpr is null.
506 if (!Ctx->SourceLocDefaultExpr) {
507 Enabled = true;
508 Ctx->SourceLocDefaultExpr = DefaultExpr;
509 }
510 }
511
513 if (Enabled)
514 Ctx->SourceLocDefaultExpr = nullptr;
515 }
516
517private:
519 bool Enabled = false;
520};
521
522} // namespace interp
523} // namespace clang
524
525#endif
NodeId Parent
Definition: ASTDiff.cpp:191
llvm::MachO::Record Record
Definition: MachO.h:31
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition: Expr.h:4141
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5564
Represents a loop initializing the elements of an array.
Definition: Expr.h:5511
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2664
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2846
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3840
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1485
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1540
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1264
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1371
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1731
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4098
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
Represents a list-initialization with parenthesis.
Definition: ExprCXX.h:4923
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition: ExprCXX.h:523
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2175
Represents the this expression in C++.
Definition: ExprCXX.h:1148
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1202
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition: ExprCXX.h:1062
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2820
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3483
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4558
Complex values, per C99 6.2.5p11.
Definition: Type.h:2876
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4088
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3413
Represents the specialization of a concept - evaluates to a prvalue of type bool.
Definition: ExprConcepts.h:42
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:195
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1072
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1260
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3446
This represents one expression.
Definition: Expr.h:110
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
Definition: Expr.cpp:3846
An expression trait intrinsic.
Definition: ExprCXX.h:2917
RoundingMode getRoundingMode() const
Definition: LangOptions.h:842
Represents a function declaration or definition.
Definition: Decl.h:1971
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4633
Represents a C11 generic selection.
Definition: Expr.h:5725
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1712
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5600
Describes an C or C++ initializer list.
Definition: Expr.h:4847
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1948
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4689
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3172
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition: ExprObjC.h:87
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2465
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1168
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2130
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1986
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6305
A (possibly-)qualified type.
Definition: Type.h:738
Represents a struct/union/class.
Definition: Decl.h:4169
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5339
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:510
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4230
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4727
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4445
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2761
bool isAnyComplexType() const
Definition: Type.h:7504
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7913
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2568
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2183
Represents a variable declaration or definition.
Definition: Decl.h:918
ArrayIndexScope(ByteCodeExprGen< Emitter > *Ctx, uint64_t Index)
Like a regular LocalScope, except that the destructors of all local variables are automatically emitt...
AutoScope(ByteCodeExprGen< Emitter > *Ctx)
Scope for storage declared in a compound statement.
BlockScope(ByteCodeExprGen< Emitter > *Ctx)
void addExtended(const Scope::Local &Local) override
Compilation context for expressions.
bool visitExpr(const Expr *E) override
std::optional< unsigned > allocateLocal(DeclTy &&Decl, bool IsExtended=false)
Allocates a space storing a local given its type.
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst, bool IsExtended=false)
Creates a local primitive value.
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool VisitDeclRefExpr(const DeclRefExpr *E)
bool VisitExprWithCleanups(const ExprWithCleanups *E)
bool VisitPseudoObjectExpr(const PseudoObjectExpr *E)
bool VisitComplexBinOp(const BinaryOperator *E)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitMemberExpr(const MemberExpr *E)
bool VisitOffsetOfExpr(const OffsetOfExpr *E)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
bool visitThisInitializer(const Expr *I)
Visits a delegated initializer.
bool visitDecl(const VarDecl *VD) override
Toplevel visitDecl().
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E)
bool visitInitializer(const Expr *E)
Compiles an initializer.
bool VisitParenExpr(const ParenExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E)
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E)
bool VisitImaginaryLiteral(const ImaginaryLiteral *E)
bool VisitLambdaExpr(const LambdaExpr *E)
bool VisitCXXParenListInitExpr(const CXXParenListInitExpr *E)
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E)
bool VisitComplexUnaryOperator(const UnaryOperator *E)
bool VisitRequiresExpr(const RequiresExpr *E)
Program & P
Program to link to.
bool VisitBuiltinCallExpr(const CallExpr *E)
PrimType classifyPrim(const Expr *E) const
Classifies a known primitive expression.
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E)
bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init)
Pointer to the array(not the element!) must be on the stack when calling this.
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
void emitCleanup()
Emits scope cleanup instructions.
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
Context & Ctx
Current compilation context.
bool visitGlobalInitializer(const Expr *Init, unsigned I)
Visits an initializer for a global.
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
bool VisitPredefinedExpr(const PredefinedExpr *E)
VariableScope< Emitter > * VarScope
Current scope.
std::optional< PrimType > classify(QualType Ty) const
bool VisitBinaryOperator(const BinaryOperator *E)
bool VisitTypeTraitExpr(const TypeTraitExpr *E)
bool visit(const Expr *E)
Evaluates an expression and places the result on the stack.
bool VisitInitListExpr(const InitListExpr *E)
bool VisitFloatingLiteral(const FloatingLiteral *E)
bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E)
bool VisitPackIndexingExpr(const PackIndexingExpr *E)
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E)
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E)
bool visitInitList(ArrayRef< const Expr * > Inits, const Expr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E)
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E)
bool VisitUnaryOperator(const UnaryOperator *E)
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
std::optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E)
bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E)
std::optional< PrimType > classify(const Expr *E) const
bool DiscardResult
Flag indicating if return value is to be discarded.
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
const Function * getFunction(const FunctionDecl *FD)
bool visitLocalInitializer(const Expr *Init, unsigned I)
Visits an initializer for a local.
bool VisitLogicalBinOp(const BinaryOperator *E)
bool visitVarDecl(const VarDecl *VD)
Creates and initializes a variable from the given decl.
bool VisitStringLiteral(const StringLiteral *E)
bool VisitCXXConstructExpr(const CXXConstructExpr *E)
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E)
ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
Initializes the compiler and the backend emitter.
const Expr * SourceLocDefaultExpr
DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
bool VisitGNUNullExpr(const GNUNullExpr *E)
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
bool VisitSourceLocExpr(const SourceLocExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
bool VisitCXXThisExpr(const CXXThisExpr *E)
bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E)
typename Emitter::LabelTy LabelTy
bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E)
Visit an APValue.
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E)
bool VisitCallExpr(const CallExpr *E)
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
bool delegate(const Expr *E)
Just pass evaluation on to E.
bool VisitConstantExpr(const ConstantExpr *E)
bool VisitChooseExpr(const ChooseExpr *E)
bool VisitCastExpr(const CastExpr *E)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E)
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
typename Emitter::AddrTy AddrTy
Holds all information required to evaluate constexpr code in a module.
Definition: Context.h:40
const LangOptions & getLangOpts() const
Returns the language options.
Definition: Context.cpp:117
std::optional< PrimType > classify(QualType T) const
Classifies a type.
Definition: Context.cpp:119
Scope used to handle temporaries in toplevel variable declarations.
Emits the destructors of the variables of.
DestructorScope(LocalScope< Emitter > &OtherScope)
Expression scope which tracks potentially lifetime extended temporaries which are hoisted to the pare...
void addExtended(const Scope::Local &Local) override
ExprScope(ByteCodeExprGen< Emitter > *Ctx)
Bytecode function.
Definition: Function.h:77
Generic scope for local variables.
bool destroyLocals()
Explicit destruction of local variables.
~LocalScope() override
Emit a Destroy op for this scope.
void emitDestruction() override
Overriden to support explicit destruction.
void removeIfStoredOpaqueValue(const Scope::Local &Local)
bool emitDestructors() override
void addLocal(const Scope::Local &Local) override
std::optional< unsigned > Idx
Index of the scope in the chain.
LocalScope(ByteCodeExprGen< Emitter > *Ctx)
Scope used to handle initialization methods.
The program contains and links the bytecode for all functions.
Definition: Program.h:39
Structure/Class descriptor.
Definition: Record.h:25
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:72
SourceLocScope(ByteCodeExprGen< Emitter > *Ctx, const Expr *DefaultExpr)
Scope chain managing the variable lifetimes.
virtual void addExtended(const Scope::Local &Local)
void add(const Scope::Local &Local, bool IsExtended)
VariableScope * Parent
Link to the parent scope.
virtual void addLocal(const Scope::Local &Local)
VariableScope(ByteCodeExprGen< Emitter > *Ctx)
VariableScope * getParent() const
ByteCodeExprGen< Emitter > * Ctx
ByteCodeExprGen instance.
Defines the clang::TargetInfo interface.
PrimType
Enumeration of the primitive types of the VM.
Definition: PrimType.h:32
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition: Descriptor.h:27
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
@ Success
Template argument deduction was successful.
Information about a local's storage.
Definition: Function.h:38