diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/Interp/EvalEmitter.h')
-rw-r--r-- | contrib/llvm-project/clang/lib/AST/Interp/EvalEmitter.h | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/Interp/EvalEmitter.h b/contrib/llvm-project/clang/lib/AST/Interp/EvalEmitter.h index eec2ff8ee753..deb2ebc4e61f 100644 --- a/contrib/llvm-project/clang/lib/AST/Interp/EvalEmitter.h +++ b/contrib/llvm-project/clang/lib/AST/Interp/EvalEmitter.h @@ -13,23 +13,18 @@ #ifndef LLVM_CLANG_AST_INTERP_EVALEMITTER_H #define LLVM_CLANG_AST_INTERP_EVALEMITTER_H -#include "ByteCodeGenError.h" -#include "Context.h" -#include "InterpStack.h" +#include "EvaluationResult.h" #include "InterpState.h" #include "PrimType.h" -#include "Program.h" #include "Source.h" #include "llvm/Support/Error.h" namespace clang { -class FunctionDecl; namespace interp { class Context; class Function; -class InterpState; +class InterpStack; class Program; -class SourceInfo; enum Opcode : uint32_t; /// An emitter which evaluates opcodes as they are emitted. @@ -39,14 +34,16 @@ public: using AddrTy = uintptr_t; using Local = Scope::Local; - llvm::Expected<bool> interpretExpr(const Expr *E); - llvm::Expected<bool> interpretDecl(const VarDecl *VD); + EvaluationResult interpretExpr(const Expr *E); + EvaluationResult interpretDecl(const VarDecl *VD); + + InterpState &getState() { return S; } protected: EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk, APValue &Result); - virtual ~EvalEmitter() {} + virtual ~EvalEmitter(); /// Define a label. void emitLabel(LabelTy Label); @@ -57,10 +54,6 @@ protected: virtual bool visitExpr(const Expr *E) = 0; virtual bool visitDecl(const VarDecl *VD) = 0; - bool bail(const Stmt *S) { return bail(S->getBeginLoc()); } - bool bail(const Decl *D) { return bail(D->getBeginLoc()); } - bool bail(const SourceLocation &Loc); - /// Emits jumps. bool jumpTrue(const LabelTy &Label); bool jumpFalse(const LabelTy &Label); @@ -71,12 +64,16 @@ protected: Local createLocal(Descriptor *D); /// Returns the source location of the current opcode. - SourceInfo getSource(Function *F, CodePtr PC) const override { - return F ? F->getSource(PC) : CurrentSource; + SourceInfo getSource(const Function *F, CodePtr PC) const override { + return (F && F->hasBody()) ? F->getSource(PC) : CurrentSource; } /// Parameter indices. - llvm::DenseMap<const ParmVarDecl *, unsigned> Params; + llvm::DenseMap<const ParmVarDecl *, ParamOffset> Params; + /// Lambda captures. + llvm::DenseMap<const ValueDecl *, ParamOffset> LambdaCaptures; + /// Offset of the This parameter in a lambda record. + unsigned LambdaThisCapture = 0; /// Local descriptors. llvm::SmallVector<SmallVector<Local, 8>, 2> Descriptors; @@ -88,16 +85,20 @@ private: /// Callee evaluation state. InterpState S; /// Location to write the result to. - APValue &Result; + EvaluationResult EvalResult; /// Temporaries which require storage. llvm::DenseMap<unsigned, std::unique_ptr<char[]>> Locals; + Block *getLocal(unsigned Index) const { + auto It = Locals.find(Index); + assert(It != Locals.end() && "Missing local variable"); + return reinterpret_cast<Block *>(It->second.get()); + } + // The emitter always tracks the current instruction and sets OpPC to a token // value which is mapped to the location of the opcode being evaluated. CodePtr OpPC; - /// Location of a failure. - llvm::Optional<SourceLocation> BailLocation; /// Location of the current instruction. SourceInfo CurrentSource; @@ -110,12 +111,7 @@ private: /// Since expressions can only jump forward, predicated execution is /// used to deal with if-else statements. - bool isActive() { return CurrentLabel == ActiveLabel; } - - /// Helper to invoke a method. - bool ExecuteCall(Function *F, Pointer &&This, const SourceInfo &Info); - /// Helper to emit a diagnostic on a missing method. - bool ExecuteNoCall(const FunctionDecl *F, const SourceInfo &Info); + bool isActive() const { return CurrentLabel == ActiveLabel; } protected: #define GET_EVAL_PROTO |