diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index d3ae9027a7d..533274a6d83 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -449,7 +449,7 @@ std::ostream &llvm::WriteAsOperand(std::ostream &Out, const Value *V, namespace llvm { class AssemblyWriter { - std::ostream &Out; + std::ostream *Out; SlotCalculator &Table; const Module *TheModule; std::map TypeNames; @@ -457,7 +457,7 @@ class AssemblyWriter { public: inline AssemblyWriter(std::ostream &o, SlotCalculator &Tab, const Module *M, AssemblyAnnotationWriter *AAW) - : Out(o), Table(Tab), TheModule(M), AnnotationWriter(AAW) { + : Out(&o), Table(Tab), TheModule(M), AnnotationWriter(AAW) { // If the module has a symbol table, take all global types and stuff their // names into the TypeNames map. @@ -476,6 +476,7 @@ public: void writeOperand(const Value *Op, bool PrintType, bool PrintName = true); const Module* getModule() { return TheModule; } + void setStream(std::ostream &os) { Out = &os; } private : void printModule(const Module *M); @@ -491,7 +492,7 @@ private : // symbolic version of a type name. // std::ostream &printType(const Type *Ty) { - return printTypeInt(Out, Ty, TypeNames); + return printTypeInt(*Out, Ty, TypeNames); } // printTypeAtLeastOneLevel - Print out one level of the possibly complex type @@ -514,55 +515,55 @@ std::ostream &AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) { for (FunctionType::param_iterator I = FTy->param_begin(), E = FTy->param_end(); I != E; ++I) { if (I != FTy->param_begin()) - Out << ", "; + *Out << ", "; printType(*I); } if (FTy->isVarArg()) { - if (FTy->getNumParams()) Out << ", "; - Out << "..."; + if (FTy->getNumParams()) *Out << ", "; + *Out << "..."; } - Out << ")"; + *Out << ")"; } else if (const StructType *STy = dyn_cast(Ty)) { - Out << "{ "; + *Out << "{ "; for (StructType::element_iterator I = STy->element_begin(), E = STy->element_end(); I != E; ++I) { if (I != STy->element_begin()) - Out << ", "; + *Out << ", "; printType(*I); } - Out << " }"; + *Out << " }"; } else if (const PointerType *PTy = dyn_cast(Ty)) { printType(PTy->getElementType()) << "*"; } else if (const ArrayType *ATy = dyn_cast(Ty)) { - Out << "[" << ATy->getNumElements() << " x "; + *Out << "[" << ATy->getNumElements() << " x "; printType(ATy->getElementType()) << "]"; } else if (const OpaqueType *OTy = dyn_cast(Ty)) { - Out << "opaque"; + *Out << "opaque"; } else { if (!Ty->isPrimitiveType()) - Out << ""; + *Out << ""; printType(Ty); } - return Out; + return *Out; } void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType, bool PrintName) { - if (PrintType) { Out << " "; printType(Operand->getType()); } - WriteAsOperandInternal(Out, Operand, PrintName, TypeNames, &Table); + if (PrintType) { *Out << " "; printType(Operand->getType()); } + WriteAsOperandInternal(*Out, Operand, PrintName, TypeNames, &Table); } void AssemblyWriter::printModule(const Module *M) { switch (M->getEndianness()) { - case Module::LittleEndian: Out << "target endian = little\n"; break; - case Module::BigEndian: Out << "target endian = big\n"; break; + case Module::LittleEndian: *Out << "target endian = little\n"; break; + case Module::BigEndian: *Out << "target endian = big\n"; break; case Module::AnyEndianness: break; } switch (M->getPointerSize()) { - case Module::Pointer32: Out << "target pointersize = 32\n"; break; - case Module::Pointer64: Out << "target pointersize = 64\n"; break; + case Module::Pointer32: *Out << "target pointersize = 32\n"; break; + case Module::Pointer64: *Out << "target pointersize = 64\n"; break; case Module::AnyPointerSize: break; } @@ -572,7 +573,7 @@ void AssemblyWriter::printModule(const Module *M) { for (Module::const_giterator I = M->gbegin(), E = M->gend(); I != E; ++I) printGlobal(I); - Out << "\nimplementation ; Functions:\n"; + *Out << "\nimplementation ; Functions:\n"; // Output all of the functions... for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) @@ -580,27 +581,27 @@ void AssemblyWriter::printModule(const Module *M) { } void AssemblyWriter::printGlobal(const GlobalVariable *GV) { - if (GV->hasName()) Out << getLLVMName(GV->getName()) << " = "; + if (GV->hasName()) *Out << getLLVMName(GV->getName()) << " = "; if (!GV->hasInitializer()) - Out << "external "; + *Out << "external "; else switch (GV->getLinkage()) { - case GlobalValue::InternalLinkage: Out << "internal "; break; - case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break; - case GlobalValue::WeakLinkage: Out << "weak "; break; - case GlobalValue::AppendingLinkage: Out << "appending "; break; + case GlobalValue::InternalLinkage: *Out << "internal "; break; + case GlobalValue::LinkOnceLinkage: *Out << "linkonce "; break; + case GlobalValue::WeakLinkage: *Out << "weak "; break; + case GlobalValue::AppendingLinkage: *Out << "appending "; break; case GlobalValue::ExternalLinkage: break; } - Out << (GV->isConstant() ? "constant " : "global "); + *Out << (GV->isConstant() ? "constant " : "global "); printType(GV->getType()->getElementType()); if (GV->hasInitializer()) writeOperand(GV->getInitializer(), false, false); printInfoComment(*GV); - Out << "\n"; + *Out << "\n"; } @@ -618,7 +619,7 @@ void AssemblyWriter::printSymbolTable(const SymbolTable &ST) { printConstant(CPV); } else if (const Type *Ty = dyn_cast(V)) { assert(Ty->getType() == Type::TypeTy && TI->first == Type::TypeTy); - Out << "\t" << getLLVMName(I->first) << " = type "; + *Out << "\t" << getLLVMName(I->first) << " = type "; // Make sure we print out at least one level of the type structure, so // that we do not get %FILE = type %FILE @@ -637,40 +638,40 @@ void AssemblyWriter::printConstant(const Constant *CPV) { if (!CPV->hasName()) return; // Print out name... - Out << "\t" << getLLVMName(CPV->getName()) << " ="; + *Out << "\t" << getLLVMName(CPV->getName()) << " ="; // Write the value out now... writeOperand(CPV, true, false); printInfoComment(*CPV); - Out << "\n"; + *Out << "\n"; } /// printFunction - Print all aspects of a function. /// void AssemblyWriter::printFunction(const Function *F) { // Print out the return type and name... - Out << "\n"; + *Out << "\n"; - if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out); + if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, *Out); if (F->isExternal()) - Out << "declare "; + *Out << "declare "; else switch (F->getLinkage()) { - case GlobalValue::InternalLinkage: Out << "internal "; break; - case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break; - case GlobalValue::WeakLinkage: Out << "weak "; break; - case GlobalValue::AppendingLinkage: Out << "appending "; break; + case GlobalValue::InternalLinkage: *Out << "internal "; break; + case GlobalValue::LinkOnceLinkage: *Out << "linkonce "; break; + case GlobalValue::WeakLinkage: *Out << "weak "; break; + case GlobalValue::AppendingLinkage: *Out << "appending "; break; case GlobalValue::ExternalLinkage: break; } printType(F->getReturnType()) << " "; if (!F->getName().empty()) - Out << getLLVMName(F->getName()); + *Out << getLLVMName(F->getName()); else - Out << "\"\""; - Out << "("; + *Out << "\"\""; + *Out << "("; Table.incorporateFunction(F); // Loop over the arguments, printing them... @@ -681,21 +682,21 @@ void AssemblyWriter::printFunction(const Function *F) { // Finish printing arguments... if (FT->isVarArg()) { - if (FT->getNumParams()) Out << ", "; - Out << "..."; // Output varargs portion of signature! + if (FT->getNumParams()) *Out << ", "; + *Out << "..."; // Output varargs portion of signature! } - Out << ")"; + *Out << ")"; if (F->isExternal()) { - Out << "\n"; + *Out << "\n"; } else { - Out << " {"; + *Out << " {"; // Output all of its basic blocks... for the function for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I) printBasicBlock(I); - Out << "}\n"; + *Out << "}\n"; } Table.purgeFunction(); @@ -706,62 +707,62 @@ void AssemblyWriter::printFunction(const Function *F) { /// void AssemblyWriter::printArgument(const Argument *Arg) { // Insert commas as we go... the first arg doesn't get a comma - if (Arg != &Arg->getParent()->afront()) Out << ", "; + if (Arg != &Arg->getParent()->afront()) *Out << ", "; // Output type... printType(Arg->getType()); // Output name, if available... if (Arg->hasName()) - Out << " " << getLLVMName(Arg->getName()); + *Out << " " << getLLVMName(Arg->getName()); else if (Table.getSlot(Arg) < 0) - Out << ""; + *Out << ""; } /// printBasicBlock - This member is called for each basic block in a method. /// void AssemblyWriter::printBasicBlock(const BasicBlock *BB) { if (BB->hasName()) { // Print out the label if it exists... - Out << "\n" << BB->getName() << ":"; + *Out << "\n" << BB->getName() << ":"; } else if (!BB->use_empty()) { // Don't print block # of no uses... int Slot = Table.getSlot(BB); - Out << "\n;