//===-- Execution.cpp - Implement code to simulate the program ------------===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the actual instruction interpreter.
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "interpreter"
#include "Interpreter.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
#include "llvm/CodeGen/IntrinsicLowering.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Debug.h"
#include <cmath> // For fmod
using namespace llvm;
namespace {
Statistic<> NumDynamicInsts("lli", "Number of dynamic instructions executed");
Interpreter *TheEE = 0;
}
//===----------------------------------------------------------------------===//
// Value Manipulation code
//===----------------------------------------------------------------------===//
static GenericValue executeAddInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeSubInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeMulInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeRemInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeDivInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeAndInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeOrInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeXorInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeSetEQInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeSetNEInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeSetLTInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeSetGTInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeSetLEInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeSetGEInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeShrInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2,
GenericValue Src3);
GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
ExecutionContext &SF) {
switch (CE->getOpcode()) {
case Instruction::Cast:
return executeCastOperation(CE->getOperand(0), CE->getType(), SF);
case Instruction::GetElementPtr:
return executeGEPOperation(CE->getOperand(0), gep_type_begin(CE),
gep_type_end(CE), SF);
case Instruction::Add:
return executeAddInst(getOperandValue(CE->getOperand(0), SF),
getOperandValue(CE->getOperand(1), SF),
CE->getOperand(0)->getType());
case Instruction::Sub: