Use the std namespace explicitly

llvm-svn: 5708
This commit is contained in:
Chris Lattner 2003-03-06 16:32:25 +00:00
parent 805fc16a27
commit 17f8686900
3 changed files with 41 additions and 47 deletions

View File

@ -13,8 +13,6 @@
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include <algorithm> #include <algorithm>
using std::make_pair;
const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf, const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf,
const uchar *EndBuf) { const uchar *EndBuf) {
unsigned PrimType; unsigned PrimType;
@ -336,7 +334,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf,
if (!(GV = dyn_cast<GlobalValue>(Val))) return true; if (!(GV = dyn_cast<GlobalValue>(Val))) return true;
BCR_TRACE(5, "Value Found in ValueTable!\n"); BCR_TRACE(5, "Value Found in ValueTable!\n");
} else { // Nope... find or create a forward ref. for it } else { // Nope... find or create a forward ref. for it
GlobalRefsType::iterator I = GlobalRefs.find(make_pair(PT, Slot)); GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PT, Slot));
if (I != GlobalRefs.end()) { if (I != GlobalRefs.end()) {
BCR_TRACE(5, "Previous forward ref found!\n"); BCR_TRACE(5, "Previous forward ref found!\n");
@ -349,7 +347,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf,
new GlobalVariable(PT->getElementType(), false, true); new GlobalVariable(PT->getElementType(), false, true);
// Keep track of the fact that we have a forward ref to recycle it // Keep track of the fact that we have a forward ref to recycle it
GlobalRefs.insert(make_pair(make_pair(PT, Slot), GVar)); GlobalRefs.insert(std::make_pair(std::make_pair(PT, Slot), GVar));
// Must temporarily push this value into the module table... // Must temporarily push this value into the module table...
TheModule->getGlobalList().push_back(GVar); TheModule->getGlobalList().push_back(GVar);

View File

@ -16,8 +16,6 @@
#include "llvm/iMemory.h" #include "llvm/iMemory.h"
#include "llvm/iPHINode.h" #include "llvm/iPHINode.h"
#include "llvm/iOther.h" #include "llvm/iOther.h"
using std::vector;
using std::cerr;
bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf, bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf,
RawInst &Result) { RawInst &Result) {
@ -78,7 +76,7 @@ bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf,
switch (Result.NumOperands) { switch (Result.NumOperands) {
case 0: case 0:
cerr << "Zero Arg instr found!\n"; std::cerr << "Zero Arg instr found!\n";
return true; // This encoding is invalid! return true; // This encoding is invalid!
case 1: case 1:
if (read_vbr(Buf, EndBuf, Result.Arg1)) return true; if (read_vbr(Buf, EndBuf, Result.Arg1)) return true;
@ -97,7 +95,7 @@ bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf,
read_vbr(Buf, EndBuf, Result.Arg2)) return true; read_vbr(Buf, EndBuf, Result.Arg2)) return true;
// Allocate a vector to hold arguments 3, 4, 5, 6 ... // Allocate a vector to hold arguments 3, 4, 5, 6 ...
Result.VarArgs = new vector<unsigned>(Result.NumOperands-2); Result.VarArgs = new std::vector<unsigned>(Result.NumOperands-2);
for (unsigned a = 0; a < Result.NumOperands-2; a++) for (unsigned a = 0; a < Result.NumOperands-2; a++)
if (read_vbr(Buf, EndBuf, (*Result.VarArgs)[a])) return true; if (read_vbr(Buf, EndBuf, (*Result.VarArgs)[a])) return true;
break; break;
@ -107,9 +105,9 @@ bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf,
} }
#if 0 #if 0
cerr << "NO: " << Result.NumOperands << " opcode: " << Result.Opcode std::cerr << "NO: " << Result.NumOperands << " opcode: " << Result.Opcode
<< " Ty: " << Result.Ty->getDescription() << " arg1: " << Result.Arg1 << " Ty: " << Result.Ty->getDescription() << " arg1: "<< Result.Arg1
<< " arg2: " << Result.Arg2 << " arg3: " << Result.Arg3 << "\n"; << " arg2: " << Result.Arg2 << " arg3: " << Result.Arg3 << "\n";
#endif #endif
return false; return false;
} }
@ -135,7 +133,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
case Instruction::Cast: { case Instruction::Cast: {
V = getValue(Raw.Ty, Raw.Arg1); V = getValue(Raw.Ty, Raw.Arg1);
const Type *Ty = getType(Raw.Arg2); const Type *Ty = getType(Raw.Arg2);
if (V == 0 || Ty == 0) { cerr << "Invalid cast!\n"; return true; } if (V == 0 || Ty == 0) { std::cerr << "Invalid cast!\n"; return true; }
Res = new CastInst(V, Ty); Res = new CastInst(V, Ty);
return false; return false;
} }
@ -144,7 +142,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
switch (Raw.NumOperands) { switch (Raw.NumOperands) {
case 0: case 0:
case 1: case 1:
case 3: cerr << "Invalid phi node encountered!\n"; case 3: std::cerr << "Invalid phi node encountered!\n";
delete PN; delete PN;
return true; return true;
case 2: PN->addIncoming(getValue(Raw.Ty, Raw.Arg1), case 2: PN->addIncoming(getValue(Raw.Ty, Raw.Arg1),
@ -154,11 +152,11 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
PN->addIncoming(getValue(Raw.Ty, Raw.Arg1), PN->addIncoming(getValue(Raw.Ty, Raw.Arg1),
cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2))); cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2)));
if (Raw.VarArgs->size() & 1) { if (Raw.VarArgs->size() & 1) {
cerr << "PHI Node with ODD number of arguments!\n"; std::cerr << "PHI Node with ODD number of arguments!\n";
delete PN; delete PN;
return true; return true;
} else { } else {
vector<unsigned> &args = *Raw.VarArgs; std::vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0; i < args.size(); i+=2) for (unsigned i = 0; i < args.size(); i+=2)
PN->addIncoming(getValue(Raw.Ty, args[i]), PN->addIncoming(getValue(Raw.Ty, args[i]),
cast<BasicBlock>(getValue(Type::LabelTy, args[i+1]))); cast<BasicBlock>(getValue(Type::LabelTy, args[i+1])));
@ -204,12 +202,12 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
if (Raw.NumOperands < 3) return false; // No destinations? Wierd. if (Raw.NumOperands < 3) return false; // No destinations? Wierd.
if (Raw.NumOperands == 3 || Raw.VarArgs->size() & 1) { if (Raw.NumOperands == 3 || Raw.VarArgs->size() & 1) {
cerr << "Switch statement with odd number of arguments!\n"; std::cerr << "Switch statement with odd number of arguments!\n";
delete I; delete I;
return true; return true;
} }
vector<unsigned> &args = *Raw.VarArgs; std::vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0; i < args.size(); i += 2) for (unsigned i = 0; i < args.size(); i += 2)
I->dest_push_back(cast<Constant>(getValue(Raw.Ty, args[i])), I->dest_push_back(cast<Constant>(getValue(Raw.Ty, args[i])),
cast<BasicBlock>(getValue(Type::LabelTy, args[i+1]))); cast<BasicBlock>(getValue(Type::LabelTy, args[i+1])));
@ -228,14 +226,14 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
const FunctionType *MTy = dyn_cast<FunctionType>(PTy->getElementType()); const FunctionType *MTy = dyn_cast<FunctionType>(PTy->getElementType());
if (MTy == 0) return true; if (MTy == 0) return true;
vector<Value *> Params; std::vector<Value *> Params;
const FunctionType::ParamTypes &PL = MTy->getParamTypes(); const FunctionType::ParamTypes &PL = MTy->getParamTypes();
if (!MTy->isVarArg()) { if (!MTy->isVarArg()) {
FunctionType::ParamTypes::const_iterator It = PL.begin(); FunctionType::ParamTypes::const_iterator It = PL.begin();
switch (Raw.NumOperands) { switch (Raw.NumOperands) {
case 0: cerr << "Invalid call instruction encountered!\n"; case 0: std::cerr << "Invalid call instruction encountered!\n";
return true; return true;
case 1: break; case 1: break;
case 2: Params.push_back(getValue(*It++, Raw.Arg2)); break; case 2: Params.push_back(getValue(*It++, Raw.Arg2)); break;
@ -245,7 +243,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
default: default:
Params.push_back(getValue(*It++, Raw.Arg2)); Params.push_back(getValue(*It++, Raw.Arg2));
{ {
vector<unsigned> &args = *Raw.VarArgs; std::vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0; i < args.size(); i++) { for (unsigned i = 0; i < args.size(); i++) {
if (It == PL.end()) return true; if (It == PL.end()) return true;
// TODO: Check getValue for null! // TODO: Check getValue for null!
@ -257,7 +255,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
if (It != PL.end()) return true; if (It != PL.end()) return true;
} else { } else {
if (Raw.NumOperands > 2) { if (Raw.NumOperands > 2) {
vector<unsigned> &args = *Raw.VarArgs; std::vector<unsigned> &args = *Raw.VarArgs;
if (args.size() < 1) return true; if (args.size() < 1) return true;
if ((args.size() & 1) != 0) if ((args.size() & 1) != 0)
@ -288,9 +286,9 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
const FunctionType *MTy = dyn_cast<FunctionType>(PTy->getElementType()); const FunctionType *MTy = dyn_cast<FunctionType>(PTy->getElementType());
if (MTy == 0) return true; if (MTy == 0) return true;
vector<Value *> Params; std::vector<Value *> Params;
const FunctionType::ParamTypes &PL = MTy->getParamTypes(); const FunctionType::ParamTypes &PL = MTy->getParamTypes();
vector<unsigned> &args = *Raw.VarArgs; std::vector<unsigned> &args = *Raw.VarArgs;
BasicBlock *Normal, *Except; BasicBlock *Normal, *Except;
@ -352,12 +350,12 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
case Instruction::Load: case Instruction::Load:
case Instruction::GetElementPtr: { case Instruction::GetElementPtr: {
vector<Value*> Idx; std::vector<Value*> Idx;
if (!isa<PointerType>(Raw.Ty)) return true; if (!isa<PointerType>(Raw.Ty)) return true;
const CompositeType *TopTy = dyn_cast<CompositeType>(Raw.Ty); const CompositeType *TopTy = dyn_cast<CompositeType>(Raw.Ty);
switch (Raw.NumOperands) { switch (Raw.NumOperands) {
case 0: cerr << "Invalid load encountered!\n"; return true; case 0: std::cerr << "Invalid load encountered!\n"; return true;
case 1: break; case 1: break;
case 2: case 2:
if (!TopTy) return true; if (!TopTy) return true;
@ -382,7 +380,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
Idx.push_back(V = getValue(TopTy->getIndexType(), Raw.Arg2)); Idx.push_back(V = getValue(TopTy->getIndexType(), Raw.Arg2));
if (!V) return true; if (!V) return true;
vector<unsigned> &args = *Raw.VarArgs; std::vector<unsigned> &args = *Raw.VarArgs;
for (unsigned i = 0, E = args.size(); i != E; ++i) { for (unsigned i = 0, E = args.size(); i != E; ++i) {
const Type *ETy = GetElementPtrInst::getIndexedType(Raw.Ty, Idx, true); const Type *ETy = GetElementPtrInst::getIndexedType(Raw.Ty, Idx, true);
const CompositeType *ElTy = dyn_cast_or_null<CompositeType>(ETy); const CompositeType *ElTy = dyn_cast_or_null<CompositeType>(ETy);
@ -397,8 +395,8 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
if (Raw.Opcode == Instruction::Load) { if (Raw.Opcode == Instruction::Load) {
Value *Src = getValue(Raw.Ty, Raw.Arg1); Value *Src = getValue(Raw.Ty, Raw.Arg1);
if (!Idx.empty()) { if (!Idx.empty()) {
cerr << "WARNING: Bytecode contains load instruction with indices. " std::cerr << "WARNING: Bytecode contains load instruction with indices."
<< "Replacing with getelementptr/load pair\n"; << " Replacing with getelementptr/load pair\n";
assert(GetElementPtrInst::getIndexedType(Raw.Ty, Idx) && assert(GetElementPtrInst::getIndexedType(Raw.Ty, Idx) &&
"Bad indices for Load!"); "Bad indices for Load!");
Src = new GetElementPtrInst(Src, Idx); Src = new GetElementPtrInst(Src, Idx);
@ -414,13 +412,13 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
return false; return false;
} }
case Instruction::Store: { case Instruction::Store: {
vector<Value*> Idx; std::vector<Value*> Idx;
if (!isa<PointerType>(Raw.Ty)) return true; if (!isa<PointerType>(Raw.Ty)) return true;
const CompositeType *TopTy = dyn_cast<CompositeType>(Raw.Ty); const CompositeType *TopTy = dyn_cast<CompositeType>(Raw.Ty);
switch (Raw.NumOperands) { switch (Raw.NumOperands) {
case 0: case 0:
case 1: cerr << "Invalid store encountered!\n"; return true; case 1: std::cerr << "Invalid store encountered!\n"; return true;
case 2: break; case 2: break;
case 3: case 3:
if (!TopTy) return true; if (!TopTy) return true;
@ -428,7 +426,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
if (!V) return true; if (!V) return true;
break; break;
default: default:
vector<unsigned> &args = *Raw.VarArgs; std::vector<unsigned> &args = *Raw.VarArgs;
const CompositeType *ElTy = TopTy; const CompositeType *ElTy = TopTy;
unsigned i, E; unsigned i, E;
for (i = 0, E = args.size(); ElTy && i != E; ++i) { for (i = 0, E = args.size(); ElTy && i != E; ++i) {
@ -447,8 +445,8 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
Value *Ptr = getValue(Raw.Ty, Raw.Arg2); Value *Ptr = getValue(Raw.Ty, Raw.Arg2);
if (!Idx.empty()) { if (!Idx.empty()) {
cerr << "WARNING: Bytecode contains load instruction with indices. " std::cerr << "WARNING: Bytecode contains load instruction with indices. "
<< "Replacing with getelementptr/load pair\n"; << "Replacing with getelementptr/load pair\n";
const Type *ElType = GetElementPtrInst::getIndexedType(Raw.Ty, Idx); const Type *ElType = GetElementPtrInst::getIndexedType(Raw.Ty, Idx);
if (ElType == 0) return true; if (ElType == 0) return true;
@ -465,7 +463,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
} }
} // end switch(Raw.Opcode) } // end switch(Raw.Opcode)
cerr << "Unrecognized instruction! " << Raw.Opcode std::cerr << "Unrecognized instruction! " << Raw.Opcode
<< " ADDR = 0x" << (void*)Buf << "\n"; << " ADDR = 0x" << (void*)Buf << "\n";
return true; return true;
} }

View File

@ -23,9 +23,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <algorithm> #include <algorithm>
using std::cerr;
using std::pair;
using std::make_pair;
bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) { bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) {
if (Ty->isPrimitiveType()) { if (Ty->isPrimitiveType()) {
@ -115,8 +112,8 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) {
Value *d = 0; Value *d = 0;
switch (Ty->getPrimitiveID()) { switch (Ty->getPrimitiveID()) {
case Type::FunctionTyID: case Type::FunctionTyID:
cerr << "Creating method pholder! : " << type << ":" << oNum << " " std::cerr << "Creating method pholder! : " << type << ":" << oNum << " "
<< Ty->getName() << "\n"; << Ty->getName() << "\n";
d = new FunctionPHolder(Ty, oNum); d = new FunctionPHolder(Ty, oNum);
if (insertValue(d, LateResolveModuleValues) == -1) return 0; if (insertValue(d, LateResolveModuleValues) == -1) return 0;
return d; return d;
@ -143,7 +140,7 @@ Constant *BytecodeParser::getConstantValue(const Type *Ty, unsigned Slot) {
if (Value *V = getValue(Ty, Slot, false)) if (Value *V = getValue(Ty, Slot, false))
return dyn_cast<Constant>(V); // If we already have the value parsed... return dyn_cast<Constant>(V); // If we already have the value parsed...
GlobalRefsType::iterator I = GlobalRefs.find(make_pair(Ty, Slot)); GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(Ty, Slot));
if (I != GlobalRefs.end()) { if (I != GlobalRefs.end()) {
BCR_TRACE(5, "Previous forward ref found!\n"); BCR_TRACE(5, "Previous forward ref found!\n");
return cast<Constant>(I->second); return cast<Constant>(I->second);
@ -154,7 +151,7 @@ Constant *BytecodeParser::getConstantValue(const Type *Ty, unsigned Slot) {
Constant *C = new ConstPHolder(Ty, Slot); Constant *C = new ConstPHolder(Ty, Slot);
// Keep track of the fact that we have a forward ref to recycle it // Keep track of the fact that we have a forward ref to recycle it
GlobalRefs.insert(make_pair(make_pair(Ty, Slot), C)); GlobalRefs.insert(std::make_pair(std::make_pair(Ty, Slot), C));
return C; return C;
} }
} }
@ -175,8 +172,8 @@ bool BytecodeParser::postResolveValues(ValueTable &ValTab) {
Value *NewDef = getValue(D->getType(), IDNumber, false); Value *NewDef = getValue(D->getType(), IDNumber, false);
if (NewDef == 0) { if (NewDef == 0) {
Error = true; // Unresolved thinger Error = true; // Unresolved thinger
cerr << "Unresolvable reference found: <" std::cerr << "Unresolvable reference found: <"
<< D->getType()->getDescription() << ">:" << IDNumber << "!\n"; << D->getType()->getDescription() << ">:" << IDNumber <<"!\n";
} else { } else {
// Fixup all of the uses of this placeholder def... // Fixup all of the uses of this placeholder def...
D->replaceAllUsesWith(NewDef); D->replaceAllUsesWith(NewDef);
@ -241,7 +238,7 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf,
return true; return true;
} }
BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D; BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D;
if (!isa<Instruction>(D)) cerr << "\n"); if (!isa<Instruction>(D)) std::cerr << "\n");
D->setName(Name, ST); D->setName(Name, ST);
} }
@ -252,7 +249,8 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf,
} }
void BytecodeParser::ResolveReferencesToValue(Value *NewV, unsigned Slot) { void BytecodeParser::ResolveReferencesToValue(Value *NewV, unsigned Slot) {
GlobalRefsType::iterator I = GlobalRefs.find(make_pair(NewV->getType(),Slot)); GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(NewV->getType(),
Slot));
if (I == GlobalRefs.end()) return; // Never forward referenced? if (I == GlobalRefs.end()) return; // Never forward referenced?
BCR_TRACE(3, "Mutating forward refs!\n"); BCR_TRACE(3, "Mutating forward refs!\n");
@ -476,7 +474,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
// methods are loaded... // methods are loaded...
// //
FunctionSignatureList.push_back( FunctionSignatureList.push_back(
make_pair(cast<const PointerType>(Val->getType()), SlotNo)); std::make_pair(cast<const PointerType>(Val->getType()), SlotNo));
if (read_vbr(Buf, End, FnSignature)) return true; if (read_vbr(Buf, End, FnSignature)) return true;
BCR_TRACE(2, "Function of type: " << Ty << "\n"); BCR_TRACE(2, "Function of type: " << Ty << "\n");
} }