1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

Change WriteTypeSymbolic/WriteAsOperand to return void instead of

an ostream, which is just weird.

Rename SC_DEBUG -> ST_DEBUG

Remove static indentation strangeness from WriteConstantInt.  This makes it 
so that large structs are not broken down and printed on multiple lines.  If
there is demand for this to return, there are better ways to implement this.

llvm-svn: 54981
This commit is contained in:
Chris Lattner 2008-08-19 04:47:09 +00:00
parent b4cfc1a85e
commit 6df4ed8bfd
2 changed files with 28 additions and 39 deletions

View File

@ -29,7 +29,7 @@ class Value;
// type, iff there is an entry in the Module's symbol table for the specified // type, iff there is an entry in the Module's symbol table for the specified
// type or one of its component types. This is slower than a simple x << Type; // type or one of its component types. This is slower than a simple x << Type;
// //
std::ostream &WriteTypeSymbolic(std::ostream &, const Type *, const Module *M); void WriteTypeSymbolic(std::ostream &, const Type *, const Module *M);
// WriteAsOperand - Write the name of the specified value out to the specified // WriteAsOperand - Write the name of the specified value out to the specified
// ostream. This can be useful when you just want to print int %reg126, not the // ostream. This can be useful when you just want to print int %reg126, not the
@ -37,8 +37,8 @@ std::ostream &WriteTypeSymbolic(std::ostream &, const Type *, const Module *M);
// then even constants get pretty-printed; for example, the type of a null // then even constants get pretty-printed; for example, the type of a null
// pointer is printed symbolically. // pointer is printed symbolically.
// //
std::ostream &WriteAsOperand(std::ostream &, const Value *, bool PrintTy = true, void WriteAsOperand(std::ostream &, const Value *, bool PrintTy = true,
const Module *Context = 0); const Module *Context = 0);
} // End llvm namespace } // End llvm namespace

View File

