#ifndef LLVM_CLANG_AST_INTERP_EVALEMITTER_H
#define LLVM_CLANG_AST_INTERP_EVALEMITTER_H
#include "EvaluationResult.h"
#include "InterpState.h"
#include "PrimType.h"
#include "Source.h"
#include "llvm/Support/Error.h"
namespace clang {
namespace interp {
class Context;
class Function;
class InterpStack;
class Program;
enum Opcode : uint32_t;
class EvalEmitter : public SourceMapper {
public:
using LabelTy = uint32_t;
using AddrTy = uintptr_t;
using Local = Scope::Local;
EvaluationResult interpretExpr(const Expr *E,
bool ConvertResultToRValue = false);
EvaluationResult interpretDecl(const VarDecl *VD, bool CheckFullyInitialized);
void cleanup();
InterpState &getState() { return S; }
protected:
EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk);
virtual ~EvalEmitter();
void emitLabel(LabelTy Label);
LabelTy getLabel();
virtual bool visitExpr(const Expr *E) = 0;
virtual bool visitDeclAndReturn(const VarDecl *VD, bool ConstantContext) = 0;
virtual bool visitFunc(const FunctionDecl *F) = 0;
bool jumpTrue(const LabelTy &Label);
bool jumpFalse(const LabelTy &Label);
bool jump(const LabelTy &Label);
bool fallthrough(const LabelTy &Label);
bool isActive() const { return CurrentLabel == ActiveLabel; }
Local createLocal(Descriptor *D);
SourceInfo getSource(const Function *F, CodePtr PC) const override {
return (F && F->hasBody()) ? F->getSource(PC) : CurrentSource;
}
llvm::DenseMap<const ParmVarDecl *, ParamOffset> Params;
llvm::DenseMap<const ValueDecl *, ParamOffset> LambdaCaptures;
ParamOffset LambdaThisCapture{0, false};
llvm::SmallVector<SmallVector<Local, 8>, 2> Descriptors;
private:
Context &Ctx;
Program &P;
InterpState S;
EvaluationResult EvalResult;
bool ConvertResultToRValue = false;
bool CheckFullyInitialized = false;
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());
}
void updateGlobalTemporaries();
CodePtr OpPC;
SourceInfo CurrentSource;
LabelTy NextLabel = 1;
LabelTy CurrentLabel = 0;
LabelTy ActiveLabel = 0;
protected:
#define GET_EVAL_PROTO
#include "Opcodes.inc"
#undef GET_EVAL_PROTO
};
}
}
#endif