mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-07 01:38:26 +00:00
For PR950:
Convert signed integer types to signless ones. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32787 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
db8d2bed6a
commit
e49661bdf5
@ -157,7 +157,7 @@ static void *CreateArgv(ExecutionEngine *EE,
|
||||
char *Result = new char[(InputArgv.size()+1)*PtrSize];
|
||||
|
||||
DOUT << "ARGV = " << (void*)Result << "\n";
|
||||
const Type *SBytePtr = PointerType::get(Type::SByteTy);
|
||||
const Type *SBytePtr = PointerType::get(Type::Int8Ty);
|
||||
|
||||
for (unsigned i = 0; i != InputArgv.size(); ++i) {
|
||||
unsigned Size = InputArgv[i].size()+1;
|
||||
@ -228,7 +228,7 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn,
|
||||
const char * const * envp) {
|
||||
std::vector<GenericValue> GVArgs;
|
||||
GenericValue GVArgc;
|
||||
GVArgc.IntVal = argv.size();
|
||||
GVArgc.Int32Val = argv.size();
|
||||
unsigned NumArgs = Fn->getFunctionType()->getNumParams();
|
||||
if (NumArgs) {
|
||||
GVArgs.push_back(GVArgc); // Arg #0 = argc.
|
||||
@ -244,7 +244,7 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn,
|
||||
}
|
||||
}
|
||||
}
|
||||
return runFunction(Fn, GVArgs).IntVal;
|
||||
return runFunction(Fn, GVArgs).Int32Val;
|
||||
}
|
||||
|
||||
/// If possible, create a JIT, unless the caller specifically requests an
|
||||
@ -317,9 +317,9 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
||||
TD->getIndexedOffset(CE->getOperand(0)->getType(), Indexes);
|
||||
|
||||
if (getTargetData()->getPointerSize() == 4)
|
||||
Result.IntVal += Offset;
|
||||
Result.Int32Val += Offset;
|
||||
else
|
||||
Result.LongVal += Offset;
|
||||
Result.Int64Val += Offset;
|
||||
return Result;
|
||||
}
|
||||
case Instruction::Trunc:
|
||||
@ -352,14 +352,10 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
||||
GenericValue GV = getConstantValue(Op);
|
||||
switch (Op->getType()->getTypeID()) {
|
||||
case Type::BoolTyID: return PTOGV((void*)(uintptr_t)GV.BoolVal);
|
||||
case Type::SByteTyID: return PTOGV((void*)( intptr_t)GV.SByteVal);
|
||||
case Type::UByteTyID: return PTOGV((void*)(uintptr_t)GV.UByteVal);
|
||||
case Type::ShortTyID: return PTOGV((void*)( intptr_t)GV.ShortVal);
|
||||
case Type::UShortTyID: return PTOGV((void*)(uintptr_t)GV.UShortVal);
|
||||
case Type::IntTyID: return PTOGV((void*)( intptr_t)GV.IntVal);
|
||||
case Type::UIntTyID: return PTOGV((void*)(uintptr_t)GV.UIntVal);
|
||||
case Type::LongTyID: return PTOGV((void*)( intptr_t)GV.LongVal);
|
||||
case Type::ULongTyID: return PTOGV((void*)(uintptr_t)GV.ULongVal);
|
||||
case Type::Int8TyID: return PTOGV((void*)(uintptr_t)GV.Int8Val);
|
||||
case Type::Int16TyID: return PTOGV((void*)(uintptr_t)GV.Int16Val);
|
||||
case Type::Int32TyID: return PTOGV((void*)(uintptr_t)GV.Int32Val);
|
||||
case Type::Int64TyID: return PTOGV((void*)(uintptr_t)GV.Int64Val);
|
||||
default: assert(0 && "Unknown integral type!");
|
||||
}
|
||||
break;
|
||||
@ -367,25 +363,21 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
||||
case Instruction::Add:
|
||||
switch (CE->getOperand(0)->getType()->getTypeID()) {
|
||||
default: assert(0 && "Bad add type!"); abort();
|
||||
case Type::LongTyID:
|
||||
case Type::ULongTyID:
|
||||
Result.LongVal = getConstantValue(CE->getOperand(0)).LongVal +
|
||||
getConstantValue(CE->getOperand(1)).LongVal;
|
||||
case Type::Int64TyID:
|
||||
Result.Int64Val = getConstantValue(CE->getOperand(0)).Int64Val +
|
||||
getConstantValue(CE->getOperand(1)).Int64Val;
|
||||
break;
|
||||
case Type::IntTyID:
|
||||
case Type::UIntTyID:
|
||||
Result.IntVal = getConstantValue(CE->getOperand(0)).IntVal +
|
||||
getConstantValue(CE->getOperand(1)).IntVal;
|
||||
case Type::Int32TyID:
|
||||
Result.Int32Val = getConstantValue(CE->getOperand(0)).Int32Val +
|
||||
getConstantValue(CE->getOperand(1)).Int32Val;
|
||||
break;
|
||||
case Type::ShortTyID:
|
||||
case Type::UShortTyID:
|
||||
Result.ShortVal = getConstantValue(CE->getOperand(0)).ShortVal +
|
||||
getConstantValue(CE->getOperand(1)).ShortVal;
|
||||
case Type::Int16TyID:
|
||||
Result.Int16Val = getConstantValue(CE->getOperand(0)).Int16Val +
|
||||
getConstantValue(CE->getOperand(1)).Int16Val;
|
||||
break;
|
||||
case Type::SByteTyID:
|
||||
case Type::UByteTyID:
|
||||
Result.SByteVal = getConstantValue(CE->getOperand(0)).SByteVal +
|
||||
getConstantValue(CE->getOperand(1)).SByteVal;
|
||||
case Type::Int8TyID:
|
||||
Result.Int8Val = getConstantValue(CE->getOperand(0)).Int8Val +
|
||||
getConstantValue(CE->getOperand(1)).Int8Val;
|
||||
break;
|
||||
case Type::FloatTyID:
|
||||
Result.FloatVal = getConstantValue(CE->getOperand(0)).FloatVal +
|
||||
@ -407,17 +399,13 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
||||
switch (C->getType()->getTypeID()) {
|
||||
#define GET_CONST_VAL(TY, CTY, CLASS, GETMETH) \
|
||||
case Type::TY##TyID: Result.TY##Val = (CTY)cast<CLASS>(C)->GETMETH(); break
|
||||
GET_CONST_VAL(Bool , bool , ConstantBool, getValue);
|
||||
GET_CONST_VAL(UByte , unsigned char , ConstantInt, getZExtValue);
|
||||
GET_CONST_VAL(SByte , signed char , ConstantInt, getSExtValue);
|
||||
GET_CONST_VAL(UShort , unsigned short, ConstantInt, getZExtValue);
|
||||
GET_CONST_VAL(Short , signed short , ConstantInt, getSExtValue);
|
||||
GET_CONST_VAL(UInt , unsigned int , ConstantInt, getZExtValue);
|
||||
GET_CONST_VAL(Int , signed int , ConstantInt, getSExtValue);
|
||||
GET_CONST_VAL(ULong , uint64_t , ConstantInt, getZExtValue);
|
||||
GET_CONST_VAL(Long , int64_t , ConstantInt, getSExtValue);
|
||||
GET_CONST_VAL(Float , float , ConstantFP, getValue);
|
||||
GET_CONST_VAL(Double , double , ConstantFP, getValue);
|
||||
GET_CONST_VAL(Bool , bool , ConstantBool, getValue);
|
||||
GET_CONST_VAL(Int8 , unsigned char , ConstantInt, getZExtValue);
|
||||
GET_CONST_VAL(Int16 , unsigned short, ConstantInt, getZExtValue);
|
||||
GET_CONST_VAL(Int32 , unsigned int , ConstantInt, getZExtValue);
|
||||
GET_CONST_VAL(Int64 , uint64_t , ConstantInt, getZExtValue);
|
||||
GET_CONST_VAL(Float , float , ConstantFP, getValue);
|
||||
GET_CONST_VAL(Double, double , ConstantFP, getValue);
|
||||
#undef GET_CONST_VAL
|
||||
case Type::PointerTyID:
|
||||
if (isa<ConstantPointerNull>(C))
|
||||
@ -446,33 +434,29 @@ void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
|
||||
if (getTargetData()->isLittleEndian()) {
|
||||
switch (Ty->getTypeID()) {
|
||||
case Type::BoolTyID:
|
||||
case Type::UByteTyID:
|
||||
case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break;
|
||||
case Type::UShortTyID:
|
||||
case Type::ShortTyID: Ptr->Untyped[0] = Val.UShortVal & 255;
|
||||
Ptr->Untyped[1] = (Val.UShortVal >> 8) & 255;
|
||||
case Type::Int8TyID: Ptr->Untyped[0] = Val.Int8Val; break;
|
||||
case Type::Int16TyID: Ptr->Untyped[0] = Val.Int16Val & 255;
|
||||
Ptr->Untyped[1] = (Val.Int16Val >> 8) & 255;
|
||||
break;
|
||||
Store4BytesLittleEndian:
|
||||
case Type::FloatTyID:
|
||||
case Type::UIntTyID:
|
||||
case Type::IntTyID: Ptr->Untyped[0] = Val.UIntVal & 255;
|
||||
Ptr->Untyped[1] = (Val.UIntVal >> 8) & 255;
|
||||
Ptr->Untyped[2] = (Val.UIntVal >> 16) & 255;
|
||||
Ptr->Untyped[3] = (Val.UIntVal >> 24) & 255;
|
||||
case Type::Int32TyID: Ptr->Untyped[0] = Val.Int32Val & 255;
|
||||
Ptr->Untyped[1] = (Val.Int32Val >> 8) & 255;
|
||||
Ptr->Untyped[2] = (Val.Int32Val >> 16) & 255;
|
||||
Ptr->Untyped[3] = (Val.Int32Val >> 24) & 255;
|
||||
break;
|
||||
case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
|
||||
goto Store4BytesLittleEndian;
|
||||
case Type::DoubleTyID:
|
||||
case Type::ULongTyID:
|
||||
case Type::LongTyID:
|
||||
Ptr->Untyped[0] = (unsigned char)(Val.ULongVal );
|
||||
Ptr->Untyped[1] = (unsigned char)(Val.ULongVal >> 8);
|
||||
Ptr->Untyped[2] = (unsigned char)(Val.ULongVal >> 16);
|
||||
Ptr->Untyped[3] = (unsigned char)(Val.ULongVal >> 24);
|
||||
Ptr->Untyped[4] = (unsigned char)(Val.ULongVal >> 32);
|
||||
Ptr->Untyped[5] = (unsigned char)(Val.ULongVal >> 40);
|
||||
Ptr->Untyped[6] = (unsigned char)(Val.ULongVal >> 48);
|
||||
Ptr->Untyped[7] = (unsigned char)(Val.ULongVal >> 56);
|
||||
case Type::Int64TyID:
|
||||
Ptr->Untyped[0] = (unsigned char)(Val.Int64Val );
|
||||
Ptr->Untyped[1] = (unsigned char)(Val.Int64Val >> 8);
|
||||
Ptr->Untyped[2] = (unsigned char)(Val.Int64Val >> 16);
|
||||
Ptr->Untyped[3] = (unsigned char)(Val.Int64Val >> 24);
|
||||
Ptr->Untyped[4] = (unsigned char)(Val.Int64Val >> 32);
|
||||
Ptr->Untyped[5] = (unsigned char)(Val.Int64Val >> 40);
|
||||
Ptr->Untyped[6] = (unsigned char)(Val.Int64Val >> 48);
|
||||
Ptr->Untyped[7] = (unsigned char)(Val.Int64Val >> 56);
|
||||
break;
|
||||
default:
|
||||
cerr << "Cannot store value of type " << *Ty << "!\n";
|
||||
@ -480,33 +464,29 @@ void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
|
||||
} else {
|
||||
switch (Ty->getTypeID()) {
|
||||
case Type::BoolTyID:
|
||||
case Type::UByteTyID:
|
||||
case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break;
|
||||
case Type::UShortTyID:
|
||||
case Type::ShortTyID: Ptr->Untyped[1] = Val.UShortVal & 255;
|
||||
Ptr->Untyped[0] = (Val.UShortVal >> 8) & 255;
|
||||
case Type::Int8TyID: Ptr->Untyped[0] = Val.Int8Val; break;
|
||||
case Type::Int16TyID: Ptr->Untyped[1] = Val.Int16Val & 255;
|
||||
Ptr->Untyped[0] = (Val.Int16Val >> 8) & 255;
|
||||
break;
|
||||
Store4BytesBigEndian:
|
||||
case Type::FloatTyID:
|
||||
case Type::UIntTyID:
|
||||
case Type::IntTyID: Ptr->Untyped[3] = Val.UIntVal & 255;
|
||||
Ptr->Untyped[2] = (Val.UIntVal >> 8) & 255;
|
||||
Ptr->Untyped[1] = (Val.UIntVal >> 16) & 255;
|
||||
Ptr->Untyped[0] = (Val.UIntVal >> 24) & 255;
|
||||
case Type::Int32TyID: Ptr->Untyped[3] = Val.Int32Val & 255;
|
||||
Ptr->Untyped[2] = (Val.Int32Val >> 8) & 255;
|
||||
Ptr->Untyped[1] = (Val.Int32Val >> 16) & 255;
|
||||
Ptr->Untyped[0] = (Val.Int32Val >> 24) & 255;
|
||||
break;
|
||||
case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
|
||||
goto Store4BytesBigEndian;
|
||||
case Type::DoubleTyID:
|
||||
case Type::ULongTyID:
|
||||
case Type::LongTyID:
|
||||
Ptr->Untyped[7] = (unsigned char)(Val.ULongVal );
|
||||
Ptr->Untyped[6] = (unsigned char)(Val.ULongVal >> 8);
|
||||
Ptr->Untyped[5] = (unsigned char)(Val.ULongVal >> 16);
|
||||
Ptr->Untyped[4] = (unsigned char)(Val.ULongVal >> 24);
|
||||
Ptr->Untyped[3] = (unsigned char)(Val.ULongVal >> 32);
|
||||
Ptr->Untyped[2] = (unsigned char)(Val.ULongVal >> 40);
|
||||
Ptr->Untyped[1] = (unsigned char)(Val.ULongVal >> 48);
|
||||
Ptr->Untyped[0] = (unsigned char)(Val.ULongVal >> 56);
|
||||
case Type::Int64TyID:
|
||||
Ptr->Untyped[7] = (unsigned char)(Val.Int64Val );
|
||||
Ptr->Untyped[6] = (unsigned char)(Val.Int64Val >> 8);
|
||||
Ptr->Untyped[5] = (unsigned char)(Val.Int64Val >> 16);
|
||||
Ptr->Untyped[4] = (unsigned char)(Val.Int64Val >> 24);
|
||||
Ptr->Untyped[3] = (unsigned char)(Val.Int64Val >> 32);
|
||||
Ptr->Untyped[2] = (unsigned char)(Val.Int64Val >> 40);
|
||||
Ptr->Untyped[1] = (unsigned char)(Val.Int64Val >> 48);
|
||||
Ptr->Untyped[0] = (unsigned char)(Val.Int64Val >> 56);
|
||||
break;
|
||||
default:
|
||||
cerr << "Cannot store value of type " << *Ty << "!\n";
|
||||
@ -522,16 +502,13 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr,
|
||||
if (getTargetData()->isLittleEndian()) {
|
||||
switch (Ty->getTypeID()) {
|
||||
case Type::BoolTyID:
|
||||
case Type::UByteTyID:
|
||||
case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break;
|
||||
case Type::UShortTyID:
|
||||
case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[0] |
|
||||
case Type::Int8TyID: Result.Int8Val = Ptr->Untyped[0]; break;
|
||||
case Type::Int16TyID: Result.Int16Val = (unsigned)Ptr->Untyped[0] |
|
||||
((unsigned)Ptr->Untyped[1] << 8);
|
||||
break;
|
||||
Load4BytesLittleEndian:
|
||||
case Type::FloatTyID:
|
||||
case Type::UIntTyID:
|
||||
case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[0] |
|
||||
case Type::Int32TyID: Result.Int32Val = (unsigned)Ptr->Untyped[0] |
|
||||
((unsigned)Ptr->Untyped[1] << 8) |
|
||||
((unsigned)Ptr->Untyped[2] << 16) |
|
||||
((unsigned)Ptr->Untyped[3] << 24);
|
||||
@ -539,8 +516,7 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr,
|
||||
case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
|
||||
goto Load4BytesLittleEndian;
|
||||
case Type::DoubleTyID:
|
||||
case Type::ULongTyID:
|
||||
case Type::LongTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[0] |
|
||||
case Type::Int64TyID: Result.Int64Val = (uint64_t)Ptr->Untyped[0] |
|
||||
((uint64_t)Ptr->Untyped[1] << 8) |
|
||||
((uint64_t)Ptr->Untyped[2] << 16) |
|
||||
((uint64_t)Ptr->Untyped[3] << 24) |
|
||||
@ -556,16 +532,13 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr,
|
||||
} else {
|
||||
switch (Ty->getTypeID()) {
|
||||
case Type::BoolTyID:
|
||||
case Type::UByteTyID:
|
||||
case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break;
|
||||
case Type::UShortTyID:
|
||||
case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[1] |
|
||||
((unsigned)Ptr->Untyped[0] << 8);
|
||||
case Type::Int8TyID: Result.Int8Val = Ptr->Untyped[0]; break;
|
||||
case Type::Int16TyID: Result.Int16Val = (unsigned)Ptr->Untyped[1] |
|
||||
((unsigned)Ptr->Untyped[0] << 8);
|
||||
break;
|
||||
Load4BytesBigEndian:
|
||||
case Type::FloatTyID:
|
||||
case Type::UIntTyID:
|
||||
case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[3] |
|
||||
case Type::Int32TyID: Result.Int32Val =(unsigned)Ptr->Untyped[3] |
|
||||
((unsigned)Ptr->Untyped[2] << 8) |
|
||||
((unsigned)Ptr->Untyped[1] << 16) |
|
||||
((unsigned)Ptr->Untyped[0] << 24);
|
||||
@ -573,8 +546,7 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr,
|
||||
case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
|
||||
goto Load4BytesBigEndian;
|
||||
case Type::DoubleTyID:
|
||||
case Type::ULongTyID:
|
||||
case Type::LongTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[7] |
|
||||
case Type::Int64TyID: Result.Int64Val = (uint64_t)Ptr->Untyped[7] |
|
||||
((uint64_t)Ptr->Untyped[6] << 8) |
|
||||
((uint64_t)Ptr->Untyped[5] << 16) |
|
||||
((uint64_t)Ptr->Untyped[4] << 24) |
|
||||
|
@ -194,14 +194,10 @@ static GenericValue executeAddInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_BINARY_OPERATOR(+, UByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, SByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, UShort);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, Short);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, UInt);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, Int);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, ULong);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, Long);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, Int8);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, Int16);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, Int32);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, Int64);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, Float);
|
||||
IMPLEMENT_BINARY_OPERATOR(+, Double);
|
||||
default:
|
||||
@ -215,14 +211,10 @@ static GenericValue executeSubInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_BINARY_OPERATOR(-, UByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, SByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, UShort);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, Short);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, UInt);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, Int);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, ULong);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, Long);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, Int8);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, Int16);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, Int32);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, Int64);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, Float);
|
||||
IMPLEMENT_BINARY_OPERATOR(-, Double);
|
||||
default:
|
||||
@ -236,14 +228,10 @@ static GenericValue executeMulInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_BINARY_OPERATOR(*, UByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, SByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, UShort);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, Short);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, UInt);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, Int);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, ULong);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, Long);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, Int8);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, Int16);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, Int32);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, Int64);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, Float);
|
||||
IMPLEMENT_BINARY_OPERATOR(*, Double);
|
||||
default:
|
||||
@ -253,17 +241,18 @@ static GenericValue executeMulInst(GenericValue Src1, GenericValue Src2,
|
||||
return Dest;
|
||||
}
|
||||
|
||||
#define IMPLEMENT_SIGNLESS_BINOP(OP, TY1, TY2) \
|
||||
case Type::TY2##TyID: IMPLEMENT_BINARY_OPERATOR(OP, TY1)
|
||||
#define IMPLEMENT_SIGNLESS_BINOP(OP, TY, CAST) \
|
||||
case Type::TY##TyID: Dest.TY##Val = \
|
||||
((CAST)Src1.TY##Val) OP ((CAST)Src2.TY##Val); break
|
||||
|
||||
static GenericValue executeUDivInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, UByte, SByte);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, UShort, Short);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, UInt, Int);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, ULong, Long);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Int8, uint8_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Int16, uint16_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Int32, uint32_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Int64, uint64_t);
|
||||
default:
|
||||
cerr << "Unhandled type for UDiv instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -275,10 +264,10 @@ static GenericValue executeSDivInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, SByte, UByte);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Short, UShort);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Int, UInt);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Long, ULong);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Int8, int8_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Int16, int16_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Int32, int32_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(/, Int64, int64_t);
|
||||
default:
|
||||
cerr << "Unhandled type for SDiv instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -303,10 +292,10 @@ static GenericValue executeURemInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, UByte, SByte);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, UShort, Short);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, UInt, Int);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, ULong, Long);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Int8, uint8_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Int16, uint16_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Int32, uint32_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Int64, uint64_t );
|
||||
default:
|
||||
cerr << "Unhandled type for URem instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -318,10 +307,10 @@ static GenericValue executeSRemInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, SByte, UByte);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Short, UShort);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Int, UInt);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Long, ULong);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Int8, int8_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Int16, int16_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Int32, int32_t);
|
||||
IMPLEMENT_SIGNLESS_BINOP(%, Int64, int64_t);
|
||||
default:
|
||||
cerr << "Unhandled type for Rem instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -351,14 +340,10 @@ static GenericValue executeAndInst(GenericValue Src1, GenericValue Src2,
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_BINARY_OPERATOR(&, Bool);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, UByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, SByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, UShort);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, Short);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, UInt);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, Int);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, ULong);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, Long);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, Int8);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, Int16);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, Int32);
|
||||
IMPLEMENT_BINARY_OPERATOR(&, Int64);
|
||||
default:
|
||||
cerr << "Unhandled type for And instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -371,14 +356,10 @@ static GenericValue executeOrInst(GenericValue Src1, GenericValue Src2,
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_BINARY_OPERATOR(|, Bool);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, UByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, SByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, UShort);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, Short);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, UInt);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, Int);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, ULong);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, Long);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, Int8);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, Int16);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, Int32);
|
||||
IMPLEMENT_BINARY_OPERATOR(|, Int64);
|
||||
default:
|
||||
cerr << "Unhandled type for Or instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -391,14 +372,10 @@ static GenericValue executeXorInst(GenericValue Src1, GenericValue Src2,
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_BINARY_OPERATOR(^, Bool);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, UByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, SByte);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, UShort);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, Short);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, UInt);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, Int);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, ULong);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, Long);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, Int8);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, Int16);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, Int32);
|
||||
IMPLEMENT_BINARY_OPERATOR(^, Int64);
|
||||
default:
|
||||
cerr << "Unhandled type for Xor instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -406,8 +383,9 @@ static GenericValue executeXorInst(GenericValue Src1, GenericValue Src2,
|
||||
return Dest;
|
||||
}
|
||||
|
||||
#define IMPLEMENT_CMP(OP, TY1, TY2) \
|
||||
case Type::TY1##TyID: Dest.BoolVal = Src1.TY2##Val OP Src2.TY2##Val; break
|
||||
#define IMPLEMENT_ICMP(OP, TY, CAST) \
|
||||
case Type::TY##TyID: Dest.BoolVal = \
|
||||
((CAST)Src1.TY##Val) OP ((CAST)Src2.TY##Val); break
|
||||
|
||||
// Handle pointers specially because they must be compared with only as much
|
||||
// width as the host has. We _do not_ want to be comparing 64 bit values when
|
||||
@ -422,14 +400,10 @@ static GenericValue executeICMP_EQ(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(==, UByte, UByte);
|
||||
IMPLEMENT_CMP(==, SByte, SByte);
|
||||
IMPLEMENT_CMP(==, UShort, UShort);
|
||||
IMPLEMENT_CMP(==, Short, Short);
|
||||
IMPLEMENT_CMP(==, UInt, UInt);
|
||||
IMPLEMENT_CMP(==, Int, Int);
|
||||
IMPLEMENT_CMP(==, ULong, ULong);
|
||||
IMPLEMENT_CMP(==, Long, Long);
|
||||
IMPLEMENT_ICMP(==, Int8, uint8_t);
|
||||
IMPLEMENT_ICMP(==, Int16, uint16_t);
|
||||
IMPLEMENT_ICMP(==, Int32, uint32_t);
|
||||
IMPLEMENT_ICMP(==, Int64, uint64_t);
|
||||
IMPLEMENT_POINTERCMP(==);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_EQ predicate: " << *Ty << "\n";
|
||||
@ -442,14 +416,10 @@ static GenericValue executeICMP_NE(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(!=, UByte, UByte);
|
||||
IMPLEMENT_CMP(!=, SByte, SByte);
|
||||
IMPLEMENT_CMP(!=, UShort,UShort);
|
||||
IMPLEMENT_CMP(!=, Short, Short);
|
||||
IMPLEMENT_CMP(!=, UInt, UInt);
|
||||
IMPLEMENT_CMP(!=, Int, Int);
|
||||
IMPLEMENT_CMP(!=, ULong, ULong);
|
||||
IMPLEMENT_CMP(!=, Long, Long);
|
||||
IMPLEMENT_ICMP(!=, Int8, uint8_t);
|
||||
IMPLEMENT_ICMP(!=, Int16, uint16_t);
|
||||
IMPLEMENT_ICMP(!=, Int32, uint32_t);
|
||||
IMPLEMENT_ICMP(!=, Int64, uint64_t);
|
||||
IMPLEMENT_POINTERCMP(!=);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_NE predicate: " << *Ty << "\n";
|
||||
@ -462,14 +432,10 @@ static GenericValue executeICMP_ULT(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(<, SByte, UByte);
|
||||
IMPLEMENT_CMP(<, Short, UShort);
|
||||
IMPLEMENT_CMP(<, Int, UInt);
|
||||
IMPLEMENT_CMP(<, Long, ULong);
|
||||
IMPLEMENT_CMP(<, UByte, UByte);
|
||||
IMPLEMENT_CMP(<, UShort, UShort);
|
||||
IMPLEMENT_CMP(<, UInt, UInt);
|
||||
IMPLEMENT_CMP(<, ULong, ULong);
|
||||
IMPLEMENT_ICMP(<, Int8, uint8_t);
|
||||
IMPLEMENT_ICMP(<, Int16, uint16_t);
|
||||
IMPLEMENT_ICMP(<, Int32, uint32_t);
|
||||
IMPLEMENT_ICMP(<, Int64, uint64_t);
|
||||
IMPLEMENT_POINTERCMP(<);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_ULT predicate: " << *Ty << "\n";
|
||||
@ -482,14 +448,10 @@ static GenericValue executeICMP_SLT(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(<, SByte, SByte);
|
||||
IMPLEMENT_CMP(<, Short, Short);
|
||||
IMPLEMENT_CMP(<, Int, Int);
|
||||
IMPLEMENT_CMP(<, Long, Long);
|
||||
IMPLEMENT_CMP(<, UByte, SByte);
|
||||
IMPLEMENT_CMP(<, UShort, Short);
|
||||
IMPLEMENT_CMP(<, UInt, Int);
|
||||
IMPLEMENT_CMP(<, ULong, Long);
|
||||
IMPLEMENT_ICMP(<, Int8, int8_t);
|
||||
IMPLEMENT_ICMP(<, Int16, int16_t);
|
||||
IMPLEMENT_ICMP(<, Int32, int32_t);
|
||||
IMPLEMENT_ICMP(<, Int64, int64_t);
|
||||
IMPLEMENT_POINTERCMP(<);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_SLT predicate: " << *Ty << "\n";
|
||||
@ -502,14 +464,10 @@ static GenericValue executeICMP_UGT(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(>, SByte, UByte);
|
||||
IMPLEMENT_CMP(>, Short, UShort);
|
||||
IMPLEMENT_CMP(>, Int, UInt);
|
||||
IMPLEMENT_CMP(>, Long, ULong);
|
||||
IMPLEMENT_CMP(>, UByte, UByte);
|
||||
IMPLEMENT_CMP(>, UShort, UShort);
|
||||
IMPLEMENT_CMP(>, UInt, UInt);
|
||||
IMPLEMENT_CMP(>, ULong, ULong);
|
||||
IMPLEMENT_ICMP(>, Int8, uint8_t);
|
||||
IMPLEMENT_ICMP(>, Int16, uint16_t);
|
||||
IMPLEMENT_ICMP(>, Int32, uint32_t);
|
||||
IMPLEMENT_ICMP(>, Int64, uint64_t);
|
||||
IMPLEMENT_POINTERCMP(>);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_UGT predicate: " << *Ty << "\n";
|
||||
@ -522,14 +480,10 @@ static GenericValue executeICMP_SGT(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(>, SByte, SByte);
|
||||
IMPLEMENT_CMP(>, Short, Short);
|
||||
IMPLEMENT_CMP(>, Int, Int);
|
||||
IMPLEMENT_CMP(>, Long, Long);
|
||||
IMPLEMENT_CMP(>, UByte, SByte);
|
||||
IMPLEMENT_CMP(>, UShort, Short);
|
||||
IMPLEMENT_CMP(>, UInt, Int);
|
||||
IMPLEMENT_CMP(>, ULong, Long);
|
||||
IMPLEMENT_ICMP(>, Int8, int8_t);
|
||||
IMPLEMENT_ICMP(>, Int16, int16_t);
|
||||
IMPLEMENT_ICMP(>, Int32, int32_t);
|
||||
IMPLEMENT_ICMP(>, Int64, int64_t);
|
||||
IMPLEMENT_POINTERCMP(>);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_SGT predicate: " << *Ty << "\n";
|
||||
@ -542,14 +496,10 @@ static GenericValue executeICMP_ULE(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(<=, SByte, UByte);
|
||||
IMPLEMENT_CMP(<=, Short, UShort);
|
||||
IMPLEMENT_CMP(<=, Int, UInt);
|
||||
IMPLEMENT_CMP(<=, Long, ULong);
|
||||
IMPLEMENT_CMP(<=, UByte, UByte);
|
||||
IMPLEMENT_CMP(<=, UShort, UShort);
|
||||
IMPLEMENT_CMP(<=, UInt, UInt);
|
||||
IMPLEMENT_CMP(<=, ULong, ULong);
|
||||
IMPLEMENT_ICMP(<=, Int8, uint8_t);
|
||||
IMPLEMENT_ICMP(<=, Int16, uint16_t);
|
||||
IMPLEMENT_ICMP(<=, Int32, uint32_t);
|
||||
IMPLEMENT_ICMP(<=, Int64, uint64_t);
|
||||
IMPLEMENT_POINTERCMP(<=);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_ULE predicate: " << *Ty << "\n";
|
||||
@ -562,14 +512,10 @@ static GenericValue executeICMP_SLE(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(<=, SByte, SByte);
|
||||
IMPLEMENT_CMP(<=, Short, Short);
|
||||
IMPLEMENT_CMP(<=, Int, Int);
|
||||
IMPLEMENT_CMP(<=, Long, Long);
|
||||
IMPLEMENT_CMP(<=, UByte, SByte);
|
||||
IMPLEMENT_CMP(<=, UShort, Short);
|
||||
IMPLEMENT_CMP(<=, UInt, Int);
|
||||
IMPLEMENT_CMP(<=, ULong, Long);
|
||||
IMPLEMENT_ICMP(<=, Int8, int8_t);
|
||||
IMPLEMENT_ICMP(<=, Int16, int16_t);
|
||||
IMPLEMENT_ICMP(<=, Int32, int32_t);
|
||||
IMPLEMENT_ICMP(<=, Int64, int64_t);
|
||||
IMPLEMENT_POINTERCMP(<=);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_SLE predicate: " << *Ty << "\n";
|
||||
@ -582,14 +528,10 @@ static GenericValue executeICMP_UGE(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(>=, SByte, UByte);
|
||||
IMPLEMENT_CMP(>=, Short, UShort);
|
||||
IMPLEMENT_CMP(>=, Int, UInt);
|
||||
IMPLEMENT_CMP(>=, Long, ULong);
|
||||
IMPLEMENT_CMP(>=, UByte, UByte);
|
||||
IMPLEMENT_CMP(>=, UShort, UShort);
|
||||
IMPLEMENT_CMP(>=, UInt, UInt);
|
||||
IMPLEMENT_CMP(>=, ULong, ULong);
|
||||
IMPLEMENT_ICMP(>=, Int8, uint8_t);
|
||||
IMPLEMENT_ICMP(>=, Int16, uint16_t);
|
||||
IMPLEMENT_ICMP(>=, Int32, uint32_t);
|
||||
IMPLEMENT_ICMP(>=, Int64, uint64_t);
|
||||
IMPLEMENT_POINTERCMP(>=);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_UGE predicate: " << *Ty << "\n";
|
||||
@ -602,14 +544,10 @@ static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_CMP(>=, SByte, SByte);
|
||||
IMPLEMENT_CMP(>=, Short, Short);
|
||||
IMPLEMENT_CMP(>=, Int, Int);
|
||||
IMPLEMENT_CMP(>=, Long, Long);
|
||||
IMPLEMENT_CMP(>=, UByte, SByte);
|
||||
IMPLEMENT_CMP(>=, UShort, Short);
|
||||
IMPLEMENT_CMP(>=, UInt, Int);
|
||||
IMPLEMENT_CMP(>=, ULong, Long);
|
||||
IMPLEMENT_ICMP(>=, Int8, int8_t);
|
||||
IMPLEMENT_ICMP(>=, Int16, int16_t);
|
||||
IMPLEMENT_ICMP(>=, Int32, int32_t);
|
||||
IMPLEMENT_ICMP(>=, Int64, int64_t);
|
||||
IMPLEMENT_POINTERCMP(>=);
|
||||
default:
|
||||
cerr << "Unhandled type for ICMP_SGE predicate: " << *Ty << "\n";
|
||||
@ -618,15 +556,41 @@ static GenericValue executeICMP_SGE(GenericValue Src1, GenericValue Src2,
|
||||
return Dest;
|
||||
}
|
||||
|
||||
#define IMPLEMENT_SETCC(OP, TY) \
|
||||
void Interpreter::visitICmpInst(ICmpInst &I) {
|
||||
ExecutionContext &SF = ECStack.back();
|
||||
const Type *Ty = I.getOperand(0)->getType();
|
||||
GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
|
||||
GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
|
||||
GenericValue R; // Result
|
||||
|
||||
switch (I.getPredicate()) {
|
||||
case ICmpInst::ICMP_EQ: R = executeICMP_EQ(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_NE: R = executeICMP_NE(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_ULT: R = executeICMP_ULT(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_SLT: R = executeICMP_SLT(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_UGT: R = executeICMP_UGT(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_SGT: R = executeICMP_SGT(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_ULE: R = executeICMP_ULE(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_SLE: R = executeICMP_SLE(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_UGE: R = executeICMP_UGE(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_SGE: R = executeICMP_SGE(Src1, Src2, Ty); break;
|
||||
default:
|
||||
cerr << "Don't know how to handle this ICmp predicate!\n-->" << I;
|
||||
abort();
|
||||
}
|
||||
|
||||
SetValue(&I, R, SF);
|
||||
}
|
||||
|
||||
#define IMPLEMENT_FCMP(OP, TY) \
|
||||
case Type::TY##TyID: Dest.BoolVal = Src1.TY##Val OP Src2.TY##Val; break
|
||||
|
||||
static GenericValue executeFCMP_EQ(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SETCC(==, Float);
|
||||
IMPLEMENT_SETCC(==, Double);
|
||||
IMPLEMENT_FCMP(==, Float);
|
||||
IMPLEMENT_FCMP(==, Double);
|
||||
default:
|
||||
cerr << "Unhandled type for SetEQ instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -638,8 +602,8 @@ static GenericValue executeFCMP_NE(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SETCC(!=, Float);
|
||||
IMPLEMENT_SETCC(!=, Double);
|
||||
IMPLEMENT_FCMP(!=, Float);
|
||||
IMPLEMENT_FCMP(!=, Double);
|
||||
|
||||
default:
|
||||
cerr << "Unhandled type for SetNE instruction: " << *Ty << "\n";
|
||||
@ -652,8 +616,8 @@ static GenericValue executeFCMP_LE(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SETCC(<=, Float);
|
||||
IMPLEMENT_SETCC(<=, Double);
|
||||
IMPLEMENT_FCMP(<=, Float);
|
||||
IMPLEMENT_FCMP(<=, Double);
|
||||
default:
|
||||
cerr << "Unhandled type for SetLE instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -665,8 +629,8 @@ static GenericValue executeFCMP_GE(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SETCC(>=, Float);
|
||||
IMPLEMENT_SETCC(>=, Double);
|
||||
IMPLEMENT_FCMP(>=, Float);
|
||||
IMPLEMENT_FCMP(>=, Double);
|
||||
default:
|
||||
cerr << "Unhandled type for SetGE instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -678,8 +642,8 @@ static GenericValue executeFCMP_LT(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SETCC(<, Float);
|
||||
IMPLEMENT_SETCC(<, Double);
|
||||
IMPLEMENT_FCMP(<, Float);
|
||||
IMPLEMENT_FCMP(<, Double);
|
||||
default:
|
||||
cerr << "Unhandled type for SetLT instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -691,8 +655,8 @@ static GenericValue executeFCMP_GT(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SETCC(>, Float);
|
||||
IMPLEMENT_SETCC(>, Double);
|
||||
IMPLEMENT_FCMP(>, Float);
|
||||
IMPLEMENT_FCMP(>, Double);
|
||||
default:
|
||||
cerr << "Unhandled type for SetGT instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -732,32 +696,6 @@ void Interpreter::visitFCmpInst(FCmpInst &I) {
|
||||
SetValue(&I, R, SF);
|
||||
}
|
||||
|
||||
void Interpreter::visitICmpInst(ICmpInst &I) {
|
||||
ExecutionContext &SF = ECStack.back();
|
||||
const Type *Ty = I.getOperand(0)->getType();
|
||||
GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
|
||||
GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
|
||||
GenericValue R; // Result
|
||||
|
||||
switch (I.getPredicate()) {
|
||||
case ICmpInst::ICMP_EQ: R = executeICMP_EQ(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_NE: R = executeICMP_NE(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_ULT: R = executeICMP_ULT(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_SLT: R = executeICMP_SLT(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_UGT: R = executeICMP_UGT(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_SGT: R = executeICMP_SGT(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_ULE: R = executeICMP_ULE(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_SLE: R = executeICMP_SLE(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_UGE: R = executeICMP_UGE(Src1, Src2, Ty); break;
|
||||
case ICmpInst::ICMP_SGE: R = executeICMP_SGE(Src1, Src2, Ty); break;
|
||||
default:
|
||||
cerr << "Don't know how to handle this ICmp predicate!\n-->" << I;
|
||||
abort();
|
||||
}
|
||||
|
||||
SetValue(&I, R, SF);
|
||||
}
|
||||
|
||||
static GenericValue executeCmpInst(unsigned predicate, GenericValue Src1,
|
||||
GenericValue Src2, const Type *Ty) {
|
||||
GenericValue Result;
|
||||
@ -855,7 +793,7 @@ void Interpreter::exitCalled(GenericValue GV) {
|
||||
// the stack before interpreting atexit handlers.
|
||||
ECStack.clear ();
|
||||
runAtExitHandlers ();
|
||||
exit (GV.IntVal);
|
||||
exit (GV.Int32Val);
|
||||
}
|
||||
|
||||
/// Pop the last stack frame off of ECStack and then copy the result
|
||||
@ -1007,7 +945,7 @@ void Interpreter::visitAllocationInst(AllocationInst &I) {
|
||||
const Type *Ty = I.getType()->getElementType(); // Type to be allocated
|
||||
|
||||
// Get the number of elements being allocated by the array...
|
||||
unsigned NumElements = getOperandValue(I.getOperand(0), SF).UIntVal;
|
||||
unsigned NumElements = getOperandValue(I.getOperand(0), SF).Int32Val;
|
||||
|
||||
// Allocate enough memory to hold the type...
|
||||
void *Memory = malloc(NumElements * (size_t)TD.getTypeSize(Ty));
|
||||
@ -1054,14 +992,10 @@ GenericValue Interpreter::executeGEPOperation(Value *Ptr, gep_type_iterator I,
|
||||
uint64_t Idx;
|
||||
switch (I.getOperand()->getType()->getTypeID()) {
|
||||
default: assert(0 && "Illegal getelementptr index for sequential type!");
|
||||
case Type::SByteTyID: Idx = IdxGV.SByteVal; break;
|
||||
case Type::ShortTyID: Idx = IdxGV.ShortVal; break;
|
||||
case Type::IntTyID: Idx = IdxGV.IntVal; break;
|
||||
case Type::LongTyID: Idx = IdxGV.LongVal; break;
|
||||
case Type::UByteTyID: Idx = IdxGV.UByteVal; break;
|
||||
case Type::UShortTyID: Idx = IdxGV.UShortVal; break;
|
||||
case Type::UIntTyID: Idx = IdxGV.UIntVal; break;
|
||||
case Type::ULongTyID: Idx = IdxGV.ULongVal; break;
|
||||
case Type::Int8TyID: Idx = IdxGV.Int8Val; break;
|
||||
case Type::Int16TyID: Idx = IdxGV.Int16Val; break;
|
||||
case Type::Int32TyID: Idx = IdxGV.Int32Val; break;
|
||||
case Type::Int64TyID: Idx = IdxGV.Int64Val; break;
|
||||
}
|
||||
Total += PointerTy(TD.getTypeSize(ST->getElementType())*Idx);
|
||||
}
|
||||
@ -1151,16 +1085,12 @@ void Interpreter::visitCallSite(CallSite CS) {
|
||||
// source type.
|
||||
const Type *Ty = V->getType();
|
||||
if (Ty->isIntegral() && Ty->getPrimitiveSize() < 4) {
|
||||
if (Ty == Type::ShortTy)
|
||||
ArgVals.back().IntVal = ArgVals.back().ShortVal;
|
||||
else if (Ty == Type::UShortTy)
|
||||
ArgVals.back().UIntVal = ArgVals.back().UShortVal;
|
||||
else if (Ty == Type::SByteTy)
|
||||
ArgVals.back().IntVal = ArgVals.back().SByteVal;
|
||||
else if (Ty == Type::UByteTy)
|
||||
ArgVals.back().UIntVal = ArgVals.back().UByteVal;
|
||||
if (Ty == Type::Int16Ty)
|
||||
ArgVals.back().Int32Val = ArgVals.back().Int16Val;
|
||||
else if (Ty == Type::Int8Ty)
|
||||
ArgVals.back().Int32Val = ArgVals.back().Int8Val;
|
||||
else if (Ty == Type::BoolTy)
|
||||
ArgVals.back().UIntVal = ArgVals.back().BoolVal;
|
||||
ArgVals.back().Int32Val = ArgVals.back().BoolVal;
|
||||
else
|
||||
assert(0 && "Unknown type!");
|
||||
}
|
||||
@ -1173,24 +1103,20 @@ void Interpreter::visitCallSite(CallSite CS) {
|
||||
}
|
||||
|
||||
#define IMPLEMENT_SHIFT(OP, TY) \
|
||||
case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.UByteVal; break
|
||||
case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.Int8Val; break
|
||||
|
||||
#define IMPLEMENT_SIGNLESS_SHIFT(OP, TY1, TY2) \
|
||||
case Type::TY2##TyID: \
|
||||
IMPLEMENT_SHIFT(OP, TY1)
|
||||
#define IMPLEMENT_SIGNLESS_SHIFT(OP, TY, CAST) \
|
||||
case Type::TY##TyID: Dest.TY##Val = ((CAST)Src1.TY##Val) OP Src2.Int8Val; \
|
||||
break
|
||||
|
||||
static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SHIFT(<<, UByte);
|
||||
IMPLEMENT_SHIFT(<<, SByte);
|
||||
IMPLEMENT_SHIFT(<<, UShort);
|
||||
IMPLEMENT_SHIFT(<<, Short);
|
||||
IMPLEMENT_SHIFT(<<, UInt);
|
||||
IMPLEMENT_SHIFT(<<, Int);
|
||||
IMPLEMENT_SHIFT(<<, ULong);
|
||||
IMPLEMENT_SHIFT(<<, Long);
|
||||
IMPLEMENT_SHIFT(<<, Int8);
|
||||
IMPLEMENT_SHIFT(<<, Int16);
|
||||
IMPLEMENT_SHIFT(<<, Int32);
|
||||
IMPLEMENT_SHIFT(<<, Int64);
|
||||
default:
|
||||
cerr << "Unhandled type for Shl instruction: " << *Ty << "\n";
|
||||
}
|
||||
@ -1201,10 +1127,10 @@ static GenericValue executeLShrInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, UByte, SByte);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, UShort, Short);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, UInt, Int);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, ULong, Long);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Int8, uint8_t);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Int16, uint16_t);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Int32, uint32_t);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Int64, uint64_t);
|
||||
default:
|
||||
cerr << "Unhandled type for LShr instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -1216,10 +1142,10 @@ static GenericValue executeAShrInst(GenericValue Src1, GenericValue Src2,
|
||||
const Type *Ty) {
|
||||
GenericValue Dest;
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, SByte, UByte);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Short, UShort);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Int, UInt);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Long, ULong);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Int8, int8_t);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Int16, int16_t);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Int32, int32_t);
|
||||
IMPLEMENT_SIGNLESS_SHIFT(>>, Int64, int64_t);
|
||||
default:
|
||||
cerr << "Unhandled type for AShr instruction: " << *Ty << "\n";
|
||||
abort();
|
||||
@ -1260,24 +1186,20 @@ void Interpreter::visitAShr(ShiftInst &I) {
|
||||
#define IMPLEMENT_CAST_START \
|
||||
switch (DstTy->getTypeID()) {
|
||||
|
||||
#define IMPLEMENT_CAST(DTY, DCTY, STY) \
|
||||
case Type::STY##TyID: Dest.DTY##Val = DCTY Src.STY##Val; break;
|
||||
#define IMPLEMENT_CAST(STY, DTY, CAST) \
|
||||
case Type::STY##TyID: Dest.DTY##Val = (CAST(Src.STY##Val)); break;
|
||||
|
||||
#define IMPLEMENT_CAST_CASE(DESTTY, DESTCTY) \
|
||||
case Type::DESTTY##TyID: \
|
||||
#define IMPLEMENT_CAST_CASE(DTY, CAST) \
|
||||
case Type::DTY##TyID: \
|
||||
switch (SrcTy->getTypeID()) { \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, Bool); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, UByte); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, SByte); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, UShort); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, Short); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, UInt); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, Int); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, ULong); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, Long); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, Pointer); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, Float); \
|
||||
IMPLEMENT_CAST(DESTTY, DESTCTY, Double) \
|
||||
IMPLEMENT_CAST(Bool, DTY, CAST); \
|
||||
IMPLEMENT_CAST(Int8, DTY, CAST); \
|
||||
IMPLEMENT_CAST(Int16, DTY, CAST); \
|
||||
IMPLEMENT_CAST(Int32, DTY, CAST); \
|
||||
IMPLEMENT_CAST(Int64, DTY, CAST); \
|
||||
IMPLEMENT_CAST(Pointer,DTY, CAST); \
|
||||
IMPLEMENT_CAST(Float, DTY, CAST); \
|
||||
IMPLEMENT_CAST(Double, DTY, CAST); \
|
||||
default: \
|
||||
cerr << "Unhandled cast: " \
|
||||
<< *SrcTy << " to " << *DstTy << "\n"; \
|
||||
@ -1301,15 +1223,11 @@ GenericValue Interpreter::executeCastOperation(Instruction::CastOps opcode,
|
||||
if (opcode == Instruction::Trunc && DstTy->getTypeID() == Type::BoolTyID) {
|
||||
// For truncations to bool, we must clear the high order bits of the source
|
||||
switch (SrcTy->getTypeID()) {
|
||||
case Type::BoolTyID: Src.BoolVal &= 1; break;
|
||||
case Type::SByteTyID: Src.SByteVal &= 1; break;
|
||||
case Type::UByteTyID: Src.UByteVal &= 1; break;
|
||||
case Type::ShortTyID: Src.ShortVal &= 1; break;
|
||||
case Type::UShortTyID: Src.UShortVal &= 1; break;
|
||||
case Type::IntTyID: Src.IntVal &= 1; break;
|
||||
case Type::UIntTyID: Src.UIntVal &= 1; break;
|
||||
case Type::LongTyID: Src.LongVal &= 1; break;
|
||||
case Type::ULongTyID: Src.ULongVal &= 1; break;
|
||||
case Type::BoolTyID: Src.BoolVal &= 1; break;
|
||||
case Type::Int8TyID: Src.Int8Val &= 1; break;
|
||||
case Type::Int16TyID: Src.Int16Val &= 1; break;
|
||||
case Type::Int32TyID: Src.Int32Val &= 1; break;
|
||||
case Type::Int64TyID: Src.Int64Val &= 1; break;
|
||||
default:
|
||||
assert(0 && "Can't trunc a non-integer!");
|
||||
break;
|
||||
@ -1317,44 +1235,34 @@ GenericValue Interpreter::executeCastOperation(Instruction::CastOps opcode,
|
||||
} else if (opcode == Instruction::SExt &&
|
||||
SrcTy->getTypeID() == Type::BoolTyID) {
|
||||
// For sign extension from bool, we must extend the source bits.
|
||||
SrcTy = Type::LongTy;
|
||||
Src.LongVal = 0 - Src.BoolVal;
|
||||
SrcTy = Type::Int64Ty;
|
||||
Src.Int64Val = 0 - Src.BoolVal;
|
||||
}
|
||||
|
||||
switch (opcode) {
|
||||
case Instruction::Trunc: // src integer, dest integral (can't be long)
|
||||
IMPLEMENT_CAST_START
|
||||
IMPLEMENT_CAST_CASE(Bool , (bool));
|
||||
IMPLEMENT_CAST_CASE(UByte , (unsigned char));
|
||||
IMPLEMENT_CAST_CASE(SByte , ( signed char));
|
||||
IMPLEMENT_CAST_CASE(UShort , (unsigned short));
|
||||
IMPLEMENT_CAST_CASE(Short , ( signed short));
|
||||
IMPLEMENT_CAST_CASE(UInt , (unsigned int ));
|
||||
IMPLEMENT_CAST_CASE(Int , ( signed int ));
|
||||
IMPLEMENT_CAST_CASE(Bool , (bool));
|
||||
IMPLEMENT_CAST_CASE(Int8 , (uint8_t));
|
||||
IMPLEMENT_CAST_CASE(Int16, (uint16_t));
|
||||
IMPLEMENT_CAST_CASE(Int32, (uint32_t));
|
||||
IMPLEMENT_CAST_CASE(Int64, (uint64_t));
|
||||
IMPLEMENT_CAST_END
|
||||
break;
|
||||
case Instruction::ZExt: // src integral (can't be long), dest integer
|
||||
IMPLEMENT_CAST_START
|
||||
IMPLEMENT_CAST_CASE(UByte , (unsigned char));
|
||||
IMPLEMENT_CAST_CASE(SByte , (signed char)(unsigned char));
|
||||
IMPLEMENT_CAST_CASE(UShort , (unsigned short));
|
||||
IMPLEMENT_CAST_CASE(Short , (signed short)(unsigned short));
|
||||
IMPLEMENT_CAST_CASE(UInt , (unsigned int ));
|
||||
IMPLEMENT_CAST_CASE(Int , (signed int)(unsigned int ));
|
||||
IMPLEMENT_CAST_CASE(ULong , (uint64_t));
|
||||
IMPLEMENT_CAST_CASE(Long , (int64_t)(uint64_t));
|
||||
IMPLEMENT_CAST_CASE(Int8 , (uint8_t));
|
||||
IMPLEMENT_CAST_CASE(Int16, (uint16_t));
|
||||
IMPLEMENT_CAST_CASE(Int32, (uint32_t));
|
||||
IMPLEMENT_CAST_CASE(Int64, (uint64_t));
|
||||
IMPLEMENT_CAST_END
|
||||
break;
|
||||
case Instruction::SExt: // src integral (can't be long), dest integer
|
||||
IMPLEMENT_CAST_START
|
||||
IMPLEMENT_CAST_CASE(UByte , (unsigned char)(signed char));
|
||||
IMPLEMENT_CAST_CASE(SByte , (signed char));
|
||||
IMPLEMENT_CAST_CASE(UShort , (unsigned short)(signed short));
|
||||
IMPLEMENT_CAST_CASE(Short , (signed short));
|
||||
IMPLEMENT_CAST_CASE(UInt , (unsigned int )(signed int));
|
||||
IMPLEMENT_CAST_CASE(Int , (signed int));
|
||||
IMPLEMENT_CAST_CASE(ULong , (uint64_t)(int64_t));
|
||||
IMPLEMENT_CAST_CASE(Long , (int64_t));
|
||||
IMPLEMENT_CAST_CASE(Int8 , (uint8_t)(int8_t));
|
||||
IMPLEMENT_CAST_CASE(Int16, (uint16_t)(int16_t));
|
||||
IMPLEMENT_CAST_CASE(Int32, (uint32_t)(int32_t));
|
||||
IMPLEMENT_CAST_CASE(Int64, (uint64_t)(int64_t));
|
||||
IMPLEMENT_CAST_END
|
||||
break;
|
||||
case Instruction::FPTrunc: // src double, dest float
|
||||
@ -1381,41 +1289,29 @@ GenericValue Interpreter::executeCastOperation(Instruction::CastOps opcode,
|
||||
break;
|
||||
case Instruction::FPToUI: // src floating, dest integral
|
||||
IMPLEMENT_CAST_START
|
||||
IMPLEMENT_CAST_CASE(Bool , (bool));
|
||||
IMPLEMENT_CAST_CASE(UByte , (unsigned char));
|
||||
IMPLEMENT_CAST_CASE(SByte , (signed char)(unsigned char));
|
||||
IMPLEMENT_CAST_CASE(UShort , (unsigned short));
|
||||
IMPLEMENT_CAST_CASE(Short , (signed short)(unsigned short));
|
||||
IMPLEMENT_CAST_CASE(UInt , (unsigned int ));
|
||||
IMPLEMENT_CAST_CASE(Int , (signed int)(unsigned int ));
|
||||
IMPLEMENT_CAST_CASE(ULong , (uint64_t));
|
||||
IMPLEMENT_CAST_CASE(Long , (int64_t)(uint64_t));
|
||||
IMPLEMENT_CAST_CASE(Bool , (bool));
|
||||
IMPLEMENT_CAST_CASE(Int8 , (uint8_t));
|
||||
IMPLEMENT_CAST_CASE(Int16, (uint16_t));
|
||||
IMPLEMENT_CAST_CASE(Int32, (uint32_t ));
|
||||
IMPLEMENT_CAST_CASE(Int64, (uint64_t));
|
||||
IMPLEMENT_CAST_END
|
||||
break;
|
||||
case Instruction::FPToSI: // src floating, dest integral
|
||||
IMPLEMENT_CAST_START
|
||||
IMPLEMENT_CAST_CASE(Bool , (bool));
|
||||
IMPLEMENT_CAST_CASE(UByte , (unsigned char)(signed char));
|
||||
IMPLEMENT_CAST_CASE(SByte , (signed char));
|
||||
IMPLEMENT_CAST_CASE(UShort , (unsigned short)(signed short));
|
||||
IMPLEMENT_CAST_CASE(Short , (signed short));
|
||||
IMPLEMENT_CAST_CASE(UInt , (unsigned int )(signed int));
|
||||
IMPLEMENT_CAST_CASE(Int , (signed int));
|
||||
IMPLEMENT_CAST_CASE(ULong , (uint64_t)(int64_t));
|
||||
IMPLEMENT_CAST_CASE(Long , (int64_t));
|
||||
IMPLEMENT_CAST_CASE(Bool , (bool));
|
||||
IMPLEMENT_CAST_CASE(Int8 , (uint8_t) (int8_t));
|
||||
IMPLEMENT_CAST_CASE(Int16, (uint16_t)(int16_t));
|
||||
IMPLEMENT_CAST_CASE(Int32, (uint32_t)(int32_t));
|
||||
IMPLEMENT_CAST_CASE(Int64, (uint64_t)(int64_t));
|
||||
IMPLEMENT_CAST_END
|
||||
break;
|
||||
case Instruction::PtrToInt: // src pointer, dest integral
|
||||
IMPLEMENT_CAST_START
|
||||
IMPLEMENT_CAST_CASE(Bool , (bool));
|
||||
IMPLEMENT_CAST_CASE(UByte , (unsigned char));
|
||||
IMPLEMENT_CAST_CASE(SByte , (signed char)(unsigned char));
|
||||
IMPLEMENT_CAST_CASE(UShort , (unsigned short));
|
||||
IMPLEMENT_CAST_CASE(Short , (signed short)(unsigned short));
|
||||
IMPLEMENT_CAST_CASE(UInt , (unsigned int));
|
||||
IMPLEMENT_CAST_CASE(Int , (signed int)(unsigned int));
|
||||
IMPLEMENT_CAST_CASE(ULong , (uint64_t));
|
||||
IMPLEMENT_CAST_CASE(Long , (int64_t)(uint64_t));
|
||||
IMPLEMENT_CAST_CASE(Bool , (bool));
|
||||
IMPLEMENT_CAST_CASE(Int8 , (uint8_t));
|
||||
IMPLEMENT_CAST_CASE(Int16, (uint16_t));
|
||||
IMPLEMENT_CAST_CASE(Int32, (uint32_t));
|
||||
IMPLEMENT_CAST_CASE(Int64, (uint64_t));
|
||||
IMPLEMENT_CAST_END
|
||||
break;
|
||||
case Instruction::IntToPtr: // src integral, dest pointer
|
||||
@ -1426,14 +1322,10 @@ GenericValue Interpreter::executeCastOperation(Instruction::CastOps opcode,
|
||||
case Instruction::BitCast: // src any, dest any (same size)
|
||||
IMPLEMENT_CAST_START
|
||||
IMPLEMENT_CAST_CASE(Bool , (bool));
|
||||
IMPLEMENT_CAST_CASE(UByte , (unsigned char));
|
||||
IMPLEMENT_CAST_CASE(SByte , ( signed char));
|
||||
IMPLEMENT_CAST_CASE(UShort , (unsigned short));
|
||||
IMPLEMENT_CAST_CASE(Short , ( signed short));
|
||||
IMPLEMENT_CAST_CASE(UInt , (unsigned int));
|
||||
IMPLEMENT_CAST_CASE(Int , ( signed int));
|
||||
IMPLEMENT_CAST_CASE(ULong , (uint64_t));
|
||||
IMPLEMENT_CAST_CASE(Long , ( int64_t));
|
||||
IMPLEMENT_CAST_CASE(Int8 , (uint8_t));
|
||||
IMPLEMENT_CAST_CASE(Int16 , (uint16_t));
|
||||
IMPLEMENT_CAST_CASE(Int32 , (uint32_t));
|
||||
IMPLEMENT_CAST_CASE(Int64 , (uint64_t));
|
||||
IMPLEMENT_CAST_CASE(Pointer, (PointerTy));
|
||||
IMPLEMENT_CAST_CASE(Float , (float));
|
||||
IMPLEMENT_CAST_CASE(Double , (double));
|
||||
@ -1466,14 +1358,10 @@ void Interpreter::visitVAArgInst(VAArgInst &I) {
|
||||
.VarArgs[VAList.UIntPairVal.second];
|
||||
const Type *Ty = I.getType();
|
||||
switch (Ty->getTypeID()) {
|
||||
IMPLEMENT_VAARG(UByte);
|
||||
IMPLEMENT_VAARG(SByte);
|
||||
IMPLEMENT_VAARG(UShort);
|
||||
IMPLEMENT_VAARG(Short);
|
||||
IMPLEMENT_VAARG(UInt);
|
||||
IMPLEMENT_VAARG(Int);
|
||||
IMPLEMENT_VAARG(ULong);
|
||||
IMPLEMENT_VAARG(Long);
|
||||
IMPLEMENT_VAARG(Int8);
|
||||
IMPLEMENT_VAARG(Int16);
|
||||
IMPLEMENT_VAARG(Int32);
|
||||
IMPLEMENT_VAARG(Int64);
|
||||
IMPLEMENT_VAARG(Pointer);
|
||||
IMPLEMENT_VAARG(Float);
|
||||
IMPLEMENT_VAARG(Double);
|
||||
|
@ -42,18 +42,14 @@ static char getTypeID(const Type *Ty) {
|
||||
switch (Ty->getTypeID()) {
|
||||
case Type::VoidTyID: return 'V';
|
||||
case Type::BoolTyID: return 'o';
|
||||
case Type::UByteTyID: return 'B';
|
||||
case Type::SByteTyID: return 'b';
|
||||
case Type::UShortTyID: return 'S';
|
||||
case Type::ShortTyID: return 's';
|
||||
case Type::UIntTyID: return 'I';
|
||||
case Type::IntTyID: return 'i';
|
||||
case Type::ULongTyID: return 'L';
|
||||
case Type::LongTyID: return 'l';
|
||||
case Type::Int8TyID: return 'B';
|
||||
case Type::Int16TyID: return 'S';
|
||||
case Type::Int32TyID: return 'I';
|
||||
case Type::Int64TyID: return 'L';
|
||||
case Type::FloatTyID: return 'F';
|
||||
case Type::DoubleTyID: return 'D';
|
||||
case Type::PointerTyID: return 'P';
|
||||
case Type::FunctionTyID: return 'M';
|
||||
case Type::FunctionTyID:return 'M';
|
||||
case Type::StructTyID: return 'T';
|
||||
case Type::ArrayTyID: return 'A';
|
||||
case Type::OpaqueTyID: return 'O';
|
||||
@ -113,20 +109,20 @@ GenericValue Interpreter::callExternalFunction(Function *F,
|
||||
extern "C" { // Don't add C++ manglings to llvm mangling :)
|
||||
|
||||
// void putchar(sbyte)
|
||||
GenericValue lle_Vb_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
cout << Args[0].SByteVal;
|
||||
GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
cout << Args[0].Int8Val;
|
||||
return GenericValue();
|
||||
}
|
||||
|
||||
// int putchar(int)
|
||||
GenericValue lle_ii_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
cout << ((char)Args[0].IntVal) << std::flush;
|
||||
cout << ((char)Args[0].Int32Val) << std::flush;
|
||||
return Args[0];
|
||||
}
|
||||
|
||||
// void putchar(ubyte)
|
||||
GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
cout << Args[0].SByteVal << std::flush;
|
||||
GenericValue lle_Vb_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
cout << Args[0].Int8Val << std::flush;
|
||||
return Args[0];
|
||||
}
|
||||
|
||||
@ -135,7 +131,7 @@ GenericValue lle_X_atexit(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
|
||||
GenericValue GV;
|
||||
GV.IntVal = 0;
|
||||
GV.Int32Val = 0;
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -154,13 +150,13 @@ GenericValue lle_X_abort(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
// void *malloc(uint)
|
||||
GenericValue lle_X_malloc(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1 && "Malloc expects one argument!");
|
||||
return PTOGV(malloc(Args[0].UIntVal));
|
||||
return PTOGV(malloc(Args[0].Int32Val));
|
||||
}
|
||||
|
||||
// void *calloc(uint, uint)
|
||||
GenericValue lle_X_calloc(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 2 && "calloc expects two arguments!");
|
||||
return PTOGV(calloc(Args[0].UIntVal, Args[1].UIntVal));
|
||||
return PTOGV(calloc(Args[0].Int32Val, Args[1].Int32Val));
|
||||
}
|
||||
|
||||
// void free(void *)
|
||||
@ -174,7 +170,7 @@ GenericValue lle_X_free(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_atoi(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
GenericValue GV;
|
||||
GV.IntVal = atoi((char*)GVTOP(Args[0]));
|
||||
GV.Int32Val = atoi((char*)GVTOP(Args[0]));
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -232,14 +228,14 @@ GenericValue lle_X_drand48(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_lrand48(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 0);
|
||||
GenericValue GV;
|
||||
GV.IntVal = lrand48();
|
||||
GV.Int32Val = lrand48();
|
||||
return GV;
|
||||
}
|
||||
|
||||
// void srand48(long)
|
||||
GenericValue lle_X_srand48(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
srand48(Args[0].IntVal);
|
||||
srand48(Args[0].Int32Val);
|
||||
return GenericValue();
|
||||
}
|
||||
|
||||
@ -249,14 +245,14 @@ GenericValue lle_X_srand48(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_rand(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 0);
|
||||
GenericValue GV;
|
||||
GV.IntVal = rand();
|
||||
GV.Int32Val = rand();
|
||||
return GV;
|
||||
}
|
||||
|
||||
// void srand(uint)
|
||||
GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
srand(Args[0].UIntVal);
|
||||
srand(Args[0].Int32Val);
|
||||
return GenericValue();
|
||||
}
|
||||
|
||||
@ -264,7 +260,7 @@ GenericValue lle_X_srand(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_puts(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
GenericValue GV;
|
||||
GV.IntVal = puts((char*)GVTOP(Args[0]));
|
||||
GV.Int32Val = puts((char*)GVTOP(Args[0]));
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -277,7 +273,7 @@ GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
|
||||
// printf should return # chars printed. This is completely incorrect, but
|
||||
// close enough for now.
|
||||
GenericValue GV; GV.IntVal = strlen(FmtStr);
|
||||
GenericValue GV; GV.Int32Val = strlen(FmtStr);
|
||||
while (1) {
|
||||
switch (*FmtStr) {
|
||||
case 0: return GV; // Null terminator...
|
||||
@ -308,7 +304,7 @@ GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
case '%':
|
||||
sprintf(Buffer, FmtBuf); break;
|
||||
case 'c':
|
||||
sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
|
||||
sprintf(Buffer, FmtBuf, Args[ArgNo++].Int32Val); break;
|
||||
case 'd': case 'i':
|
||||
case 'u': case 'o':
|
||||
case 'x': case 'X':
|
||||
@ -323,9 +319,9 @@ GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
FmtBuf[Size+1] = 0;
|
||||
FmtBuf[Size-1] = 'l';
|
||||
}
|
||||
sprintf(Buffer, FmtBuf, Args[ArgNo++].ULongVal);
|
||||
sprintf(Buffer, FmtBuf, Args[ArgNo++].Int64Val);
|
||||
} else
|
||||
sprintf(Buffer, FmtBuf, Args[ArgNo++].IntVal); break;
|
||||
sprintf(Buffer, FmtBuf, Args[ArgNo++].Int32Val); break;
|
||||
case 'e': case 'E': case 'g': case 'G': case 'f':
|
||||
sprintf(Buffer, FmtBuf, Args[ArgNo++].DoubleVal); break;
|
||||
case 'p':
|
||||
@ -394,11 +390,11 @@ static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1,
|
||||
case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p':
|
||||
case 'd':
|
||||
if (Long || LongLong) {
|
||||
Size = 8; Ty = Type::ULongTy;
|
||||
Size = 8; Ty = Type::Int64Ty;
|
||||
} else if (Half) {
|
||||
Size = 4; Ty = Type::UShortTy;
|
||||
Size = 4; Ty = Type::Int16Ty;
|
||||
} else {
|
||||
Size = 4; Ty = Type::UIntTy;
|
||||
Size = 4; Ty = Type::Int32Ty;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -413,7 +409,7 @@ static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1,
|
||||
|
||||
case 's': case 'c': case '[': // No byteswap needed
|
||||
Size = 1;
|
||||
Ty = Type::SByteTy;
|
||||
Ty = Type::Int8Ty;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
@ -439,8 +435,8 @@ GenericValue lle_X_sscanf(FunctionType *M, const vector<GenericValue> &args) {
|
||||
Args[i] = (char*)GVTOP(args[i]);
|
||||
|
||||
GenericValue GV;
|
||||
GV.IntVal = sscanf(Args[0], Args[1], Args[2], Args[3], Args[4],
|
||||
Args[5], Args[6], Args[7], Args[8], Args[9]);
|
||||
GV.Int32Val = sscanf(Args[0], Args[1], Args[2], Args[3], Args[4],
|
||||
Args[5], Args[6], Args[7], Args[8], Args[9]);
|
||||
ByteswapSCANFResults(Args[1], Args[2], Args[3], Args[4],
|
||||
Args[5], Args[6], Args[7], Args[8], Args[9], 0);
|
||||
return GV;
|
||||
@ -455,8 +451,8 @@ GenericValue lle_X_scanf(FunctionType *M, const vector<GenericValue> &args) {
|
||||
Args[i] = (char*)GVTOP(args[i]);
|
||||
|
||||
GenericValue GV;
|
||||
GV.IntVal = scanf(Args[0], Args[1], Args[2], Args[3], Args[4],
|
||||
Args[5], Args[6], Args[7], Args[8], Args[9]);
|
||||
GV.Int32Val = scanf( Args[0], Args[1], Args[2], Args[3], Args[4],
|
||||
Args[5], Args[6], Args[7], Args[8], Args[9]);
|
||||
ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4],
|
||||
Args[5], Args[6], Args[7], Args[8], Args[9]);
|
||||
return GV;
|
||||
@ -466,7 +462,7 @@ GenericValue lle_X_scanf(FunctionType *M, const vector<GenericValue> &args) {
|
||||
// int clock(void) - Profiling implementation
|
||||
GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
extern unsigned int clock(void);
|
||||
GenericValue GV; GV.IntVal = clock();
|
||||
GenericValue GV; GV.Int32Val = clock();
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -479,7 +475,7 @@ GenericValue lle_i_clock(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_strcmp(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 2);
|
||||
GenericValue Ret;
|
||||
Ret.IntVal = strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]));
|
||||
Ret.Int32Val = strcmp((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1]));
|
||||
return Ret;
|
||||
}
|
||||
|
||||
@ -498,10 +494,10 @@ GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
static GenericValue size_t_to_GV (size_t n) {
|
||||
GenericValue Ret;
|
||||
if (sizeof (size_t) == sizeof (uint64_t)) {
|
||||
Ret.ULongVal = n;
|
||||
Ret.Int64Val = n;
|
||||
} else {
|
||||
assert (sizeof (size_t) == sizeof (unsigned int));
|
||||
Ret.UIntVal = n;
|
||||
Ret.Int32Val = n;
|
||||
}
|
||||
return Ret;
|
||||
}
|
||||
@ -509,10 +505,10 @@ static GenericValue size_t_to_GV (size_t n) {
|
||||
static size_t GV_to_size_t (GenericValue GV) {
|
||||
size_t count;
|
||||
if (sizeof (size_t) == sizeof (uint64_t)) {
|
||||
count = (size_t)GV.ULongVal;
|
||||
count = (size_t)GV.Int64Val;
|
||||
} else {
|
||||
assert (sizeof (size_t) == sizeof (unsigned int));
|
||||
count = (size_t)GV.UIntVal;
|
||||
count = (size_t)GV.Int32Val;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@ -540,7 +536,7 @@ GenericValue lle_X___strdup(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_memset(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 3);
|
||||
size_t count = GV_to_size_t (Args[2]);
|
||||
return PTOGV(memset(GVTOP(Args[0]), Args[1].IntVal, count));
|
||||
return PTOGV(memset(GVTOP(Args[0]), Args[1].Int32Val, count));
|
||||
}
|
||||
|
||||
// void *memcpy(void *Dest, void *src, size_t Size);
|
||||
@ -569,7 +565,7 @@ GenericValue lle_X_fopen(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_fclose(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
GenericValue GV;
|
||||
GV.IntVal = fclose(getFILE(GVTOP(Args[0])));
|
||||
GV.Int32Val = fclose(getFILE(GVTOP(Args[0])));
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -578,7 +574,7 @@ GenericValue lle_X_feof(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
GenericValue GV;
|
||||
|
||||
GV.IntVal = feof(getFILE(GVTOP(Args[0])));
|
||||
GV.Int32Val = feof(getFILE(GVTOP(Args[0])));
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -605,7 +601,7 @@ GenericValue lle_X_fwrite(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
// char *fgets(char *s, int n, FILE *stream);
|
||||
GenericValue lle_X_fgets(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 3);
|
||||
return GVTOP(fgets((char*)GVTOP(Args[0]), Args[1].IntVal,
|
||||
return GVTOP(fgets((char*)GVTOP(Args[0]), Args[1].Int32Val,
|
||||
getFILE(GVTOP(Args[2]))));
|
||||
}
|
||||
|
||||
@ -620,7 +616,7 @@ GenericValue lle_X_freopen(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
GenericValue GV;
|
||||
GV.IntVal = fflush(getFILE(GVTOP(Args[0])));
|
||||
GV.Int32Val = fflush(getFILE(GVTOP(Args[0])));
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -628,7 +624,7 @@ GenericValue lle_X_fflush(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_getc(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
GenericValue GV;
|
||||
GV.IntVal = getc(getFILE(GVTOP(Args[0])));
|
||||
GV.Int32Val = getc(getFILE(GVTOP(Args[0])));
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -641,7 +637,7 @@ GenericValue lle_X__IO_getc(FunctionType *F, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_fputc(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 2);
|
||||
GenericValue GV;
|
||||
GV.IntVal = fputc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
|
||||
GV.Int32Val = fputc(Args[0].Int32Val, getFILE(GVTOP(Args[1])));
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -649,7 +645,7 @@ GenericValue lle_X_fputc(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_ungetc(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 2);
|
||||
GenericValue GV;
|
||||
GV.IntVal = ungetc(Args[0].IntVal, getFILE(GVTOP(Args[1])));
|
||||
GV.Int32Val = ungetc(Args[0].Int32Val, getFILE(GVTOP(Args[1])));
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -657,7 +653,7 @@ GenericValue lle_X_ungetc(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
GenericValue lle_X_ferror(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
assert(Args.size() == 1);
|
||||
GenericValue GV;
|
||||
GV.IntVal = ferror (getFILE(GVTOP(Args[0])));
|
||||
GV.Int32Val = ferror (getFILE(GVTOP(Args[0])));
|
||||
return GV;
|
||||
}
|
||||
|
||||
|
@ -95,11 +95,11 @@ GenericValue JIT::runFunction(Function *F,
|
||||
|
||||
// Handle some common cases first. These cases correspond to common `main'
|
||||
// prototypes.
|
||||
if (RetTy == Type::IntTy || RetTy == Type::UIntTy || RetTy == Type::VoidTy) {
|
||||
if (RetTy == Type::Int32Ty || RetTy == Type::Int32Ty || RetTy == Type::VoidTy) {
|
||||
switch (ArgValues.size()) {
|
||||
case 3:
|
||||
if ((FTy->getParamType(0) == Type::IntTy ||
|
||||
FTy->getParamType(0) == Type::UIntTy) &&
|
||||
if ((FTy->getParamType(0) == Type::Int32Ty ||
|
||||
FTy->getParamType(0) == Type::Int32Ty) &&
|
||||
isa<PointerType>(FTy->getParamType(1)) &&
|
||||
isa<PointerType>(FTy->getParamType(2))) {
|
||||
int (*PF)(int, char **, const char **) =
|
||||
@ -107,30 +107,30 @@ GenericValue JIT::runFunction(Function *F,
|
||||
|
||||
// Call the function.
|
||||
GenericValue rv;
|
||||
rv.IntVal = PF(ArgValues[0].IntVal, (char **)GVTOP(ArgValues[1]),
|
||||
rv.Int32Val = PF(ArgValues[0].Int32Val, (char **)GVTOP(ArgValues[1]),
|
||||
(const char **)GVTOP(ArgValues[2]));
|
||||
return rv;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ((FTy->getParamType(0) == Type::IntTy ||
|
||||
FTy->getParamType(0) == Type::UIntTy) &&
|
||||
if ((FTy->getParamType(0) == Type::Int32Ty ||
|
||||
FTy->getParamType(0) == Type::Int32Ty) &&
|
||||
isa<PointerType>(FTy->getParamType(1))) {
|
||||
int (*PF)(int, char **) = (int(*)(int, char **))(intptr_t)FPtr;
|
||||
|
||||
// Call the function.
|
||||
GenericValue rv;
|
||||
rv.IntVal = PF(ArgValues[0].IntVal, (char **)GVTOP(ArgValues[1]));
|
||||
rv.Int32Val = PF(ArgValues[0].Int32Val, (char **)GVTOP(ArgValues[1]));
|
||||
return rv;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (FTy->getNumParams() == 1 &&
|
||||
(FTy->getParamType(0) == Type::IntTy ||
|
||||
FTy->getParamType(0) == Type::UIntTy)) {
|
||||
(FTy->getParamType(0) == Type::Int32Ty ||
|
||||
FTy->getParamType(0) == Type::Int32Ty)) {
|
||||
GenericValue rv;
|
||||
int (*PF)(int) = (int(*)(int))(intptr_t)FPtr;
|
||||
rv.IntVal = PF(ArgValues[0].IntVal);
|
||||
rv.Int32Val = PF(ArgValues[0].Int32Val);
|
||||
return rv;
|
||||
}
|
||||
break;
|
||||
@ -145,22 +145,18 @@ GenericValue JIT::runFunction(Function *F,
|
||||
case Type::BoolTyID:
|
||||
rv.BoolVal = ((bool(*)())(intptr_t)FPtr)();
|
||||
return rv;
|
||||
case Type::SByteTyID:
|
||||
case Type::UByteTyID:
|
||||
rv.SByteVal = ((char(*)())(intptr_t)FPtr)();
|
||||
case Type::Int8TyID:
|
||||
rv.Int8Val = ((char(*)())(intptr_t)FPtr)();
|
||||
return rv;
|
||||
case Type::ShortTyID:
|
||||
case Type::UShortTyID:
|
||||
rv.ShortVal = ((short(*)())(intptr_t)FPtr)();
|
||||
case Type::Int16TyID:
|
||||
rv.Int16Val = ((short(*)())(intptr_t)FPtr)();
|
||||
return rv;
|
||||
case Type::VoidTyID:
|
||||
case Type::IntTyID:
|
||||
case Type::UIntTyID:
|
||||
rv.IntVal = ((int(*)())(intptr_t)FPtr)();
|
||||
case Type::Int32TyID:
|
||||
rv.Int32Val = ((int(*)())(intptr_t)FPtr)();
|
||||
return rv;
|
||||
case Type::LongTyID:
|
||||
case Type::ULongTyID:
|
||||
rv.LongVal = ((int64_t(*)())(intptr_t)FPtr)();
|
||||
case Type::Int64TyID:
|
||||
rv.Int64Val = ((int64_t(*)())(intptr_t)FPtr)();
|
||||
return rv;
|
||||
case Type::FloatTyID:
|
||||
rv.FloatVal = ((float(*)())(intptr_t)FPtr)();
|
||||
@ -196,22 +192,18 @@ GenericValue JIT::runFunction(Function *F,
|
||||
switch (ArgTy->getTypeID()) {
|
||||
default: assert(0 && "Unknown argument type for function call!");
|
||||
case Type::BoolTyID: C = ConstantBool::get(AV.BoolVal); break;
|
||||
case Type::SByteTyID: C = ConstantInt::get(ArgTy, AV.SByteVal); break;
|
||||
case Type::UByteTyID: C = ConstantInt::get(ArgTy, AV.UByteVal); break;
|
||||
case Type::ShortTyID: C = ConstantInt::get(ArgTy, AV.ShortVal); break;
|
||||
case Type::UShortTyID: C = ConstantInt::get(ArgTy, AV.UShortVal); break;
|
||||
case Type::IntTyID: C = ConstantInt::get(ArgTy, AV.IntVal); break;
|
||||
case Type::UIntTyID: C = ConstantInt::get(ArgTy, AV.UIntVal); break;
|
||||
case Type::LongTyID: C = ConstantInt::get(ArgTy, AV.LongVal); break;
|
||||
case Type::ULongTyID: C = ConstantInt::get(ArgTy, AV.ULongVal); break;
|
||||
case Type::Int8TyID: C = ConstantInt::get(ArgTy, AV.Int8Val); break;
|
||||
case Type::Int16TyID: C = ConstantInt::get(ArgTy, AV.Int16Val); break;
|
||||
case Type::Int32TyID: C = ConstantInt::get(ArgTy, AV.Int32Val); break;
|
||||
case Type::Int64TyID: C = ConstantInt::get(ArgTy, AV.Int64Val); break;
|
||||
case Type::FloatTyID: C = ConstantFP ::get(ArgTy, AV.FloatVal); break;
|
||||
case Type::DoubleTyID: C = ConstantFP ::get(ArgTy, AV.DoubleVal); break;
|
||||
case Type::PointerTyID:
|
||||
void *ArgPtr = GVTOP(AV);
|
||||
if (sizeof(void*) == 4) {
|
||||
C = ConstantInt::get(Type::IntTy, (int)(intptr_t)ArgPtr);
|
||||
C = ConstantInt::get(Type::Int32Ty, (int)(intptr_t)ArgPtr);
|
||||
} else {
|
||||
C = ConstantInt::get(Type::LongTy, (intptr_t)ArgPtr);
|
||||
C = ConstantInt::get(Type::Int64Ty, (intptr_t)ArgPtr);
|
||||
}
|
||||
C = ConstantExpr::getIntToPtr(C, ArgTy); // Cast the integer to pointer
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user