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 /// Evaluates an expression and places the result on the stack. If the
159 /// expression is of composite type, a local variable will be created
160 /// and a pointer to said variable will be placed on the stack.
161 bool visit(const Expr *E);
162 /// Compiles an initializer. This is like visit() but it will never
163 /// create a variable and instead rely on a variable already having
164 /// been created. visitInitializer() then relies on a pointer to this
165 /// variable being on top of the stack.
166 bool visitInitializer(const Expr *E);
167 /// Evaluates an expression for side effects and discards the result.
168 bool discard(const Expr *E);
169 /// Just pass evaluation on to \p E. This leaves all the parsing flags
170 /// intact.
171 bool delegate(const Expr *E);
172
173 /// Creates and initializes a variable from the given decl.
174 bool visitVarDecl(const VarDecl *VD);
175 /// Visit an APValue.
176 bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E);
177
178 /// Visits an expression and converts it to a boolean.
179 bool visitBool(const Expr *E);
180
181 /// Visits an initializer for a local.
182 bool visitLocalInitializer(const Expr *Init, unsigned I) {
183 if (!this->emitGetPtrLocal(I, Init))
184 return false;
185
187 return false;
188
189 if (!this->emitFinishInit(Init))
190 return false;
191
192 return this->emitPopPtr(Init);
193 }
194
195 /// Visits an initializer for a global.
196 bool visitGlobalInitializer(const Expr *Init, unsigned I) {
197 if (!this->emitGetPtrGlobal(I, Init))
198 return false;
199
201 return false;
202
203 if (!this->emitFinishInit(Init))
204 return false;
205
206 return this->emitPopPtr(Init);
207 }
208
209 /// Visits a delegated initializer.
210 bool visitThisInitializer(const Expr *I) {
211 if (!this->emitThis(I))
212 return false;
213
214 if (!visitInitializer(I))
215 return false;
216
217 return this->emitFinishInitPop(I);
218 }
219
220 bool visitInitList(ArrayRef<const Expr *> Inits, const Expr *E);
221 bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init);
222
223 /// Creates a local primitive value.
224 unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst,
225 bool IsExtended = false);
226
227 /// Allocates a space storing a local given its type.
228 std::optional<unsigned> allocateLocal(DeclTy &&Decl, bool IsExtended = false);
229
230private:
231 friend class VariableScope<Emitter>;
232 friend class LocalScope<Emitter>;
233 friend class DestructorScope<Emitter>;
234 friend class DeclScope<Emitter>;
235 friend class OptionScope<Emitter>;
236 friend class ArrayIndexScope<Emitter>;
237 friend class SourceLocScope<Emitter>;
238
239 /// Emits a zero initializer.
240 bool visitZeroInitializer(PrimType T, QualType QT, const Expr *E);
241 bool visitZeroRecordInitializer(const Record *R, const Expr *E);
242
243 /// Emits an APSInt constant.
244 bool emitConst(const llvm::APSInt &Value, PrimType Ty, const Expr *E);
245 bool emitConst(const llvm::APSInt &Value, const Expr *E);
246 bool emitConst(const llvm::APInt &Value, const Expr *E) {
247 return emitConst(static_cast<llvm::APSInt>(Value), E);
248 }
249
250 /// Emits an integer constant.
251 template <typename T> bool emitConst(T Value, PrimType Ty, const Expr *E);
252 template <typename T> bool emitConst(T Value, const Expr *E);
253
254 llvm::RoundingMode getRoundingMode(const Expr *E) const {
256
257 if (FPO.getRoundingMode() == llvm::RoundingMode::Dynamic)
258 return llvm::RoundingMode::NearestTiesToEven;
259
260 return FPO.getRoundingMode();
261 }
262
263 bool emitPrimCast(PrimType FromT, PrimType ToT, QualType ToQT, const Expr *E);
264 PrimType classifyComplexElementType(QualType T) const {
265 assert(T->isAnyComplexType());
266
267 QualType ElemType = T->getAs<ComplexType>()->getElementType();
268
269 return *this->classify(ElemType);
270 }
271
272 bool emitComplexReal(const Expr *SubExpr);
273 bool emitComplexBoolCast(const Expr *E);
274 bool emitComplexComparison(const Expr *LHS, const Expr *RHS,
275 const BinaryOperator *E);
276
277 bool emitRecordDestruction(const Record *R);
278 bool emitDestruction(const Descriptor *Desc);
279 unsigned collectBaseOffset(const RecordType *BaseType,
280 const RecordType *DerivedType);
281
282protected:
283 /// Variable to storage mapping.
284 llvm::DenseMap<const ValueDecl *, Scope::Local> Locals;
285
286 /// OpaqueValueExpr to location mapping.
287 llvm::DenseMap<const OpaqueValueExpr *, unsigned> OpaqueExprs;
288
289 /// Current scope.
291
292 /// Current argument index. Needed to emit ArrayInitIndexExpr.
293 std::optional<uint64_t> ArrayIndex;
294
295 /// DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
296 const Expr *SourceLocDefaultExpr = nullptr;
297
298 /// Flag indicating if return value is to be discarded.
299 bool DiscardResult = false;
300
301 /// Flag inidicating if we're initializing an already created
302 /// variable. This is set in visitInitializer().
303 bool Initializing = false;
304
305 /// Flag indicating if we're initializing a global variable.
306 bool GlobalDecl = false;
307};
308
309extern template class ByteCodeExprGen<ByteCodeEmitter>;
310extern template class ByteCodeExprGen<EvalEmitter>;
311
312/// Scope chain managing the variable lifetimes.
313template <class Emitter> class VariableScope {
314public:
316 : Ctx(Ctx), Parent(Ctx->VarScope) {
317 Ctx->VarScope = this;
318 }
319
320 virtual ~VariableScope() { Ctx->VarScope = this->Parent; }
321
322 void add(const Scope::Local &Local, bool IsExtended) {
323 if (IsExtended)
324 this->addExtended(Local);
325 else
326 this->addLocal(Local);
327 }
328
329 virtual void addLocal(const Scope::Local &Local) {
330 if (this->Parent)
331 this->Parent->addLocal(Local);
332 }
333
334 virtual void addExtended(const Scope::Local &Local) {
335 if (this->Parent)
336 this->Parent->addExtended(Local);
337 }
338
339 virtual void emitDestruction() {}
340 virtual bool emitDestructors() { return true; }
341 VariableScope *getParent() const { return Parent; }
342
343protected:
344 /// ByteCodeExprGen instance.
346 /// Link to the parent scope.
348};
349
350/// Generic scope for local variables.
351template <class Emitter> class LocalScope : public VariableScope<Emitter> {
352public:
354
355 /// Emit a Destroy op for this scope.
356 ~LocalScope() override {
357 if (!Idx)
358 return;
359 this->Ctx->emitDestroy(*Idx, SourceInfo{});
360 removeStoredOpaqueValues();
361 }
362
363 /// Overriden to support explicit destruction.
364 void emitDestruction() override { destroyLocals(); }
365
366 /// Explicit destruction of local variables.
368 if (!Idx)
369 return true;
370
371 bool Success = this->emitDestructors();
372 this->Ctx->emitDestroy(*Idx, SourceInfo{});
373 removeStoredOpaqueValues();
374 this->Idx = std::nullopt;
375 return Success;
376 }
377
378 void addLocal(const Scope::Local &Local) override {
379 if (!Idx) {
380 Idx = this->Ctx->Descriptors.size();
381 this->Ctx->Descriptors.emplace_back();
382 }
383
384 this->Ctx->Descriptors[*Idx].emplace_back(Local);
385 }
386
387 bool emitDestructors() override {
388 if (!Idx)
389 return true;
390 // Emit destructor calls for local variables of record
391 // type with a destructor.
392 for (Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
393 if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
394 if (!this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{}))
395 return false;
396
397 if (!this->Ctx->emitDestruction(Local.Desc))
398 return false;
399
400 if (!this->Ctx->emitPopPtr(SourceInfo{}))
401 return false;
402 removeIfStoredOpaqueValue(Local);
403 }
404 }
405 return true;
406 }
407
409 if (!Idx)
410 return;
411
412 for (const Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
413 removeIfStoredOpaqueValue(Local);
414 }
415 }
416
418 if (const auto *OVE =
419 llvm::dyn_cast_if_present<OpaqueValueExpr>(Local.Desc->asExpr())) {
420 if (auto It = this->Ctx->OpaqueExprs.find(OVE);
421 It != this->Ctx->OpaqueExprs.end())
422 this->Ctx->OpaqueExprs.erase(It);
423 };
424 }
425
426 /// Index of the scope in the chain.
427 std::optional<unsigned> Idx;
428};
429
430/// Emits the destructors of the variables of \param OtherScope
431/// when this scope is destroyed. Does not create a Scope in the bytecode at
432/// all, this is just a RAII object to emit destructors.
433template <class Emitter> class DestructorScope final {
434public:
435 DestructorScope(LocalScope<Emitter> &OtherScope) : OtherScope(OtherScope) {}
436
437 ~DestructorScope() { OtherScope.emitDestructors(); }
438
439private:
440 LocalScope<Emitter> &OtherScope;
441};
442
443/// Like a regular LocalScope, except that the destructors of all local
444/// variables are automatically emitted when the AutoScope is destroyed.
445template <class Emitter> class AutoScope : public LocalScope<Emitter> {
446public:
448 : LocalScope<Emitter>(Ctx), DS(*this) {}
449
450private:
452};
453
454/// Scope for storage declared in a compound statement.
455template <class Emitter> class BlockScope final : public AutoScope<Emitter> {
456public:
458
459 void addExtended(const Scope::Local &Local) override {
460 // If we to this point, just add the variable as a normal local
461 // variable. It will be destroyed at the end of the block just
462 // like all others.
463 this->addLocal(Local);
464 }
465};
466
467/// Expression scope which tracks potentially lifetime extended
468/// temporaries which are hoisted to the parent scope on exit.
469template <class Emitter> class ExprScope final : public AutoScope<Emitter> {
470public:
472
473 void addExtended(const Scope::Local &Local) override {
474 if (this->Parent)
475 this->Parent->addLocal(Local);
476 }
477};
478
479template <class Emitter> class ArrayIndexScope final {
480public:
481 ArrayIndexScope(ByteCodeExprGen<Emitter> *Ctx, uint64_t Index) : Ctx(Ctx) {
482 OldArrayIndex = Ctx->ArrayIndex;
483 Ctx->ArrayIndex = Index;
484 }
485
486 ~ArrayIndexScope() { Ctx->ArrayIndex = OldArrayIndex; }
487
488private:
490 std::optional<uint64_t> OldArrayIndex;
491};
492
493template <class Emitter> class SourceLocScope final {
494public:
496 : Ctx(Ctx) {
497 assert(DefaultExpr);
498 // We only switch if the current SourceLocDefaultExpr is null.
499 if (!Ctx->SourceLocDefaultExpr) {
500 Enabled = true;
501 Ctx->SourceLocDefaultExpr = DefaultExpr;
502 }
503 }
504
506 if (Enabled)
507 Ctx->SourceLocDefaultExpr = nullptr;
508 }
509
510private:
512 bool Enabled = false;
513};
514
515} // namespace interp
516} // namespace clang
517
518#endif
NodeId Parent
Definition: ASTDiff.cpp:191
llvm::MachO::Record Record
Definition: MachO.h:28
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:4148
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5571
Represents a loop initializing the elements of an array.
Definition: Expr.h:5518
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:2836
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3847
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1475
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1530
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1254
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1361
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1721
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4088
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
Represents a list-initialization with parenthesis.
Definition: ExprCXX.h:4913
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:2165
Represents the this expression in C++.
Definition: ExprCXX.h:1148
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1192
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:3490
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4565
Complex values, per C99 6.2.5p11.
Definition: Type.h:2875
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4095
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3420
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:3436
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:3852
An expression trait intrinsic.
Definition: ExprCXX.h:2907
RoundingMode getRoundingMode() const
Definition: LangOptions.h:837
Represents a function declaration or definition.
Definition: Decl.h:1959
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4640
Represents a C11 generic selection.
Definition: Expr.h:5732
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:5607
Describes an C or C++ initializer list.
Definition: Expr.h:4854
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1938
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4679
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3183
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:6312
A (possibly-)qualified type.
Definition: Type.h:738
Represents a struct/union/class.
Definition: Decl.h:4133
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5309
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:4220
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4734
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:4435
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2751
bool isAnyComplexType() const
Definition: Type.h:7469
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7878
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(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.
@ Success
Template argument deduction was successful.
Information about a local's storage.
Definition: Function.h:38