14 #ifndef LLVM_LIB_EXECUTIONENGINE_INTERPRETER_INTERPRETER_H
15 #define LLVM_LIB_EXECUTIONENGINE_INTERPRETER_INTERPRETER_H
23 #include "llvm/Support/DataTypes.h"
28 class IntrinsicLowering;
30 template<
typename T>
class generic_gep_type_iterator;
40 std::vector<void *> Allocations;
48 Allocations = std::move(RHS.Allocations);
57 void add(
void *Mem) { Allocations.push_back(Mem); }
71 std::map<Value *, GenericValue>
Values;
87 Values = std::move(O.Values);
103 std::vector<ExecutionContext> ECStack;
107 std::vector<Function*> AtExitHandlers;
125 std::string *ErrorStr =
nullptr);
133 bool AbortOnFailure =
true)
override {
201 AtExitHandlers.push_back(F);
205 return &(ECStack.back ().VarArgs[0]);
218 void *getPointerToFunction(
Function *
F)
override {
return (
void*)
F; }
220 void initializeExecutionEngine() { }
221 void initializeExternalFunctions();
222 GenericValue getConstantExprValue(ConstantExpr *CE, ExecutionContext &SF);
223 GenericValue getOperandValue(Value *V, ExecutionContext &SF);
224 GenericValue executeTruncInst(Value *SrcVal,
Type *DstTy,
225 ExecutionContext &SF);
226 GenericValue executeSExtInst(Value *SrcVal,
Type *DstTy,
227 ExecutionContext &SF);
228 GenericValue executeZExtInst(Value *SrcVal,
Type *DstTy,
229 ExecutionContext &SF);
230 GenericValue executeFPTruncInst(Value *SrcVal,
Type *DstTy,
231 ExecutionContext &SF);
232 GenericValue executeFPExtInst(Value *SrcVal,
Type *DstTy,
233 ExecutionContext &SF);
234 GenericValue executeFPToUIInst(Value *SrcVal,
Type *DstTy,
235 ExecutionContext &SF);
236 GenericValue executeFPToSIInst(Value *SrcVal,
Type *DstTy,
237 ExecutionContext &SF);
238 GenericValue executeUIToFPInst(Value *SrcVal,
Type *DstTy,
239 ExecutionContext &SF);
240 GenericValue executeSIToFPInst(Value *SrcVal,
Type *DstTy,
241 ExecutionContext &SF);
242 GenericValue executePtrToIntInst(Value *SrcVal,
Type *DstTy,
243 ExecutionContext &SF);
244 GenericValue executeIntToPtrInst(Value *SrcVal,
Type *DstTy,
245 ExecutionContext &SF);
246 GenericValue executeBitCastInst(Value *SrcVal,
Type *DstTy,
247 ExecutionContext &SF);
249 Type *Ty, ExecutionContext &SF);
250 void popStackAndReturnValueToCaller(
Type *RetTy, GenericValue Result);
ExecutionContext & operator=(ExecutionContext &&O)
static ExecutionEngine * create(std::unique_ptr< Module > M, std::string *ErrorStr=nullptr)
Create an interpreter ExecutionEngine.
ReturnInst - Return a value (possibly void), from a function.
void visitVAArgInst(VAArgInst &I)
ExecutionContext(ExecutionContext &&O)
A parsed version of the target data layout string in and methods for querying it. ...
generic_gep_type_iterator gep_type_iterator
std::vector< GenericValue > ValuePlaneTy
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Base class for instruction visitors.
Interpreter(std::unique_ptr< Module > M)
void visitAllocaInst(AllocaInst &I)
void visitStoreInst(StoreInst &I)
void visitTruncInst(TruncInst &I)
void visitFPToUIInst(FPToUIInst &I)
This class represents zero extension of integer types.
void visitGetElementPtrInst(GetElementPtrInst &I)
CallInst - This class represents a function call, abstracting a target machine's calling convention...
BasicBlock::iterator CurInst
AllocaHolder & operator=(AllocaHolder &&RHS)
std::map< Value *, GenericValue > Values
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
void visitExtractElementInst(ExtractElementInst &I)
void visitShl(BinaryOperator &I)
This class represents a sign extension of integer types.
LoadInst - an instruction for reading from memory.
void visitFCmpInst(FCmpInst &I)
void visitCallInst(CallInst &I)
SelectInst - This class represents the LLVM 'select' instruction.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void visitSelectInst(SelectInst &I)
void visitInvokeInst(InvokeInst &I)
void * getPointerToNamedFunction(StringRef Name, bool AbortOnFailure=true) override
getPointerToNamedFunction - This method returns the address of the specified function by using the dl...
This class represents a cast from a pointer to an integer.
void visitInsertElementInst(InsertElementInst &I)
void visitFPTruncInst(FPTruncInst &I)
void visitPHINode(PHINode &PN)
This instruction compares its operands according to the predicate given to the constructor.
This class represents a no-op cast from one type to another.
void callFunction(Function *F, ArrayRef< GenericValue > ArgVals)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void visitInsertValueInst(InsertValueInst &I)
StoreInst - an instruction for storing to memory.
This class represents a cast from floating point to signed integer.
void visitBitCastInst(BitCastInst &I)
This class represents a truncation of integer types.
Local Stack Slot Allocation
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
void visitLShr(BinaryOperator &I)
void visitICmpInst(ICmpInst &I)
InsertElementInst - This instruction inserts a single (scalar) element into a VectorType value...
LLVM Basic Block Representation.
BranchInst - Conditional or Unconditional Branch instruction.
void visitCallSite(CallSite CS)
UnreachableInst - This function has undefined behavior.
IndirectBrInst - Indirect Branch Instruction.
void visitIndirectBrInst(IndirectBrInst &I)
void visitZExtInst(ZExtInst &I)
void exitCalled(GenericValue GV)
This instruction compares its operands according to the predicate given to the constructor.
GenericValue * getFirstVarArg()
void visitExtractValueInst(ExtractValueInst &I)
This class represents a cast from an integer to a pointer.
void visitFPToSIInst(FPToSIInst &I)
void visitIntToPtrInst(IntToPtrInst &I)
void visitFPExtInst(FPExtInst &I)
void visitInstruction(Instruction &I)
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
void visitUnreachableInst(UnreachableInst &I)
static ExecutionEngine *(* InterpCtor)(std::unique_ptr< Module > M, std::string *ErrorStr)
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
void visitShuffleVectorInst(ShuffleVectorInst &I)
std::vector< GenericValue > VarArgs
void visitReturnInst(ReturnInst &I)
void visitSExtInst(SExtInst &I)
This class represents a cast from floating point to unsigned integer.
GenericValue runFunction(Function *F, ArrayRef< GenericValue > ArgValues) override
run - Start execution with the specified function and arguments.
void visitPtrToIntInst(PtrToIntInst &I)
void runAtExitHandlers()
runAtExitHandlers - Run any functions registered by the program's calls to atexit(3), which we intercept and store in AtExitHandlers.
void visitBranchInst(BranchInst &I)
void visitAShr(BinaryOperator &I)
void visitSIToFPInst(SIToFPInst &I)
This class represents a cast unsigned integer to floating point.
void visitBinaryOperator(BinaryOperator &I)
void visitLoadInst(LoadInst &I)
SwitchInst - Multiway switch.
This class represents a cast from signed integer to floating point.
This class represents a truncation of floating point types.
LLVM Value Representation.
void visitUIToFPInst(UIToFPInst &I)
void addAtExitHandler(Function *F)
InvokeInst - Invoke instruction.
GenericValue callExternalFunction(Function *F, ArrayRef< GenericValue > ArgVals)
void visitSwitchInst(SwitchInst &I)
StringRef - Represent a constant reference to a string, i.e.
AllocaHolder(AllocaHolder &&RHS)
This class represents an extension of floating point types.
AllocaInst - an instruction to allocate memory on the stack.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...