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);
104 bool VisitTypeTraitExpr(const TypeTraitExpr *E);
106 bool VisitLambdaExpr(const LambdaExpr *E);
107 bool VisitPredefinedExpr(const PredefinedExpr *E);
108 bool VisitCXXThrowExpr(const CXXThrowExpr *E);
112 bool VisitSourceLocExpr(const SourceLocExpr *E);
113 bool VisitOffsetOfExpr(const OffsetOfExpr *E);
115 bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
117 bool VisitChooseExpr(const ChooseExpr *E);
121 bool VisitCXXUuidofExpr(const CXXUuidofExpr *E);
122 bool VisitRequiresExpr(const RequiresExpr *E);
127 bool VisitRecoveryExpr(const RecoveryExpr *E);
128 bool VisitAddrLabelExpr(const AddrLabelExpr *E);
131 bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E);
132
133protected:
134 bool visitExpr(const Expr *E) override;
135 bool visitDecl(const VarDecl *VD) override;
136
137protected:
138 /// Emits scope cleanup instructions.
139 void emitCleanup();
140
141 /// Returns a record type from a record or pointer type.
143
144 /// Returns a record from a record or pointer type.
146 Record *getRecord(const RecordDecl *RD);
147
148 // Returns a function for the given FunctionDecl.
149 // If the function does not exist yet, it is compiled.
150 const Function *getFunction(const FunctionDecl *FD);
151
152 std::optional<PrimType> classify(const Expr *E) const {
153 return Ctx.classify(E);
154 }
155 std::optional<PrimType> classify(QualType Ty) const {
156 return Ctx.classify(Ty);
157 }
158
159 /// Classifies a known primitive type.
161 if (auto T = classify(Ty)) {
162 return *T;
163 }
164 llvm_unreachable("not a primitive type");
165 }
166 /// Classifies a known primitive expression.
167 PrimType classifyPrim(const Expr *E) const {
168 if (auto T = classify(E))
169 return *T;
170 llvm_unreachable("not a primitive type");
171 }
172
173 /// Evaluates an expression and places the result on the stack. If the
174 /// expression is of composite type, a local variable will be created
175 /// and a pointer to said variable will be placed on the stack.
176 bool visit(const Expr *E);
177 /// Compiles an initializer. This is like visit() but it will never
178 /// create a variable and instead rely on a variable already having
179 /// been created. visitInitializer() then relies on a pointer to this
180 /// variable being on top of the stack.
181 bool visitInitializer(const Expr *E);
182 /// Evaluates an expression for side effects and discards the result.
183 bool discard(const Expr *E);
184 /// Just pass evaluation on to \p E. This leaves all the parsing flags
185 /// intact.
186 bool delegate(const Expr *E);
187
188 /// Creates and initializes a variable from the given decl.
189 bool visitVarDecl(const VarDecl *VD);
190 /// Visit an APValue.
191 bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E);
192 bool visitAPValueInitializer(const APValue &Val, const Expr *E);
193 /// Visit the given decl as if we have a reference to it.
194 bool visitDeclRef(const ValueDecl *D, const Expr *E);
195
196 /// Visits an expression and converts it to a boolean.
197 bool visitBool(const Expr *E);
198
199 /// Visits an initializer for a local.
200 bool visitLocalInitializer(const Expr *Init, unsigned I) {
201 if (!this->emitGetPtrLocal(I, Init))
202 return false;
203
205 return false;
206
207 if (!this->emitFinishInit(Init))
208 return false;
209
210 return this->emitPopPtr(Init);
211 }
212
213 /// Visits an initializer for a global.
214 bool visitGlobalInitializer(const Expr *Init, unsigned I) {
215 if (!this->emitGetPtrGlobal(I, Init))
216 return false;
217
219 return false;
220
221 if (!this->emitFinishInit(Init))
222 return false;
223
224 return this->emitPopPtr(Init);
225 }
226
227 /// Visits a delegated initializer.
228 bool visitThisInitializer(const Expr *I) {
229 if (!this->emitThis(I))
230 return false;
231
232 if (!visitInitializer(I))
233 return false;
234
235 return this->emitFinishInitPop(I);
236 }
237
238 bool visitInitList(ArrayRef<const Expr *> Inits, const Expr *ArrayFiller,
239 const Expr *E);
240 bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init);
241
242 /// Creates a local primitive value.
243 unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst,
244 bool IsExtended = false);
245
246 /// Allocates a space storing a local given its type.
247 std::optional<unsigned>
248 allocateLocal(DeclTy &&Decl, const ValueDecl *ExtendingDecl = nullptr);
249
250private:
251 friend class VariableScope<Emitter>;
252 friend class LocalScope<Emitter>;
253 friend class DestructorScope<Emitter>;
254 friend class DeclScope<Emitter>;
255 friend class OptionScope<Emitter>;
256 friend class ArrayIndexScope<Emitter>;
257 friend class SourceLocScope<Emitter>;
258
259 /// Emits a zero initializer.
260 bool visitZeroInitializer(PrimType T, QualType QT, const Expr *E);
261 bool visitZeroRecordInitializer(const Record *R, const Expr *E);
262
263 /// Emits an APSInt constant.
264 bool emitConst(const llvm::APSInt &Value, PrimType Ty, const Expr *E);
265 bool emitConst(const llvm::APSInt &Value, const Expr *E);
266 bool emitConst(const llvm::APInt &Value, const Expr *E) {
267 return emitConst(static_cast<llvm::APSInt>(Value), E);
268 }
269
270 /// Emits an integer constant.
271 template <typename T> bool emitConst(T Value, PrimType Ty, const Expr *E);
272 template <typename T> bool emitConst(T Value, const Expr *E);
273
274 llvm::RoundingMode getRoundingMode(const Expr *E) const {
276
277 if (FPO.getRoundingMode() == llvm::RoundingMode::Dynamic)
278 return llvm::RoundingMode::NearestTiesToEven;
279
280 return FPO.getRoundingMode();
281 }
282
283 bool emitPrimCast(PrimType FromT, PrimType ToT, QualType ToQT, const Expr *E);
284 PrimType classifyComplexElementType(QualType T) const {
285 assert(T->isAnyComplexType());
286
287 QualType ElemType = T->getAs<ComplexType>()->getElementType();
288
289 return *this->classify(ElemType);
290 }
291
292 bool emitComplexReal(const Expr *SubExpr);
293 bool emitComplexBoolCast(const Expr *E);
294 bool emitComplexComparison(const Expr *LHS, const Expr *RHS,
295 const BinaryOperator *E);
296
297 bool emitRecordDestruction(const Record *R);
298 bool emitDestruction(const Descriptor *Desc);
299 unsigned collectBaseOffset(const QualType BaseType,
300 const QualType DerivedType);
301
302protected:
303 /// Variable to storage mapping.
304 llvm::DenseMap<const ValueDecl *, Scope::Local> Locals;
305
306 /// OpaqueValueExpr to location mapping.
307 llvm::DenseMap<const OpaqueValueExpr *, unsigned> OpaqueExprs;
308
309 /// Current scope.
311
312 /// Current argument index. Needed to emit ArrayInitIndexExpr.
313 std::optional<uint64_t> ArrayIndex;
314
315 /// DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
316 const Expr *SourceLocDefaultExpr = nullptr;
317
318 /// Flag indicating if return value is to be discarded.
319 bool DiscardResult = false;
320
321 /// Flag inidicating if we're initializing an already created
322 /// variable. This is set in visitInitializer().
323 bool Initializing = false;
324
325 /// Flag indicating if we're initializing a global variable.
326 bool GlobalDecl = false;
327};
328
329extern template class ByteCodeExprGen<ByteCodeEmitter>;
330extern template class ByteCodeExprGen<EvalEmitter>;
331
332/// Scope chain managing the variable lifetimes.
333template <class Emitter> class VariableScope {
334public:
336 : Ctx(Ctx), Parent(Ctx->VarScope), ValDecl(VD) {
337 Ctx->VarScope = this;
338 }
339
340 virtual ~VariableScope() { Ctx->VarScope = this->Parent; }
341
342 void add(const Scope::Local &Local, bool IsExtended) {
343 if (IsExtended)
344 this->addExtended(Local);
345 else
346 this->addLocal(Local);
347 }
348
349 virtual void addLocal(const Scope::Local &Local) {
350 if (this->Parent)
351 this->Parent->addLocal(Local);
352 }
353
354 virtual void addExtended(const Scope::Local &Local) {
355 if (this->Parent)
356 this->Parent->addExtended(Local);
357 }
358
359 void addExtended(const Scope::Local &Local, const ValueDecl *ExtendingDecl) {
360 // Walk up the chain of scopes until we find the one for ExtendingDecl.
361 // If there is no such scope, attach it to the parent one.
362 VariableScope *P = this;
363 while (P) {
364 if (P->ValDecl == ExtendingDecl) {
365 P->addLocal(Local);
366 return;
367 }
368 P = P->Parent;
369 if (!P)
370 break;
371 }
372
373 // Use the parent scope.
374 addExtended(Local);
375 }
376
377 virtual void emitDestruction() {}
378 virtual bool emitDestructors() { return true; }
379 VariableScope *getParent() const { return Parent; }
380
381protected:
382 /// ByteCodeExprGen instance.
384 /// Link to the parent scope.
386 const ValueDecl *ValDecl = nullptr;
387};
388
389/// Generic scope for local variables.
390template <class Emitter> class LocalScope : public VariableScope<Emitter> {
391public:
393 : VariableScope<Emitter>(Ctx, nullptr) {}
394
395 /// Emit a Destroy op for this scope.
396 ~LocalScope() override {
397 if (!Idx)
398 return;
399 this->Ctx->emitDestroy(*Idx, SourceInfo{});
400 removeStoredOpaqueValues();
401 }
402
403 /// Overriden to support explicit destruction.
404 void emitDestruction() override { destroyLocals(); }
405
406 /// Explicit destruction of local variables.
408 if (!Idx)
409 return true;
410
411 bool Success = this->emitDestructors();
412 this->Ctx->emitDestroy(*Idx, SourceInfo{});
413 removeStoredOpaqueValues();
414 this->Idx = std::nullopt;
415 return Success;
416 }
417
418 void addLocal(const Scope::Local &Local) override {
419 if (!Idx) {
420 Idx = this->Ctx->Descriptors.size();
421 this->Ctx->Descriptors.emplace_back();
422 }
423
424 this->Ctx->Descriptors[*Idx].emplace_back(Local);
425 }
426
427 bool emitDestructors() override {
428 if (!Idx)
429 return true;
430 // Emit destructor calls for local variables of record
431 // type with a destructor.
432 for (Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
433 if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
434 if (!this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{}))
435 return false;
436
437 if (!this->Ctx->emitDestruction(Local.Desc))
438 return false;
439
440 if (!this->Ctx->emitPopPtr(SourceInfo{}))
441 return false;
442 removeIfStoredOpaqueValue(Local);
443 }
444 }
445 return true;
446 }
447
449 if (!Idx)
450 return;
451
452 for (const Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
453 removeIfStoredOpaqueValue(Local);
454 }
455 }
456
458 if (const auto *OVE =
459 llvm::dyn_cast_if_present<OpaqueValueExpr>(Local.Desc->asExpr())) {
460 if (auto It = this->Ctx->OpaqueExprs.find(OVE);
461 It != this->Ctx->OpaqueExprs.end())
462 this->Ctx->OpaqueExprs.erase(It);
463 };
464 }
465
466 /// Index of the scope in the chain.
467 std::optional<unsigned> Idx;
468};
469
470/// Emits the destructors of the variables of \param OtherScope
471/// when this scope is destroyed. Does not create a Scope in the bytecode at
472/// all, this is just a RAII object to emit destructors.
473template <class Emitter> class DestructorScope final {
474public:
475 DestructorScope(LocalScope<Emitter> &OtherScope) : OtherScope(OtherScope) {}
476
477 ~DestructorScope() { OtherScope.emitDestructors(); }
478
479private:
480 LocalScope<Emitter> &OtherScope;
481};
482
483/// Like a regular LocalScope, except that the destructors of all local
484/// variables are automatically emitted when the AutoScope is destroyed.
485template <class Emitter> class AutoScope : public LocalScope<Emitter> {
486public:
488 : LocalScope<Emitter>(Ctx), DS(*this) {}
489
490private:
492};
493
494/// Scope for storage declared in a compound statement.
495template <class Emitter> class BlockScope final : public AutoScope<Emitter> {
496public:
498
499 void addExtended(const Scope::Local &Local) override {
500 // If we to this point, just add the variable as a normal local
501 // variable. It will be destroyed at the end of the block just
502 // like all others.
503 this->addLocal(Local);
504 }
505};
506
507template <class Emitter> class ExprScope final : public AutoScope<Emitter> {
508public:
510};
511
512template <class Emitter> class ArrayIndexScope final {
513public:
514 ArrayIndexScope(ByteCodeExprGen<Emitter> *Ctx, uint64_t Index) : Ctx(Ctx) {
515 OldArrayIndex = Ctx->ArrayIndex;
516 Ctx->ArrayIndex = Index;
517 }
518
519 ~ArrayIndexScope() { Ctx->ArrayIndex = OldArrayIndex; }
520
521private:
523 std::optional<uint64_t> OldArrayIndex;
524};
525
526template <class Emitter> class SourceLocScope final {
527public:
529 : Ctx(Ctx) {
530 assert(DefaultExpr);
531 // We only switch if the current SourceLocDefaultExpr is null.
532 if (!Ctx->SourceLocDefaultExpr) {
533 Enabled = true;
534 Ctx->SourceLocDefaultExpr = DefaultExpr;
535 }
536 }
537
539 if (Enabled)
540 Ctx->SourceLocDefaultExpr = nullptr;
541 }
542
543private:
545 bool Enabled = false;
546};
547
548} // namespace interp
549} // namespace clang
550
551#endif
NodeId Parent
Definition: ASTDiff.cpp:191
StringRef P
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
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4338
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:2848
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:1487
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1542
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:1733
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4120
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
Represents a list-initialization with parenthesis.
Definition: ExprCXX.h:4956
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:2177
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:3102
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
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4499
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:86
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3468
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:3844
An expression trait intrinsic.
Definition: ExprCXX.h:2919
RoundingMode getRoundingMode() const
Definition: LangOptions.h:849
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:1950
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4722
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3172
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition: ExprObjC.h:87
ObjCBoxedExpr - used for generalized expression boxing.
Definition: ExprObjC.h:127
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:410
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition: ExprObjC.h:51
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:940
Represents a struct/union/class.
Definition: Decl.h:4170
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5565
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition: Expr.h:6909
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:510
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4431
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4252
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:4478
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2763
bool isAnyComplexType() const
Definition: Type.h:7727
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8143
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
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
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
bool VisitAddrLabelExpr(const AddrLabelExpr *E)
std::optional< unsigned > allocateLocal(DeclTy &&Decl, const ValueDecl *ExtendingDecl=nullptr)
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 VisitObjCStringLiteral(const ObjCStringLiteral *E)
bool VisitComplexBinOp(const BinaryOperator *E)
bool VisitCXXThrowExpr(const CXXThrowExpr *E)
bool VisitConvertVectorExpr(const ConvertVectorExpr *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 VisitObjCBoxedExpr(const ObjCBoxedExpr *E)
bool VisitParenExpr(const ParenExpr *E)
bool Initializing
Flag inidicating if we're initializing an already created variable.
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *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 visitAPValueInitializer(const APValue &Val, const Expr *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 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 VisitObjCEncodeExpr(const ObjCEncodeExpr *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)
bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *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 visitInitList(ArrayRef< const Expr * > Inits, const Expr *ArrayFiller, const Expr *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 visitDeclRef(const ValueDecl *D, const Expr *E)
Visit the given decl as if we have a reference to it.
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)
bool VisitRecoveryExpr(const RecoveryExpr *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:120
std::optional< PrimType > classify(QualType T) const
Classifies a type.
Definition: Context.cpp:122
Scope used to handle temporaries in toplevel variable declarations.
Emits the destructors of the variables of.
DestructorScope(LocalScope< Emitter > &OtherScope)
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 addExtended(const Scope::Local &Local, const ValueDecl *ExtendingDecl)
void add(const Scope::Local &Local, bool IsExtended)
VariableScope(ByteCodeExprGen< Emitter > *Ctx, const ValueDecl *VD)
VariableScope * Parent
Link to the parent scope.
virtual void addLocal(const Scope::Local &Local)
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:33
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