clang  10.0.0svn
InterpState.h
Go to the documentation of this file.
1 //===--- InterpState.h - Interpreter state for the constexpr VM -*- 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 // Definition of the interpreter state and entry point.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_AST_INTERP_INTERPSTATE_H
14 #define LLVM_CLANG_AST_INTERP_INTERPSTATE_H
15 
16 #include "Context.h"
17 #include "Function.h"
18 #include "InterpStack.h"
19 #include "State.h"
20 #include "clang/AST/APValue.h"
22 #include "clang/AST/Expr.h"
24 
25 namespace clang {
26 namespace interp {
27 class Context;
28 class Function;
29 class InterpStack;
30 class InterpFrame;
31 class SourceMapper;
32 
33 /// Interpreter context.
34 class InterpState final : public State, public SourceMapper {
35 public:
37  SourceMapper *M = nullptr);
38 
39  ~InterpState();
40 
41  // Stack frame accessors.
42  Frame *getSplitFrame() { return Parent.getCurrentFrame(); }
43  Frame *getCurrentFrame() override;
44  unsigned getCallStackDepth() override { return CallStackDepth; }
45  const Frame *getBottomFrame() const override {
46  return Parent.getBottomFrame();
47  }
48 
49  // Acces objects from the walker context.
50  Expr::EvalStatus &getEvalStatus() const override {
51  return Parent.getEvalStatus();
52  }
53  ASTContext &getCtx() const override { return Parent.getCtx(); }
54 
55  // Forward status checks and updates to the walker.
56  bool checkingForUndefinedBehavior() const override {
57  return Parent.checkingForUndefinedBehavior();
58  }
59  bool keepEvaluatingAfterFailure() const override {
60  return Parent.keepEvaluatingAfterFailure();
61  }
62  bool checkingPotentialConstantExpression() const override {
64  }
65  bool noteUndefinedBehavior() override {
66  return Parent.noteUndefinedBehavior();
67  }
68  bool hasActiveDiagnostic() override { return Parent.hasActiveDiagnostic(); }
69  void setActiveDiagnostic(bool Flag) override {
70  Parent.setActiveDiagnostic(Flag);
71  }
72  void setFoldFailureDiagnostic(bool Flag) override {
73  Parent.setFoldFailureDiagnostic(Flag);
74  }
75  bool hasPriorDiagnostic() override { return Parent.hasPriorDiagnostic(); }
76 
77  /// Reports overflow and return true if evaluation should continue.
78  bool reportOverflow(const Expr *E, const llvm::APSInt &Value);
79 
80  /// Deallocates a pointer.
81  void deallocate(Block *B);
82 
83  /// Delegates source mapping to the mapper.
84  SourceInfo getSource(Function *F, CodePtr PC) const override {
85  return M ? M->getSource(F, PC) : F->getSource(PC);
86  }
87 
88 private:
89  /// AST Walker state.
90  State &Parent;
91  /// Dead block chain.
92  DeadBlock *DeadBlocks = nullptr;
93  /// Reference to the offset-source mapping.
94  SourceMapper *M;
95 
96 public:
97  /// Reference to the module containing all bytecode.
99  /// Temporary stack.
101  /// Interpreter Context.
103  /// The current frame.
104  InterpFrame *Current = nullptr;
105  /// Call stack depth.
106  unsigned CallStackDepth;
107 };
108 
109 } // namespace interp
110 } // namespace clang
111 
112 #endif
virtual Expr::EvalStatus & getEvalStatus() const =0
unsigned getCallStackDepth() override
Definition: InterpState.h:44
Descriptor for a dead block.
Definition: Block.h:112
InterpFrame * Current
The current frame.
Definition: InterpState.h:104
bool keepEvaluatingAfterFailure() const override
Definition: InterpState.h:59
Pointer into the code segment.
Definition: Source.h:25
Interface for classes which map locations to sources.
Definition: Source.h:102
Frame storing local variables.
Definition: InterpFrame.h:29
Expr::EvalStatus & getEvalStatus() const override
Definition: InterpState.h:50
constexpr XRayInstrMask Function
Definition: XRayInstr.h:38
SourceInfo getSource(CodePtr PC) const
Returns the source information at a given PC.
Definition: Function.cpp:34
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:81
Holds all information required to evaluate constexpr code in a module.
Definition: Context.h:48
virtual ASTContext & getCtx() const =0
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
bool reportOverflow(const Expr *E, const llvm::APSInt &Value)
Reports overflow and return true if evaluation should continue.
Definition: InterpState.cpp:51
InterpStack & Stk
Temporary stack.
Definition: InterpState.h:100
A memory block, either on the stack or in the heap.
Definition: Block.h:37
ASTContext & getCtx() const override
Definition: InterpState.h:53
virtual bool keepEvaluatingAfterFailure() const =0
virtual bool checkingForUndefinedBehavior() const =0
bool noteUndefinedBehavior() override
Definition: InterpState.h:65
Context & Ctx
Interpreter Context.
Definition: InterpState.h:102
Stack frame storing temporaries and parameters.
Definition: InterpStack.h:22
virtual void setFoldFailureDiagnostic(bool Flag)=0
void setFoldFailureDiagnostic(bool Flag) override
Definition: InterpState.h:72
This represents one expression.
Definition: Expr.h:108
Implements a partial diagnostic which may not be emitted.
virtual bool hasActiveDiagnostic()=0
virtual void setActiveDiagnostic(bool Flag)=0
The program contains and links the bytecode for all functions.
Definition: Program.h:43
virtual SourceInfo getSource(Function *F, CodePtr PC) const =0
Returns source information for a given PC in a function.
bool checkingForUndefinedBehavior() const override
Definition: InterpState.h:56
Base class for stack frames, shared between VM and walker.
Definition: Frame.h:25
virtual Frame * getCurrentFrame()=0
bool hasActiveDiagnostic() override
Definition: InterpState.h:68
virtual bool noteUndefinedBehavior()=0
llvm::APSInt APSInt
Bytecode function.
Definition: Function.h:59
unsigned CallStackDepth
Call stack depth.
Definition: InterpState.h:106
Frame * getCurrentFrame() override
Definition: InterpState.cpp:43
EvalStatus is a struct with detailed info about an evaluation in progress.
Definition: Expr.h:550
SourceInfo getSource(Function *F, CodePtr PC) const override
Delegates source mapping to the mapper.
Definition: InterpState.h:84
Dataflow Directional Tag Classes.
virtual bool checkingPotentialConstantExpression() const =0
InterpState(State &Parent, Program &P, InterpStack &Stk, Context &Ctx, SourceMapper *M=nullptr)
Definition: InterpState.cpp:24
void deallocate(Block *B)
Deallocates a pointer.
Definition: InterpState.cpp:57
Interpreter context.
Definition: InterpState.h:34
virtual bool hasPriorDiagnostic()=0
Program & P
Reference to the module containing all bytecode.
Definition: InterpState.h:98
void setActiveDiagnostic(bool Flag) override
Definition: InterpState.h:69
Interface for the VM to interact with the AST walker's context.
Definition: State.h:55
bool checkingPotentialConstantExpression() const override
Definition: InterpState.h:62
virtual const Frame * getBottomFrame() const =0
bool hasPriorDiagnostic() override
Definition: InterpState.h:75
const Frame * getBottomFrame() const override
Definition: InterpState.h:45