@ -295,9 +295,9 @@ static SlotTracker *createSlotTracker(const Value *V) {
} }
#if 0 #if 0
#define SC_DEBUG(X) cerr << X #define ST_DEBUG(X) cerr << X
#else #else
#define SC_DEBUG(X) #define ST_DEBUG(X)
#endif #endif
// Module level constructor. Causes the contents of the Module (sans functions) // Module level constructor. Causes the contents of the Module (sans functions)
@ -332,7 +332,7 @@ inline void SlotTracker::initialize() {
// Iterate through all the global variables, functions, and global // Iterate through all the global variables, functions, and global
// variable initializers and create slots for them. // variable initializers and create slots for them.
void SlotTracker::processModule() { void SlotTracker::processModule() {
SC_DEBUG("begin processModule!\n"); ST_DEBUG("begin processModule!\n");
// Add all of the unnamed global variables to the value table. // Add all of the unnamed global variables to the value table.
for (Module::const_global_iterator I = TheModule->global_begin(), for (Module::const_global_iterator I = TheModule->global_begin(),
@ -346,13 +346,13 @@ void SlotTracker::processModule() {
if (!I->hasName()) if (!I->hasName())
CreateModuleSlot(I); CreateModuleSlot(I);
SC_DEBUG("end processModule!\n"); ST_DEBUG("end processModule!\n");
} }
// Process the arguments, basic blocks, and instructions of a function. // Process the arguments, basic blocks, and instructions of a function.
void SlotTracker::processFunction() { void SlotTracker::processFunction() {
SC_DEBUG("begin processFunction!\n"); ST_DEBUG("begin processFunction!\n");
fNext = 0; fNext = 0;
// Add all the function arguments with no names. // Add all the function arguments with no names.
@ -361,7 +361,7 @@ void SlotTracker::processFunction() {
if (!AI->hasName()) if (!AI->hasName())
CreateFunctionSlot(AI); CreateFunctionSlot(AI);
SC_DEBUG("Inserting Instructions:\n"); ST_DEBUG("Inserting Instructions:\n");
// Add all of the basic blocks and instructions with no names. // Add all of the basic blocks and instructions with no names.
for (Function::const_iterator BB = TheFunction->begin(), for (Function::const_iterator BB = TheFunction->begin(),
@ -375,18 +375,18 @@ void SlotTracker::processFunction() {
FunctionProcessed = true; FunctionProcessed = true;
SC_DEBUG("end processFunction!\n"); ST_DEBUG("end processFunction!\n");
} }
/// Clean up after incorporating a function. This is the only way to get out of /// Clean up after incorporating a function. This is the only way to get out of
/// the function incorporation state that affects get*Slot/Create*Slot. Function /// the function incorporation state that affects get*Slot/Create*Slot. Function
/// incorporation state is indicated by TheFunction != 0. /// incorporation state is indicated by TheFunction != 0.
void SlotTracker::purgeFunction() { void SlotTracker::purgeFunction() {
SC_DEBUG("begin purgeFunction!\n"); ST_DEBUG("begin purgeFunction!\n");
fMap.clear(); // Simply discard the function level map fMap.clear(); // Simply discard the function level map
TheFunction = 0; TheFunction = 0;
FunctionProcessed = false; FunctionProcessed = false;
SC_DEBUG("end purgeFunction!\n"); ST_DEBUG("end purgeFunction!\n");
} }
/// getGlobalSlot - Get the slot number of a global value. /// getGlobalSlot - Get the slot number of a global value.
@ -421,10 +421,10 @@ void SlotTracker::CreateModuleSlot(const GlobalValue *V) {
unsigned DestSlot = mNext++; unsigned DestSlot = mNext++;
mMap[V] = DestSlot; mMap[V] = DestSlot;
SC_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" << ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
DestSlot << " ["); DestSlot << " [");
// G = Global, F = Function, A = Alias, o = other // G = Global, F = Function, A = Alias, o = other
SC_DEBUG((isa<GlobalVariable>(V) ? 'G' : ST_DEBUG((isa<GlobalVariable>(V) ? 'G' :
(isa<Function>(V) ? 'F' : (isa<Function>(V) ? 'F' :
(isa<GlobalAlias>(V) ? 'A' : 'o'))) << "]\n"); (isa<GlobalAlias>(V) ? 'A' : 'o'))) << "]\n");
} }
@ -439,7 +439,7 @@ void SlotTracker::CreateFunctionSlot(const Value *V) {
fMap[V] = DestSlot; fMap[V] = DestSlot;
// G = Global, F = Function, o = other // G = Global, F = Function, o = other
SC_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" << ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<
DestSlot << " [o]\n"); DestSlot << " [o]\n");
} }
@ -618,18 +618,19 @@ static std::ostream &printTypeInt(std::ostream &Out, const Type *Ty,
/// type, iff there is an entry in the modules symbol table for the specified /// type, iff there is an entry in the modules symbol table for the specified
/// type or one of it's component types. This is slower than a simple x << Type /// type or one of it's component types. This is slower than a simple x << Type
/// ///
std::ostream &llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty, void llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty,
const Module *M) { const Module *M) {
Out << ' '; Out << ' ';
// If they want us to print out a type, but there is no context, we can't // If they want us to print out a type, but there is no context, we can't
// print it symbolically. // print it symbolically.
if (!M) if (!M) {
return Out << Ty->getDescription(); Out << Ty->getDescription();
} else {
std::map<const Type *, std::string> TypeNames; std::map<const Type *, std::string> TypeNames;
fillTypeNameTable(M, TypeNames); fillTypeNameTable(M, TypeNames);
return printTypeInt(Out, Ty, TypeNames); printTypeInt(Out, Ty, TypeNames);
}
} }
// PrintEscapedString - Print each character of the specified string, escaping // PrintEscapedString - Print each character of the specified string, escaping
@ -683,9 +684,6 @@ static const char *getPredicateText(unsigned predicate) {
static void WriteConstantInt(std::ostream &Out, const Constant *CV, static void WriteConstantInt(std::ostream &Out, const Constant *CV,
std::map<const Type *, std::string> &TypeTable, std::map<const Type *, std::string> &TypeTable,
SlotTracker *Machine) { SlotTracker *Machine) {
const int IndentSize = 4;
// FIXME: WHY IS INDENT STATIC??
static std::string Indent = "\n";
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
if (CI->getType() == Type::Int1Ty) { if (CI->getType() == Type::Int1Ty) {
Out << (CI->getZExtValue() ? "true" : "false"); Out << (CI->getZExtValue() ? "true" : "false");
@ -791,24 +789,17 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
Out << '{'; Out << '{';
unsigned N = CS->getNumOperands(); unsigned N = CS->getNumOperands();
if (N) { if (N) {
if (N > 2) { Out << ' ';
Indent += std::string(IndentSize, ' ');
Out << Indent;
} else {
Out << ' ';
}
printTypeInt(Out, CS->getOperand(0)->getType(), TypeTable); printTypeInt(Out, CS->getOperand(0)->getType(), TypeTable);
WriteAsOperandInternal(Out, CS->getOperand(0), TypeTable, Machine); WriteAsOperandInternal(Out, CS->getOperand(0), TypeTable, Machine);
for (unsigned i = 1; i < N; i++) { for (unsigned i = 1; i < N; i++) {
Out << ", "; Out << ", ";
if (N > 2) Out << Indent;
printTypeInt(Out, CS->getOperand(i)->getType(), TypeTable); printTypeInt(Out, CS->getOperand(i)->getType(), TypeTable);
WriteAsOperandInternal(Out, CS->getOperand(i), TypeTable, Machine); WriteAsOperandInternal(Out, CS->getOperand(i), TypeTable, Machine);
} }
if (N > 2) Indent.resize(Indent.size() - IndentSize);
} }
Out << " }"; Out << " }";
@ -818,8 +809,7 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
const Type *ETy = CP->getType()->getElementType(); const Type *ETy = CP->getType()->getElementType();
assert(CP->getNumOperands() > 0 && assert(CP->getNumOperands() > 0 &&
"Number of operands for a PackedConst must be > 0"); "Number of operands for a PackedConst must be > 0");
Out << '<'; Out << "< ";
Out << ' ';
printTypeInt(Out, ETy, TypeTable); printTypeInt(Out, ETy, TypeTable);
WriteAsOperandInternal(Out, CP->getOperand(0), TypeTable, Machine); WriteAsOperandInternal(Out, CP->getOperand(0), TypeTable, Machine);
for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) { for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {
@ -926,8 +916,8 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
/// ostream. This can be useful when you just want to print int %reg126, not /// ostream. This can be useful when you just want to print int %reg126, not
/// the whole instruction that generated it. /// the whole instruction that generated it.
/// ///
std::ostream &llvm::WriteAsOperand(std::ostream &Out, const Value *V, void llvm::WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType,
bool PrintType, const Module *Context) { const Module *Context) {
std::map<const Type *, std::string> TypeNames; std::map<const Type *, std::string> TypeNames;
if (Context == 0) Context = getModuleFromVal(V); if (Context == 0) Context = getModuleFromVal(V);
@ -938,7 +928,6 @@ std::ostream &llvm::WriteAsOperand(std::ostream &Out, const Value *V,
printTypeInt(Out, V->getType(), TypeNames); printTypeInt(Out, V->getType(), TypeNames);
WriteAsOperandInternal(Out, V, TypeNames, 0); WriteAsOperandInternal(Out, V, TypeNames, 0);
return Out;
} }