aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine/Interpreter
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-12-31 05:51:36 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-12-31 05:51:36 +0000
commite49661bdf5b7a913d4e368cf511381e524ae403a (patch)
treef371f5de755929c3be4963651db688651654a224 /lib/ExecutionEngine/Interpreter
parentdb8d2bed6a0ef890b81fabb014bfcb678e891695 (diff)
downloadexternal_llvm-e49661bdf5b7a913d4e368cf511381e524ae403a.zip
external_llvm-e49661bdf5b7a913d4e368cf511381e524ae403a.tar.gz
external_llvm-e49661bdf5b7a913d4e368cf511381e524ae403a.tar.bz2
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
Diffstat (limited to 'lib/ExecutionEngine/Interpreter')
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp526
-rw-r--r--lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp96
2 files changed, 253 insertions, 369 deletions
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index 3ca5682..97411d3 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -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);
diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index a1c4317..d567dff 100644
--- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -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;
}