clang  16.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"
23 #include "clang/AST/StmtVisitor.h"
24 #include "clang/Basic/TargetInfo.h"
25 #include "llvm/ADT/Optional.h"
26 
27 namespace clang {
28 class QualType;
29 
30 namespace interp {
31 
32 template <class Emitter> class LocalScope;
33 template <class Emitter> class RecordScope;
34 template <class Emitter> class VariableScope;
35 template <class Emitter> class DeclScope;
36 template <class Emitter> class OptionScope;
37 template <class Emitter> class ArrayIndexScope;
38 
39 /// Compilation context for expressions.
40 template <class Emitter>
41 class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
42  public Emitter {
43 protected:
44  // Aliases for types defined in the emitter.
45  using LabelTy = typename Emitter::LabelTy;
46  using AddrTy = typename Emitter::AddrTy;
47 
48  // Reference to a function generating the pointer of an initialized object.s
49  using InitFnRef = std::function<bool()>;
50 
51  /// Current compilation context.
53  /// Program to link to.
55 
56 public:
57  /// Initializes the compiler and the backend emitter.
58  template <typename... Tys>
59  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
60  : Emitter(Ctx, P, Args...), Ctx(Ctx), P(P) {}
61 
62  // Expression visitors - result returned on interp stack.
63  bool VisitCastExpr(const CastExpr *E);
64  bool VisitIntegerLiteral(const IntegerLiteral *E);
65  bool VisitParenExpr(const ParenExpr *E);
66  bool VisitBinaryOperator(const BinaryOperator *E);
69  bool VisitCallExpr(const CallExpr *E);
74  bool VisitCXXThisExpr(const CXXThisExpr *E);
75  bool VisitUnaryOperator(const UnaryOperator *E);
76  bool VisitDeclRefExpr(const DeclRefExpr *E);
80  bool VisitInitListExpr(const InitListExpr *E);
81  bool VisitConstantExpr(const ConstantExpr *E);
83  bool VisitMemberExpr(const MemberExpr *E);
87  bool VisitStringLiteral(const StringLiteral *E);
90 
91 protected:
92  bool visitExpr(const Expr *E) override;
93  bool visitDecl(const VarDecl *VD) override;
94 
95 protected:
96  /// Emits scope cleanup instructions.
97  void emitCleanup();
98 
99  /// Returns a record type from a record or pointer type.
100  const RecordType *getRecordTy(QualType Ty);
101 
102  /// Returns a record from a record or pointer type.
104  Record *getRecord(const RecordDecl *RD);
105 
106  // Returns a function for the given FunctionDecl.
107  // If the function does not exist yet, it is compiled.
108  const Function *getFunction(const FunctionDecl *FD);
109 
110  /// Returns the size int bits of an integer.
111  unsigned getIntWidth(QualType Ty) {
112  auto &ASTContext = Ctx.getASTContext();
113  return ASTContext.getIntWidth(Ty);
114  }
115 
116  /// Returns the value of CHAR_BIT.
117  unsigned getCharBit() const {
118  auto &ASTContext = Ctx.getASTContext();
120  }
121 
122  /// Classifies a type.
124  return E->isGLValue() ? PT_Ptr : classify(E->getType());
125  }
127  return Ctx.classify(Ty);
128  }
129 
130  /// Checks if a pointer needs adjustment.
131  bool needsAdjust(QualType Ty) const {
132  return true;
133  }
134 
135  /// Classifies a known primitive type
137  if (auto T = classify(Ty)) {
138  return *T;
139  }
140  llvm_unreachable("not a primitive type");
141  }
142 
143  /// Evaluates an expression for side effects and discards the result.
144  bool discard(const Expr *E);
145  /// Evaluates an expression and places result on stack.
146  bool visit(const Expr *E);
147  /// Compiles an initializer.
148  bool visitInitializer(const Expr *E);
149  /// Compiles an array initializer.
150  bool visitArrayInitializer(const Expr *Initializer);
151  /// Compiles a record initializer.
152  bool visitRecordInitializer(const Expr *Initializer);
153 
154  /// Visits an expression and converts it to a boolean.
155  bool visitBool(const Expr *E);
156 
157  /// Visits an initializer for a local.
158  bool visitLocalInitializer(const Expr *Init, unsigned I) {
159  if (!this->emitGetPtrLocal(I, Init))
160  return false;
161 
162  if (!visitInitializer(Init))
163  return false;
164 
165  return this->emitPopPtr(Init);
166  }
167 
168  /// Visits an initializer for a global.
169  bool visitGlobalInitializer(const Expr *Init, unsigned I) {
170  if (!this->emitGetPtrGlobal(I, Init))
171  return false;
172 
173  if (!visitInitializer(Init))
174  return false;
175 
176  return this->emitPopPtr(Init);
177  }
178 
179  /// Visits a delegated initializer.
180  bool visitThisInitializer(const Expr *I) {
181  if (!this->emitThis(I))
182  return false;
183 
184  if (!visitInitializer(I))
185  return false;
186 
187  return this->emitPopPtr(I);
188  }
189 
190  /// Creates a local primitive value.
191  unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsMutable,
192  bool IsExtended = false);
193 
194  /// Allocates a space storing a local given its type.
196  bool IsExtended = false);
197 
198 private:
199  friend class VariableScope<Emitter>;
200  friend class LocalScope<Emitter>;
201  friend class RecordScope<Emitter>;
202  friend class DeclScope<Emitter>;
203  friend class OptionScope<Emitter>;
204  friend class ArrayIndexScope<Emitter>;
205 
206  /// Emits a zero initializer.
207  bool visitZeroInitializer(PrimType T, const Expr *E);
208 
209  enum class DerefKind {
210  /// Value is read and pushed to stack.
211  Read,
212  /// Direct method generates a value which is written. Returns pointer.
213  Write,
214  /// Direct method receives the value, pushes mutated value. Returns pointer.
215  ReadWrite,
216  };
217 
218  /// Method to directly load a value. If the value can be fetched directly,
219  /// the direct handler is called. Otherwise, a pointer is left on the stack
220  /// and the indirect handler is expected to operate on that.
221  bool dereference(const Expr *LV, DerefKind AK,
222  llvm::function_ref<bool(PrimType)> Direct,
223  llvm::function_ref<bool(PrimType)> Indirect);
224  bool dereferenceParam(const Expr *LV, PrimType T, const ParmVarDecl *PD,
225  DerefKind AK,
226  llvm::function_ref<bool(PrimType)> Direct,
227  llvm::function_ref<bool(PrimType)> Indirect);
228  bool dereferenceVar(const Expr *LV, PrimType T, const VarDecl *PD,
229  DerefKind AK, llvm::function_ref<bool(PrimType)> Direct,
230  llvm::function_ref<bool(PrimType)> Indirect);
231 
232  /// Emits an APSInt constant.
233  bool emitConst(const APSInt &Value, const Expr *E);
234  bool emitConst(const APInt &Value, const Expr *E) {
235  return emitConst(static_cast<APSInt>(Value), E);
236  }
237 
238  /// Emits an integer constant.
239  template <typename T> bool emitConst(T Value, const Expr *E);
240 
241  /// Emits the initialized pointer.
242  bool emitInitFn() {
243  assert(InitFn && "missing initializer");
244  return (*InitFn)();
245  }
246 
247  /// Returns the CXXRecordDecl for the type of the given expression,
248  /// or nullptr if no such decl exists.
249  const CXXRecordDecl *getRecordDecl(const Expr *E) const {
250  QualType T = E->getType();
251  if (const auto *RD = T->getPointeeCXXRecordDecl())
252  return RD;
253  return T->getAsCXXRecordDecl();
254  }
255 
256 protected:
257  /// Variable to storage mapping.
258  llvm::DenseMap<const ValueDecl *, Scope::Local> Locals;
259 
260  /// OpaqueValueExpr to location mapping.
261  llvm::DenseMap<const OpaqueValueExpr *, unsigned> OpaqueExprs;
262 
263  /// Current scope.
265 
266  /// Current argument index. Needed to emit ArrayInitIndexExpr.
268 
269  /// Flag indicating if return value is to be discarded.
270  bool DiscardResult = false;
271 
272  /// Expression being initialized.
274 };
275 
276 extern template class ByteCodeExprGen<ByteCodeEmitter>;
277 extern template class ByteCodeExprGen<EvalEmitter>;
278 
279 /// Scope chain managing the variable lifetimes.
280 template <class Emitter> class VariableScope {
281 public:
282  virtual ~VariableScope() { Ctx->VarScope = this->Parent; }
283 
284  void add(const Scope::Local &Local, bool IsExtended) {
285  if (IsExtended)
286  this->addExtended(Local);
287  else
288  this->addLocal(Local);
289  }
290 
291  virtual void addLocal(const Scope::Local &Local) {
292  if (this->Parent)
293  this->Parent->addLocal(Local);
294  }
295 
296  virtual void addExtended(const Scope::Local &Local) {
297  if (this->Parent)
298  this->Parent->addExtended(Local);
299  }
300 
301  virtual void emitDestruction() {}
302 
304 
305 protected:
307  : Ctx(Ctx), Parent(Ctx->VarScope) {
308  Ctx->VarScope = this;
309  }
310 
311  /// ByteCodeExprGen instance.
313  /// Link to the parent scope.
315 };
316 
317 /// Scope for local variables.
318 ///
319 /// When the scope is destroyed, instructions are emitted to tear down
320 /// all variables declared in this scope.
321 template <class Emitter> class LocalScope : public VariableScope<Emitter> {
322 public:
324 
325  ~LocalScope() override { this->emitDestruction(); }
326 
327  void addLocal(const Scope::Local &Local) override {
328  if (!Idx) {
329  Idx = this->Ctx->Descriptors.size();
330  this->Ctx->Descriptors.emplace_back();
331  }
332 
333  this->Ctx->Descriptors[*Idx].emplace_back(Local);
334  }
335 
336  void emitDestruction() override {
337  if (!Idx)
338  return;
339  this->Ctx->emitDestroy(*Idx, SourceInfo{});
340  }
341 
342 protected:
343  /// Index of the scope in the chain.
345 };
346 
347 /// Scope for storage declared in a compound statement.
348 template <class Emitter> class BlockScope final : public LocalScope<Emitter> {
349 public:
351 
352  void addExtended(const Scope::Local &Local) override {
353  llvm_unreachable("Cannot create temporaries in full scopes");
354  }
355 };
356 
357 /// Expression scope which tracks potentially lifetime extended
358 /// temporaries which are hoisted to the parent scope on exit.
359 template <class Emitter> class ExprScope final : public LocalScope<Emitter> {
360 public:
362 
363  void addExtended(const Scope::Local &Local) override {
364  this->Parent->addLocal(Local);
365  }
366 };
367 
368 template <class Emitter> class ArrayIndexScope final {
369 public:
371  OldArrayIndex = Ctx->ArrayIndex;
372  Ctx->ArrayIndex = Index;
373  }
374 
375  ~ArrayIndexScope() { Ctx->ArrayIndex = OldArrayIndex; }
376 
377 private:
379  Optional<uint64_t> OldArrayIndex;
380 };
381 
382 } // namespace interp
383 } // namespace clang
384 
385 #endif
clang::ArrayInitIndexExpr
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5479
clang::SubstNonTypeTemplateParmExpr
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4269
Pointer.h
clang::interp::ByteCodeExprGen::visitBool
bool visitBool(const Expr *E)
Visits an expression and converts it to a boolean.
Definition: ByteCodeExprGen.cpp:593
clang::CXXBoolLiteralExpr
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:721
clang::interp::APInt
llvm::APInt APInt
Definition: Integral.h:27
clang::interp::ByteCodeExprGen::discard
bool discard(const Expr *E)
Evaluates an expression for side effects and discards the result.
Definition: ByteCodeExprGen.cpp:581
clang::interp::OptionScope
Scope used to handle initialization methods.
Definition: ByteCodeExprGen.cpp:44
clang::interp::ByteCodeExprGen::VisitPointerArithBinOp
bool VisitPointerArithBinOp(const BinaryOperator *E)
Perform addition/subtraction of a pointer and an integer or subtraction of two pointers.
Definition: ByteCodeExprGen.cpp:261
clang::interp::ByteCodeExprGen::getIntWidth
unsigned getIntWidth(QualType Ty)
Returns the size int bits of an integer.
Definition: ByteCodeExprGen.h:111
clang::interp::ByteCodeExprGen::OpaqueExprs
llvm::DenseMap< const OpaqueValueExpr *, unsigned > OpaqueExprs
OpaqueValueExpr to location mapping.
Definition: ByteCodeExprGen.h:261
clang::interp::Context::classify
llvm::Optional< PrimType > classify(QualType T) const
Classifies an expression.
Definition: Context.cpp:75
clang::interp::ByteCodeExprGen::VisitImplicitValueInitExpr
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E)
Definition: ByteCodeExprGen.cpp:309
clang::ASTContext::getIntWidth
unsigned getIntWidth(QualType T) const
Definition: ASTContext.cpp:10901
clang::AbstractConditionalOperator
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition: Expr.h:4112
clang::interp::ExprScope
Expression scope which tracks potentially lifetime extended temporaries which are hoisted to the pare...
Definition: ByteCodeExprGen.h:359
clang::interp::ByteCodeExprGen::VisitBinaryOperator
bool VisitBinaryOperator(const BinaryOperator *E)
Definition: ByteCodeExprGen.cpp:173
TargetInfo.h
clang::interp::ByteCodeExprGen::VisitStringLiteral
bool VisitStringLiteral(const StringLiteral *E)
Definition: ByteCodeExprGen.cpp:513
clang::interp::ByteCodeExprGen::visitLocalInitializer
bool visitLocalInitializer(const Expr *Init, unsigned I)
Visits an initializer for a local.
Definition: ByteCodeExprGen.h:158
clang::interp::ByteCodeExprGen::VisitCXXBoolLiteralExpr
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
Definition: ByteCodeExprGen.cpp:1248
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::interp::ByteCodeExprGen::VisitDeclRefExpr
bool VisitDeclRefExpr(const DeclRefExpr *E)
Definition: ByteCodeExprGen.cpp:1360
clang::interp::VariableScope::addExtended
virtual void addExtended(const Scope::Local &Local)
Definition: ByteCodeExprGen.h:296
clang::interp::ByteCodeExprGen::VisitCXXThisExpr
bool VisitCXXThisExpr(const CXXThisExpr *E)
Definition: ByteCodeExprGen.cpp:1266
clang::interp::LocalScope::addLocal
void addLocal(const Scope::Local &Local) override
Definition: ByteCodeExprGen.h:327
clang::interp::ByteCodeExprGen::emitCleanup
void emitCleanup()
Emits scope cleanup instructions.
Definition: ByteCodeExprGen.cpp:1393
Write
@ Write
Definition: CGBuiltin.cpp:7596
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1712
clang::interp::ByteCodeExprGen
Compilation context for expressions.
Definition: ByteCodeExprGen.h:41
clang::interp::ByteCodeExprGen::Ctx
Context & Ctx
Current compilation context.
Definition: ByteCodeExprGen.h:52
clang::interp::ByteCodeExprGen::classify
llvm::Optional< PrimType > classify(QualType Ty) const
Definition: ByteCodeExprGen.h:126
clang::TargetInfo::getCharWidth
unsigned getCharWidth() const
Definition: TargetInfo.h:466
clang::interp::ByteCodeExprGen::VisitCXXMemberCallExpr
bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *E)
Definition: ByteCodeExprGen.cpp:1226
clang::interp::ByteCodeExprGen::P
Program & P
Program to link to.
Definition: ByteCodeExprGen.h:54
clang::InitListExpr
Describes an C or C++ initializer list.
Definition: Expr.h:4796
llvm::Optional< PrimType >
clang::UnaryOperator
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2172
clang::interp::Context
Holds all information required to evaluate constexpr code in a module.
Definition: Context.h:35
clang::interp::ByteCodeExprGen::InitFnRef
std::function< bool()> InitFnRef
Definition: ByteCodeExprGen.h:49
clang::interp::VariableScope::Parent
VariableScope * Parent
Link to the parent scope.
Definition: ByteCodeExprGen.h:314
clang::interp::ByteCodeExprGen::AddrTy
typename Emitter::AddrTy AddrTy
Definition: ByteCodeExprGen.h:46
clang::Expr::isGLValue
bool isGLValue() const
Definition: Expr.h:273
clang::interp::ByteCodeExprGen::classify
llvm::Optional< PrimType > classify(const Expr *E) const
Classifies a type.
Definition: ByteCodeExprGen.h:123
clang::interp::VariableScope
Scope chain managing the variable lifetimes.
Definition: ByteCodeExprGen.h:34
clang::interp::ByteCodeExprGen::VisitOpaqueValueExpr
bool VisitOpaqueValueExpr(const OpaqueValueExpr *E)
Definition: ByteCodeExprGen.cpp:477
clang::interp::ByteCodeExprGen::VisitMemberExpr
bool VisitMemberExpr(const MemberExpr *E)
Definition: ByteCodeExprGen.cpp:440
clang::OpaqueValueExpr
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1144
Decl.h
clang::interp::Scope::Local
Information about a local's storage.
Definition: Function.h:35
clang::interp::RecordScope
Definition: ByteCodeExprGen.h:33
clang::interp::ExprScope::addExtended
void addExtended(const Scope::Local &Local) override
Definition: ByteCodeExprGen.h:363
clang::interp::LocalScope::Idx
Optional< unsigned > Idx
Index of the scope in the chain.
Definition: ByteCodeExprGen.h:344
clang::interp::ByteCodeExprGen::VisitSubstNonTypeTemplateParmExpr
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
Definition: ByteCodeExprGen.cpp:353
clang::IntegerLiteral
Definition: Expr.h:1503
clang::interp::ByteCodeExprGen::ArrayIndex
llvm::Optional< uint64_t > ArrayIndex
Current argument index. Needed to emit ArrayInitIndexExpr.
Definition: ByteCodeExprGen.h:267
clang::UnaryExprOrTypeTraitExpr
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2558
clang::interp::VariableScope::Ctx
ByteCodeExprGen< Emitter > * Ctx
ByteCodeExprGen instance.
Definition: ByteCodeExprGen.h:312
clang::interp::ByteCodeExprGen::allocateLocal
llvm::Optional< unsigned > allocateLocal(DeclTy &&Decl, bool IsExtended=false)
Allocates a space storing a local given its type.
Definition: ByteCodeExprGen.cpp:816
clang::interp::ByteCodeExprGen::allocateLocalPrimitive
unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsMutable, bool IsExtended=false)
Creates a local primitive value.
Definition: ByteCodeExprGen.cpp:802
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4816
clang::interp::LocalScope
Scope for local variables.
Definition: ByteCodeExprGen.h:32
clang::interp::LocalScope::LocalScope
LocalScope(ByteCodeExprGen< Emitter > *Ctx)
Definition: ByteCodeExprGen.h:323
clang::interp::VariableScope::addLocal
virtual void addLocal(const Scope::Local &Local)
Definition: ByteCodeExprGen.h:291
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3812
hlsl::uint64_t
unsigned long uint64_t
Definition: hlsl_basic_types.h:25
clang::interp::ByteCodeExprGen::VisitCXXDefaultInitExpr
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
Definition: ByteCodeExprGen.cpp:1236
clang::interp::VariableScope::add
void add(const Scope::Local &Local, bool IsExtended)
Definition: ByteCodeExprGen.h:284
clang::interp::BlockScope::addExtended
void addExtended(const Scope::Local &Local) override
Definition: ByteCodeExprGen.h:352
clang::interp::LocalScope::emitDestruction
void emitDestruction() override
Definition: ByteCodeExprGen.h:336
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::interp::ByteCodeExprGen::getRecord
Record * getRecord(QualType Ty)
Returns a record from a record or pointer type.
Definition: ByteCodeExprGen.cpp:1089
clang::interp::LocalScope::~LocalScope
~LocalScope() override
Definition: ByteCodeExprGen.h:325
clang::interp::DeclScope
Scope used to handle temporaries in toplevel variable declarations.
Definition: ByteCodeExprGen.cpp:30
clang::interp::BlockScope
Scope for storage declared in a compound statement.
Definition: ByteCodeExprGen.h:348
clang::interp::ByteCodeExprGen::VisitCallExpr
bool VisitCallExpr(const CallExpr *E)
Definition: ByteCodeExprGen.cpp:1173
clang::interp::ByteCodeExprGen::VisitConstantExpr
bool VisitConstantExpr(const ConstantExpr *E)
Definition: ByteCodeExprGen.cpp:359
clang::interp::ByteCodeExprGen::visitThisInitializer
bool visitThisInitializer(const Expr *I)
Visits a delegated initializer.
Definition: ByteCodeExprGen.h:180
clang::interp::PrimType
PrimType
Enumeration of the primitive types of the VM.
Definition: PrimType.h:28
clang::interp::ByteCodeExprGen::visitExpr
bool visitExpr(const Expr *E) override
Definition: ByteCodeExprGen.cpp:1124
clang::interp::VariableScope::getParent
VariableScope * getParent()
Definition: ByteCodeExprGen.h:303
Expr.h
clang::ImplicitValueInitExpr
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5515
clang::interp::ByteCodeExprGen::Locals
llvm::DenseMap< const ValueDecl *, Scope::Local > Locals
Variable to storage mapping.
Definition: ByteCodeExprGen.h:258
bool
#define bool
Definition: stdbool.h:20
clang::interp::ByteCodeExprGen::DiscardResult
bool DiscardResult
Flag indicating if return value is to be discarded.
Definition: ByteCodeExprGen.h:270
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
clang::StringLiteral
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1776
PrimType.h
clang::interp::ByteCodeExprGen::visitRecordInitializer
bool visitRecordInitializer(const Expr *Initializer)
Compiles a record initializer.
Definition: ByteCodeExprGen.cpp:987
clang::interp::ByteCodeExprGen::VisitCXXNullPtrLiteralExpr
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
Definition: ByteCodeExprGen.cpp:1257
clang::interp::SourceInfo
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:68
clang::interp::ByteCodeExprGen::VisitParenExpr
bool VisitParenExpr(const ParenExpr *E)
Definition: ByteCodeExprGen.cpp:168
clang::interp::VariableScope::~VariableScope
virtual ~VariableScope()
Definition: ByteCodeExprGen.h:282
clang::interp::ByteCodeExprGen::classifyPrim
PrimType classifyPrim(QualType Ty) const
Classifies a known primitive type.
Definition: ByteCodeExprGen.h:136
clang::CXXDefaultArgExpr
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1248
clang::interp::ByteCodeExprGen::VisitUnaryExprOrTypeTraitExpr
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
Definition: ByteCodeExprGen.cpp:386
clang::interp::ByteCodeExprGen::needsAdjust
bool needsAdjust(QualType Ty) const
Checks if a pointer needs adjustment.
Definition: ByteCodeExprGen.h:131
clang::interp::ByteCodeExprGen::getRecordTy
const RecordType * getRecordTy(QualType Ty)
Returns a record type from a record or pointer type.
Definition: ByteCodeExprGen.cpp:1081
clang::ConstantExpr
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1041
clang::interp::ByteCodeExprGen::VisitCXXDefaultArgExpr
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
Definition: ByteCodeExprGen.cpp:1242
clang::interp::ByteCodeExprGen::VisitIntegerLiteral
bool VisitIntegerLiteral(const IntegerLiteral *E)
Definition: ByteCodeExprGen.cpp:160
clang::CharacterLiteral
Definition: Expr.h:1593
clang::interp::ByteCodeExprGen::ByteCodeExprGen
ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
Initializes the compiler and the backend emitter.
Definition: ByteCodeExprGen.h:59
Emitter
clang::interp::VariableScope::VariableScope
VariableScope(ByteCodeExprGen< Emitter > *Ctx)
Definition: ByteCodeExprGen.h:306
clang::interp::ByteCodeExprGen::VisitCompoundAssignOperator
bool VisitCompoundAssignOperator(const CompoundAssignOperator *E)
Definition: ByteCodeExprGen.cpp:525
clang::interp::ByteCodeExprGen::visitGlobalInitializer
bool visitGlobalInitializer(const Expr *Init, unsigned I)
Visits an initializer for a global.
Definition: ByteCodeExprGen.h:169
clang::interp::ByteCodeExprGen::VisitUnaryOperator
bool VisitUnaryOperator(const UnaryOperator *E)
Definition: ByteCodeExprGen.cpp:1273
clang::interp::ByteCodeExprGen::getCharBit
unsigned getCharBit() const
Returns the value of CHAR_BIT.
Definition: ByteCodeExprGen.h:117
clang::interp::ByteCodeExprGen::VisitInitListExpr
bool VisitInitListExpr(const InitListExpr *E)
Definition: ByteCodeExprGen.cpp:344
clang::interp::ByteCodeExprGen::InitFn
llvm::Optional< InitFnRef > InitFn
Expression being initialized.
Definition: ByteCodeExprGen.h:273
clang::interp::ByteCodeExprGen::LabelTy
typename Emitter::LabelTy LabelTy
Definition: ByteCodeExprGen.h:45
clang::ParenExpr
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2121
Value
Value
Definition: UninitializedValues.cpp:103
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::interp::ByteCodeExprGen::VarScope
VariableScope< Emitter > * VarScope
Current scope.
Definition: ByteCodeExprGen.h:264
clang::ArraySubscriptExpr
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2654
StmtVisitor.h
clang::CXXNullPtrLiteralExpr
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:766
clang::CompoundAssignOperator
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4059
clang::ConstStmtVisitor
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:193
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:773
clang::interp::ByteCodeExprGen::visitInitializer
bool visitInitializer(const Expr *E)
Compiles an initializer.
Definition: ByteCodeExprGen.cpp:1067
clang::CXXThisExpr
Represents the this expression in C++.
Definition: ExprCXX.h:1149
clang
Definition: CalledOnceCheck.h:17
clang::interp::Function
Bytecode function.
Definition: Function.h:74
clang::interp::ArrayIndexScope::~ArrayIndexScope
~ArrayIndexScope()
Definition: ByteCodeExprGen.h:375
clang::interp::ByteCodeExprGen::VisitAbstractConditionalOperator
bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E)
Definition: ByteCodeExprGen.cpp:482
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
EvalEmitter.h
ByteCodeEmitter.h
clang::interp::ByteCodeExprGen::VisitCastExpr
bool VisitCastExpr(const CastExpr *E)
Definition: ByteCodeExprGen.cpp:91
clang::interp::Context::getASTContext
ASTContext & getASTContext() const
Returns the AST context.
Definition: Context.h:53
clang::MemberExpr
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3169
clang::interp::ArrayIndexScope::ArrayIndexScope
ArrayIndexScope(ByteCodeExprGen< Emitter > *Ctx, uint64_t Index)
Definition: ByteCodeExprGen.h:370
clang::interp::ExprScope::ExprScope
ExprScope(ByteCodeExprGen< Emitter > *Ctx)
Definition: ByteCodeExprGen.h:361
clang::interp::ByteCodeExprGen::visitDecl
bool visitDecl(const VarDecl *VD) override
Definition: ByteCodeExprGen.cpp:1136
clang::interp::DeclTy
unsigned llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition: Descriptor.h:26
Parent
NodeId Parent
Definition: ASTDiff.cpp:190
clang::interp::APSInt
llvm::APSInt APSInt
Definition: Integral.h:28
clang::interp::ByteCodeExprGen::VisitCharacterLiteral
bool VisitCharacterLiteral(const CharacterLiteral *E)
Definition: ByteCodeExprGen.cpp:519
clang::interp::PT_Ptr
@ PT_Ptr
Definition: PrimType.h:38
clang::interp::ByteCodeExprGen::visit
bool visit(const Expr *E)
Evaluates an expression and places result on stack.
Definition: ByteCodeExprGen.cpp:587
clang::interp::Program
The program contains and links the bytecode for all functions.
Definition: Program.h:40
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::interp::ByteCodeExprGen::getFunction
const Function * getFunction(const FunctionDecl *FD)
Definition: ByteCodeExprGen.cpp:1102
clang::CXXDefaultInitExpr
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1325
clang::interp::ByteCodeExprGen::VisitArraySubscriptExpr
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E)
Definition: ByteCodeExprGen.cpp:317
clang::CastExpr
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3480
clang::interp::Record
Structure/Class descriptor.
Definition: Record.h:24
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1232
clang::interp::ByteCodeExprGen::VisitArrayInitIndexExpr
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E)
Definition: ByteCodeExprGen.cpp:467
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1904
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3983
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2810
Record.h
clang::interp::ArrayIndexScope
Definition: ByteCodeExprGen.h:37
clang::CXXMemberCallExpr
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:177
clang::interp::ByteCodeExprGen::visitArrayInitializer
bool visitArrayInitializer(const Expr *Initializer)
Compiles an array initializer.
Definition: ByteCodeExprGen.cpp:849
clang::interp::BlockScope::BlockScope
BlockScope(ByteCodeExprGen< Emitter > *Ctx)
Definition: ByteCodeExprGen.h:350
clang::interp::VariableScope::emitDestruction
virtual void emitDestruction()
Definition: ByteCodeExprGen.h:301