//===-- Execution.cpp - Implement code to simulate the program ------------===//
//
// This file contains the actual instruction interpreter.
//
//===----------------------------------------------------------------------===//
#include "Interpreter.h"
#include "ExecutionAnnotations.h"
#include "llvm/iOther.h"
#include "llvm/iTerminators.h"
#include "llvm/iMemory.h"
#include "llvm/Type.h"
#include "llvm/ConstPoolVals.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Target/TargetData.h"
#include "llvm/GlobalVariable.h"
#include <math.h> // For fmod
#include <signal.h>
#include <setjmp.h>
// Create a TargetData structure to handle memory addressing and size/alignment
// computations
//
static TargetData TD("lli Interpreter");
CachedWriter CW; // Object to accelerate printing of LLVM
sigjmp_buf SignalRecoverBuffer;
static bool InInstruction = false;
extern "C" {
static void SigHandler(int Signal) {
if (InInstruction)
siglongjmp(SignalRecoverBuffer, Signal);
}
}
static void initializeSignalHandlers() {
struct sigaction Action;
Action.sa_handler = SigHandler;
Action.sa_flags = SA_SIGINFO;
sigemptyset(&Action.sa_mask);
sigaction(SIGSEGV, &Action, 0);
sigaction(SIGBUS, &Action, 0);
sigaction(SIGINT, &Action, 0);
sigaction(SIGFPE, &Action, 0);
}
//===----------------------------------------------------------------------===//
// Value Manipulation code
//===----------------------------------------------------------------------===//
static unsigned getOperandSlot(Value *V) {
SlotNumber *SN = (SlotNumber*)V->getAnnotation(SlotNumberAID);
assert(SN && "Operand does not have a slot number annotation!");
return SN->SlotNum;
}
#define GET_CONST_VAL(TY, CLASS) \
case Type::TY##TyID: Result.TY##Val = cast<CLASS>(CPV)->getValue(); break
static GenericValue getOperandValue(Value *V, ExecutionContext &SF) {
if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {
GenericValue Result;
switch (CPV->getType()->getPrimitiveID()) {
GET_CONST_VAL(Bool , ConstPoolBool);
GET_CONST_VAL(UByte , ConstPoolUInt);
GET_CONST_VAL(SByte , ConstPoolSInt);
GET_CONST_VAL(UShort , ConstPoolUInt);
GET_CONST_VAL(Short , ConstPoolSInt);
GET_CONST_VAL(UInt , ConstPoolUInt);
GET_CONST_VAL(Int , ConstPoolSInt);
GET_CONST_VAL(ULong , ConstPoolUInt);
GET_CONST_VAL(Long , ConstPoolSInt);
GET_CONST_VAL(Float , ConstPoolFP);
GET_CONST_VAL(Double , ConstPoolFP);
case Type::PointerTyID:
if <