#include <math.h> // For fmod
#include <signal.h>
#include <setjmp.h>
-using std::vector;
-using std::cout;
-using std::cerr;
Interpreter *TheEE = 0;
ProfileStructureFields("profilestructfields",
cl::desc("Profile Structure Field Accesses"));
#include <map>
-static std::map<const StructType *, vector<unsigned> > FieldAccessCounts;
+static std::map<const StructType *, std::vector<unsigned> > FieldAccessCounts;
#endif
sigjmp_buf SignalRecoverBuffer;
getOperandValue(CE->getOperand(1), SF),
CE->getType());
default:
- cerr << "Unhandled ConstantExpr: " << CE << "\n";
+ std::cerr << "Unhandled ConstantExpr: " << CE << "\n";
abort();
return GenericValue();
}
static void printOperandInfo(Value *V, ExecutionContext &SF) {
if (isa<Constant>(V)) {
- cout << "Constant Pool Value\n";
+ std::cout << "Constant Pool Value\n";
} else if (isa<GlobalValue>(V)) {
- cout << "Global Value\n";
+ std::cout << "Global Value\n";
} else {
unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
unsigned Slot = getOperandSlot(V);
- cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot
- << " Addr=" << &SF.Values[TyP][Slot] << " SF=" << &SF
- << " Contents=0x";
+ std::cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot
+ << " Addr=" << &SF.Values[TyP][Slot] << " SF=" << &SF
+ << " Contents=0x";
const unsigned char *Buf = (const unsigned char*)&SF.Values[TyP][Slot];
for (unsigned i = 0; i < sizeof(GenericValue); ++i) {
unsigned char Cur = Buf[i];
- cout << ( Cur >= 160? char((Cur>>4)+'A'-10) : char((Cur>>4) + '0'))
- << ((Cur&15) >= 10? char((Cur&15)+'A'-10) : char((Cur&15) + '0'));
+ std::cout << ( Cur >= 160?char((Cur>>4)+'A'-10):char((Cur>>4) + '0'))
+ << ((Cur&15) >= 10?char((Cur&15)+'A'-10):char((Cur&15) + '0'));
}
- cout << "\n";
+ std::cout << "\n";
}
}
static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) {
unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
- //cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)] << "\n";
+ //std::cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)]<< "\n";
SF.Values[TyP][getOperandSlot(V)] = Val;
}
IMPLEMENT_BINARY_OPERATOR(+, Long);
IMPLEMENT_BINARY_OPERATOR(+, Float);
IMPLEMENT_BINARY_OPERATOR(+, Double);
- IMPLEMENT_BINARY_OPERATOR(+, Pointer);
default:
- cout << "Unhandled type for Add instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for Add instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_BINARY_OPERATOR(-, Long);
IMPLEMENT_BINARY_OPERATOR(-, Float);
IMPLEMENT_BINARY_OPERATOR(-, Double);
- IMPLEMENT_BINARY_OPERATOR(-, Pointer);
default:
- cout << "Unhandled type for Sub instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for Sub instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_BINARY_OPERATOR(*, Long);
IMPLEMENT_BINARY_OPERATOR(*, Float);
IMPLEMENT_BINARY_OPERATOR(*, Double);
- IMPLEMENT_BINARY_OPERATOR(*, Pointer);
default:
- cout << "Unhandled type for Mul instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for Mul instruction: " << Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_BINARY_OPERATOR(/, Long);
IMPLEMENT_BINARY_OPERATOR(/, Float);
IMPLEMENT_BINARY_OPERATOR(/, Double);
- IMPLEMENT_BINARY_OPERATOR(/, Pointer);
default:
- cout << "Unhandled type for Div instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for Div instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_BINARY_OPERATOR(%, Int);
IMPLEMENT_BINARY_OPERATOR(%, ULong);
IMPLEMENT_BINARY_OPERATOR(%, Long);
- IMPLEMENT_BINARY_OPERATOR(%, Pointer);
case Type::FloatTyID:
Dest.FloatVal = fmod(Src1.FloatVal, Src2.FloatVal);
break;
Dest.DoubleVal = fmod(Src1.DoubleVal, Src2.DoubleVal);
break;
default:
- cout << "Unhandled type for Rem instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for Rem instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_BINARY_OPERATOR(&, Int);
IMPLEMENT_BINARY_OPERATOR(&, ULong);
IMPLEMENT_BINARY_OPERATOR(&, Long);
- IMPLEMENT_BINARY_OPERATOR(&, Pointer);
default:
- cout << "Unhandled type for And instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for And instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_BINARY_OPERATOR(|, Int);
IMPLEMENT_BINARY_OPERATOR(|, ULong);
IMPLEMENT_BINARY_OPERATOR(|, Long);
- IMPLEMENT_BINARY_OPERATOR(|, Pointer);
default:
- cout << "Unhandled type for Or instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for Or instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_BINARY_OPERATOR(^, Int);
IMPLEMENT_BINARY_OPERATOR(^, ULong);
IMPLEMENT_BINARY_OPERATOR(^, Long);
- IMPLEMENT_BINARY_OPERATOR(^, Pointer);
default:
- cout << "Unhandled type for Xor instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for Xor instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_SETCC(==, Double);
IMPLEMENT_SETCC(==, Pointer);
default:
- cout << "Unhandled type for SetEQ instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for SetEQ instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_SETCC(!=, Pointer);
default:
- cout << "Unhandled type for SetNE instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for SetNE instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_SETCC(<=, Double);
IMPLEMENT_SETCC(<=, Pointer);
default:
- cout << "Unhandled type for SetLE instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for SetLE instruction: " << Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_SETCC(>=, Double);
IMPLEMENT_SETCC(>=, Pointer);
default:
- cout << "Unhandled type for SetGE instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for SetGE instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_SETCC(<, Double);
IMPLEMENT_SETCC(<, Pointer);
default:
- cout << "Unhandled type for SetLT instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for SetLT instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
IMPLEMENT_SETCC(>, Double);
IMPLEMENT_SETCC(>, Pointer);
default:
- cout << "Unhandled type for SetGT instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for SetGT instruction: " << *Ty << "\n";
+ abort();
}
return Dest;
}
case Instruction::SetLT: R = executeSetLTInst(Src1, Src2, Ty); break;
case Instruction::SetGT: R = executeSetGTInst(Src1, Src2, Ty); break;
default:
- cout << "Don't know how to handle this binary operator!\n-->" << I;
- R = Src1;
+ std::cout << "Don't know how to handle this binary operator!\n-->" << I;
+ abort();
}
SetValue(&I, R, SF);
// Print out structure field accounting information...
if (!FieldAccessCounts.empty()) {
CW << "Profile Field Access Counts:\n";
- std::map<const StructType *, vector<unsigned> >::iterator
+ std::map<const StructType *, std::vector<unsigned> >::iterator
I = FieldAccessCounts.begin(), E = FieldAccessCounts.end();
for (; I != E; ++I) {
- vector<unsigned> &OfC = I->second;
+ std::vector<unsigned> &OfC = I->second;
CW << " '" << (Value*)I->first << "'\t- Sum=";
unsigned Sum = 0;
CW << "\n";
CW << "Profile Field Access Percentages:\n";
- cout.precision(3);
+ std::cout.precision(3);
for (I = FieldAccessCounts.begin(); I != E; ++I) {
- vector<unsigned> &OfC = I->second;
+ std::vector<unsigned> &OfC = I->second;
unsigned Sum = 0;
for (unsigned i = 0; i < OfC.size(); ++i)
Sum += OfC[i];
void Interpreter::exitCalled(GenericValue GV) {
if (!QuietMode) {
- cout << "Program returned ";
+ std::cout << "Program returned ";
print(Type::IntTy, GV);
- cout << " via 'void exit(int)'\n";
+ std::cout << " via 'void exit(int)'\n";
}
ExitCode = GV.SByteVal;
CW << "Function " << M->getType() << " \"" << M->getName()
<< "\" returned ";
print(RetTy, Result);
- cout << "\n";
+ std::cout << "\n";
}
if (RetTy->isIntegral())
CW << "Function " << M->getType() << " \"" << M->getName()
<< "\" returned ";
print(RetTy, Result);
- cout << "\n";
+ std::cout << "\n";
}
}
#ifdef PROFILE_STRUCTURE_FIELDS
if (ProfileStructureFields) {
// Do accounting for this field...
- vector<unsigned> &OfC = FieldAccessCounts[STy];
+ std::vector<unsigned> &OfC = FieldAccessCounts[STy];
if (OfC.size() == 0) OfC.resize(STy->getElementTypes().size());
OfC[Index]++;
}
unsigned Idx = getOperandValue(*I, SF).LongVal;
if (const ArrayType *AT = dyn_cast<ArrayType>(ST))
if (Idx >= AT->getNumElements() && ArrayChecksEnabled) {
- cerr << "Out of range memory access to element #" << Idx
- << " of a " << AT->getNumElements() << " element array."
- << " Subscript #" << *I << "\n";
+ std::cerr << "Out of range memory access to element #" << Idx
+ << " of a " << AT->getNumElements() << " element array."
+ << " Subscript #" << *I << "\n";
// Get outta here!!!
siglongjmp(SignalRecoverBuffer, SIGTRAP);
}
((uint64_t)Ptr->Untyped[7] << 56);
break;
default:
- cout << "Cannot load value of type " << I.getType() << "!\n";
+ std::cout << "Cannot load value of type " << *I.getType() << "!\n";
+ abort();
}
} else {
switch (I.getType()->getPrimitiveID()) {
((uint64_t)Ptr->Untyped[0] << 56);
break;
default:
- cout << "Cannot load value of type " << I.getType() << "!\n";
+ std::cout << "Cannot load value of type " << *I.getType() << "!\n";
+ abort();
}
}
void Interpreter::executeCallInst(CallInst &I, ExecutionContext &SF) {
ECStack.back().Caller = &I;
- vector<GenericValue> ArgVals;
+ std::vector<GenericValue> ArgVals;
ArgVals.reserve(I.getNumOperands()-1);
for (unsigned i = 1; i < I.getNumOperands(); ++i) {
ArgVals.push_back(getOperandValue(I.getOperand(i), SF));
IMPLEMENT_SHIFT(<<, Int);
IMPLEMENT_SHIFT(<<, ULong);
IMPLEMENT_SHIFT(<<, Long);
- IMPLEMENT_SHIFT(<<, Pointer);
default:
- cout << "Unhandled type for Shl instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for Shl instruction: " << *Ty << "\n";
}
SetValue(&I, Dest, SF);
}
IMPLEMENT_SHIFT(>>, Int);
IMPLEMENT_SHIFT(>>, ULong);
IMPLEMENT_SHIFT(>>, Long);
- IMPLEMENT_SHIFT(>>, Pointer);
default:
- cout << "Unhandled type for Shr instruction: " << Ty << "\n";
+ std::cout << "Unhandled type for Shr instruction: " << *Ty << "\n";
+ abort();
}
SetValue(&I, Dest, SF);
}
IMPLEMENT_CAST(DESTTY, DESTCTY, Double)
#define IMPLEMENT_CAST_CASE_END() \
- default: cout << "Unhandled cast: " << SrcTy << " to " << Ty << "\n"; \
- break; \
+ default: std::cout << "Unhandled cast: " << SrcTy << " to " << Ty << "\n"; \
+ abort(); \
} \
break
IMPLEMENT_CAST_CASE(Double , (double));
IMPLEMENT_CAST_CASE(Bool , (bool));
default:
- cout << "Unhandled dest type for cast instruction: " << Ty << "\n";
+ std::cout << "Unhandled dest type for cast instruction: " << *Ty << "\n";
abort();
}
//===----------------------------------------------------------------------===//
// callMethod - Execute the specified function...
//
-void Interpreter::callMethod(Function *M, const vector<GenericValue> &ArgVals) {
+void Interpreter::callMethod(Function *M,
+ const std::vector<GenericValue> &ArgVals) {
assert((ECStack.empty() || ECStack.back().Caller == 0 ||
ECStack.back().Caller->getNumOperands()-1 == ArgVals.size()) &&
"Incorrect number of arguments passed into function call!");
CW << "Function " << M->getType() << " \"" << M->getName()
<< "\" returned ";
print(RetTy, Result);
- cout << "\n";
+ std::cout << "\n";
if (RetTy->isIntegral())
ExitCode = Result.IntVal; // Capture the exit code of the program
if (int SigNo = sigsetjmp(SignalRecoverBuffer, 1)) {
--SF.CurInst; // Back up to erroring instruction
if (SigNo != SIGINT) {
- cout << "EXCEPTION OCCURRED [" << strsignal(SigNo) << "]:\n";
+ std::cout << "EXCEPTION OCCURRED [" << strsignal(SigNo) << "]:\n";
printStackTrace();
// If -abort-on-exception was specified, terminate LLI instead of trying
// to debug it.
//
if (AbortOnExceptions) exit(1);
} else if (SigNo == SIGINT) {
- cout << "CTRL-C Detected, execution halted.\n";
+ std::cout << "CTRL-C Detected, execution halted.\n";
}
InInstruction = false;
return true;
case Instruction::Shr: executeShrInst (cast<ShiftInst>(I), SF); break;
case Instruction::Cast: executeCastInst (cast<CastInst> (I), SF); break;
default:
- cout << "Don't know how to execute this instruction!\n-->" << I;
+ std::cout << "Don't know how to execute this instruction!\n-->" << I;
+ abort();
}
}
InInstruction = false;
void Interpreter::stepInstruction() { // Do the 'step' command
if (ECStack.empty()) {
- cout << "Error: no program running, cannot step!\n";
+ std::cout << "Error: no program running, cannot step!\n";
return;
}
// --- UI Stuff...
void Interpreter::nextInstruction() { // Do the 'next' command
if (ECStack.empty()) {
- cout << "Error: no program running, cannot 'next'!\n";
+ std::cout << "Error: no program running, cannot 'next'!\n";
return;
}
// Step into the function...
if (executeInstruction()) {
// Hit a breakpoint, print current instruction, then return to user...
- cout << "Breakpoint hit!\n";
+ std::cout << "Breakpoint hit!\n";
printCurrentInstruction();
return;
}
void Interpreter::run() {
if (ECStack.empty()) {
- cout << "Error: no program running, cannot run!\n";
+ std::cout << "Error: no program running, cannot run!\n";
return;
}
HitBreakpoint = executeInstruction();
}
- if (HitBreakpoint) {
- cout << "Breakpoint hit!\n";
- }
+ if (HitBreakpoint)
+ std::cout << "Breakpoint hit!\n";
+
// Print the next instruction to execute...
printCurrentInstruction();
}
void Interpreter::finish() {
if (ECStack.empty()) {
- cout << "Error: no program running, cannot run!\n";
+ std::cout << "Error: no program running, cannot run!\n";
return;
}
HitBreakpoint = executeInstruction();
}
- if (HitBreakpoint) {
- cout << "Breakpoint hit!\n";
- }
+ if (HitBreakpoint)
+ std::cout << "Breakpoint hit!\n";
// Print the next instruction to execute...
printCurrentInstruction();
void Interpreter::printCurrentInstruction() {
if (!ECStack.empty()) {
if (ECStack.back().CurBB->begin() == ECStack.back().CurInst) // print label
- WriteAsOperand(cout, ECStack.back().CurBB) << ":\n";
+ WriteAsOperand(std::cout, ECStack.back().CurBB) << ":\n";
Instruction &I = *ECStack.back().CurInst;
InstNumber *IN = (InstNumber*)I.getAnnotation(SlotNumberAID);
assert(IN && "Instruction has no numbering annotation!");
- cout << "#" << IN->InstNum << I;
+ std::cout << "#" << IN->InstNum << I;
}
}
void Interpreter::printValue(const Type *Ty, GenericValue V) {
switch (Ty->getPrimitiveID()) {
- case Type::BoolTyID: cout << (V.BoolVal?"true":"false"); break;
+ case Type::BoolTyID: std::cout << (V.BoolVal?"true":"false"); break;
case Type::SByteTyID:
- cout << (int)V.SByteVal << " '" << V.SByteVal << "'"; break;
+ std::cout << (int)V.SByteVal << " '" << V.SByteVal << "'"; break;
case Type::UByteTyID:
- cout << (unsigned)V.UByteVal << " '" << V.UByteVal << "'"; break;
- case Type::ShortTyID: cout << V.ShortVal; break;
- case Type::UShortTyID: cout << V.UShortVal; break;
- case Type::IntTyID: cout << V.IntVal; break;
- case Type::UIntTyID: cout << V.UIntVal; break;
- case Type::LongTyID: cout << (long)V.LongVal; break;
- case Type::ULongTyID: cout << (unsigned long)V.ULongVal; break;
- case Type::FloatTyID: cout << V.FloatVal; break;
- case Type::DoubleTyID: cout << V.DoubleVal; break;
- case Type::PointerTyID:cout << (void*)GVTOP(V); break;
+ std::cout << (unsigned)V.UByteVal << " '" << V.UByteVal << "'"; break;
+ case Type::ShortTyID: std::cout << V.ShortVal; break;
+ case Type::UShortTyID: std::cout << V.UShortVal; break;
+ case Type::IntTyID: std::cout << V.IntVal; break;
+ case Type::UIntTyID: std::cout << V.UIntVal; break;
+ case Type::LongTyID: std::cout << (long)V.LongVal; break;
+ case Type::ULongTyID: std::cout << (unsigned long)V.ULongVal; break;
+ case Type::FloatTyID: std::cout << V.FloatVal; break;
+ case Type::DoubleTyID: std::cout << V.DoubleVal; break;
+ case Type::PointerTyID:std::cout << (void*)GVTOP(V); break;
default:
- cout << "- Don't know how to print value of this type!";
+ std::cout << "- Don't know how to print value of this type!";
break;
}
}
} else { // Otherwise there should be an annotation for the slot#
print(PickedVal->getType(),
getOperandValue(PickedVal, ECStack[CurFrame]));
- cout << "\n";
+ std::cout << "\n";
}
}
Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name));
if (!PickedVal) return;
- cout << "Value: ";
+ std::cout << "Value: ";
print(PickedVal->getType(),
getOperandValue(PickedVal, ECStack[CurFrame]));
- cout << "\n";
+ std::cout << "\n";
printOperandInfo(PickedVal, ECStack[CurFrame]);
}
unsigned i = 0;
for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++i) {
- if (i != 0) cout << ", ";
+ if (i != 0) std::cout << ", ";
CW << *I << "=";
printValue(I->getType(), getOperandValue(I, ECStack[FrameNo]));
}
- cout << ")\n";
+ std::cout << ")\n";
if (FrameNo != int(ECStack.size()-1)) {
BasicBlock::iterator I = ECStack[FrameNo].CurInst;