diff options
author | Bill Wendling <isanbard@gmail.com> | 2006-11-29 00:19:40 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2006-11-29 00:19:40 +0000 |
commit | 68fe61d6a165ea6090008e281330895a21607daf (patch) | |
tree | 2e0cc1cbd16099aed908dbb3ecda16cf57d04300 | |
parent | a5b31ca85686062408bca0f0a8aa43f9fe58e644 (diff) |
Replacing std::iostreams with llvm iostreams. Some of these changes involve
adding a temporary wrapper around the ostream to make it friendly to
functions expecting an LLVM stream. This should be fixed in the future.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31990 91177308-0d34-0410-b5e6-96231b3b80d8
25 files changed, 217 insertions, 179 deletions
diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp index 2ec5437c36..30f63bb8f4 100644 --- a/examples/ModuleMaker/ModuleMaker.cpp +++ b/examples/ModuleMaker/ModuleMaker.cpp @@ -18,8 +18,7 @@ #include "llvm/Constants.h" #include "llvm/Instructions.h" #include "llvm/Bytecode/Writer.h" -#include <iostream> - +#include "llvm/Support/Streams.h" using namespace llvm; int main() { @@ -54,7 +53,7 @@ int main() { BB->getInstList().push_back(new ReturnInst(Add)); // Output the bytecode file to stdout - WriteBytecodeToFile(M, std::cout); + WriteBytecodeToFile(M, llvm_cout); // Delete the module and all of its contents. delete M; diff --git a/include/llvm/Analysis/CallGraph.h b/include/llvm/Analysis/CallGraph.h index b567bab474..f29aef3a22 100644 --- a/include/llvm/Analysis/CallGraph.h +++ b/include/llvm/Analysis/CallGraph.h @@ -152,6 +152,9 @@ public: /// void initialize(Module &M); + void print(llvm_ostream &o, const Module *M) const { + if (o.stream()) print(*o.stream(), M); + } virtual void print(std::ostream &o, const Module *M) const; void dump() const; @@ -198,6 +201,9 @@ public: /// dump - Print out this call graph node. /// void dump() const; + void print(llvm_ostream &OS) const { + if (OS.stream()) print(*OS.stream()); + } void print(std::ostream &OS) const; //===--------------------------------------------------------------------- diff --git a/include/llvm/Bytecode/WriteBytecodePass.h b/include/llvm/Bytecode/WriteBytecodePass.h index 198cc02629..a634812498 100644 --- a/include/llvm/Bytecode/WriteBytecodePass.h +++ b/include/llvm/Bytecode/WriteBytecodePass.h @@ -17,18 +17,19 @@ #include "llvm/Pass.h" #include "llvm/Bytecode/Writer.h" -#include <iostream> namespace llvm { +class llvm_ostream; + class WriteBytecodePass : public ModulePass { - std::ostream *Out; // ostream to print on + llvm_ostream *Out; // ostream to print on bool DeleteStream; bool CompressFile; public: WriteBytecodePass() - : Out(&std::cout), DeleteStream(false), CompressFile(true) {} - WriteBytecodePass(std::ostream *o, bool DS = false, bool CF = true) + : Out(&llvm_cout), DeleteStream(false), CompressFile(true) {} + WriteBytecodePass(llvm_ostream *o, bool DS = false, bool CF = true) : Out(o), DeleteStream(DS), CompressFile(CF) {} inline ~WriteBytecodePass() { diff --git a/include/llvm/Bytecode/Writer.h b/include/llvm/Bytecode/Writer.h index 8b89226fa5..374e5df482 100644 --- a/include/llvm/Bytecode/Writer.h +++ b/include/llvm/Bytecode/Writer.h @@ -15,14 +15,13 @@ #ifndef LLVM_BYTECODE_WRITER_H #define LLVM_BYTECODE_WRITER_H -#include <iosfwd> - namespace llvm { + class llvm_ostream; class Module; /// WriteBytecodeToFile - Write the specified module to the specified output /// stream. If compress is set to true, try to use compression when writing /// out the file. This can never fail if M is a well-formed module. - void WriteBytecodeToFile(const Module *M, std::ostream &Out, + void WriteBytecodeToFile(const Module *M, llvm_ostream &Out, bool compress = true); } // End llvm namespace diff --git a/include/llvm/CodeGen/Passes.h b/include/llvm/CodeGen/Passes.h index adccf531eb..4d27e541d7 100644 --- a/include/llvm/CodeGen/Passes.h +++ b/include/llvm/CodeGen/Passes.h @@ -70,6 +70,11 @@ namespace llvm { /// FunctionPass *createLinearScanRegisterAllocator(); + /// PriorityBasedGraphColoringRegisterAllocator Pass - This pass implements + /// the priority-based graph coloring register allocator by Chow & Hennessey, + /// a global register allocator. + FunctionPass *createGraphColoringRegisterAllocator(); + /// PrologEpilogCodeInserter Pass - This pass inserts prolog and epilog code, /// and eliminates abstract frame references. /// diff --git a/include/llvm/Support/Streams.h b/include/llvm/Support/Streams.h index 8048d56e70..a422756c63 100644 --- a/include/llvm/Support/Streams.h +++ b/include/llvm/Support/Streams.h @@ -43,6 +43,7 @@ namespace llvm { } bool operator == (const std::ostream &OS) { return &OS == Stream; } + bool operator == (const llvm_ostream &OS) { return OS.Stream == Stream; } }; extern llvm_ostream llvm_null; diff --git a/lib/Analysis/DataStructure/Local.cpp b/lib/Analysis/DataStructure/Local.cpp index 34947371c6..436218be9e 100644 --- a/lib/Analysis/DataStructure/Local.cpp +++ b/lib/Analysis/DataStructure/Local.cpp @@ -24,7 +24,6 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Timer.h" -#include <iostream> // FIXME: This should eventually be a FunctionPass that is automatically // aggregated into a Pass. @@ -435,7 +434,7 @@ void GraphBuilder::visitGetElementPtrInst(User &GEP) { // Variable index into a node. We must merge all of the elements of the // sequential type here. if (isa<PointerType>(STy)) - std::cerr << "Pointer indexing not handled yet!\n"; + llvm_cerr << "Pointer indexing not handled yet!\n"; else { const ArrayType *ATy = cast<ArrayType>(STy); unsigned ElSize = TD.getTypeSize(CurTy); @@ -1062,7 +1061,7 @@ void GraphBuilder::visitCallSite(CallSite CS) { if (DisableDirectCallOpt || !isa<Function>(Callee)) { CalleeNode = getValueDest(*Callee).getNode(); if (CalleeNode == 0) { - std::cerr << "WARNING: Program is calling through a null pointer?\n"<< *I; + llvm_cerr << "WARNING: Program is calling through a null pointer?\n"<< *I; return; // Calling a null pointer? } } diff --git a/lib/Analysis/DataStructure/Printer.cpp b/lib/Analysis/DataStructure/Printer.cpp index b425e4e472..ef3ed75555 100644 --- a/lib/Analysis/DataStructure/Printer.cpp +++ b/lib/Analysis/DataStructure/Printer.cpp @@ -19,9 +19,10 @@ #include "llvm/Assembly/Writer.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/GraphWriter.h" +#include "llvm/Support/Streams.h" #include "llvm/ADT/Statistic.h" #include "llvm/Config/config.h" -#include <iostream> +#include <ostream> #include <fstream> #include <sstream> using namespace llvm; @@ -36,7 +37,7 @@ namespace { Statistic<> NumFoldedNodes ("dsa", "Number of folded nodes (in final graph)"); } -void DSNode::dump() const { print(std::cerr, 0); } +void DSNode::dump() const { print(llvm_cerr, 0); } static std::string getCaption(const DSNode *N, const DSGraph *G) { std::stringstream OS; diff --git a/lib/Analysis/DataStructure/Steensgaard.cpp b/lib/Analysis/DataStructure/Steensgaard.cpp index eb5b74ca02..292dfffa0d 100644 --- a/lib/Analysis/DataStructure/Steensgaard.cpp +++ b/lib/Analysis/DataStructure/Steensgaard.cpp @@ -20,7 +20,7 @@ #include "llvm/Analysis/Passes.h" #include "llvm/Module.h" #include "llvm/Support/Debug.h" -#include <iostream> +#include <ostream> using namespace llvm; namespace { @@ -53,6 +53,9 @@ namespace { } // print - Implement the Pass::print method... + void print(llvm_ostream O, const Module *M) const { + if (O.stream()) print(*O.stream(), M); + } void print(std::ostream &O, const Module *M) const { assert(ResultGraph && "Result graph has not yet been computed!"); ResultGraph->writeGraphToFile(O, "steensgaards"); @@ -188,7 +191,7 @@ bool Steens::runOnModule(Module &M) { // FIXME: We should be able to disable the globals graph for steens! //ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals); - DEBUG(print(std::cerr, &M)); + print(DOUT, &M); return false; } diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp index 73aa231e21..54e2944b95 100644 --- a/lib/Analysis/IPA/Andersens.cpp +++ b/lib/Analysis/IPA/Andersens.cpp @@ -62,7 +62,6 @@ #include "llvm/Support/Debug.h" #include "llvm/ADT/Statistic.h" #include <set> -#include <iostream> using namespace llvm; namespace { @@ -534,7 +533,7 @@ Andersens::Node *Andersens::getNodeForConstantPointer(Constant *C) { case Instruction::BitCast: return getNodeForConstantPointer(CE->getOperand(0)); default: - std::cerr << "Constant Expr not yet handled: " << *CE << "\n"; + llvm_cerr << "Constant Expr not yet handled: " << *CE << "\n"; assert(0); } } else { @@ -561,7 +560,7 @@ Andersens::Node *Andersens::getNodeForConstantPointerTarget(Constant *C) { case Instruction::BitCast: return getNodeForConstantPointerTarget(CE->getOperand(0)); default: - std::cerr << "Constant Expr not yet handled: " << *CE << "\n"; + llvm_cerr << "Constant Expr not yet handled: " << *CE << "\n"; assert(0); } } else { @@ -787,7 +786,7 @@ void Andersens::visitInstruction(Instruction &I) { return; default: // Is this something we aren't handling yet? - std::cerr << "Unknown instruction: " << I; + llvm_cerr << "Unknown instruction: " << I; abort(); } } @@ -1105,13 +1104,13 @@ void Andersens::SolveConstraints() { void Andersens::PrintNode(Node *N) { if (N == &GraphNodes[UniversalSet]) { - std::cerr << "<universal>"; + llvm_cerr << "<universal>"; return; } else if (N == &GraphNodes[NullPtr]) { - std::cerr << "<nullptr>"; + llvm_cerr << "<nullptr>"; return; } else if (N == &GraphNodes[NullObject]) { - std::cerr << "<null>"; + llvm_cerr << "<null>"; return; } @@ -1120,56 +1119,56 @@ void Andersens::PrintNode(Node *N) { if (Function *F = dyn_cast<Function>(V)) { if (isa<PointerType>(F->getFunctionType()->getReturnType()) && N == getReturnNode(F)) { - std::cerr << F->getName() << ":retval"; + llvm_cerr << F->getName() << ":retval"; return; } else if (F->getFunctionType()->isVarArg() && N == getVarargNode(F)) { - std::cerr << F->getName() << ":vararg"; + llvm_cerr << F->getName() << ":vararg"; return; } } if (Instruction *I = dyn_cast<Instruction>(V)) - std::cerr << I->getParent()->getParent()->getName() << ":"; + llvm_cerr << I->getParent()->getParent()->getName() << ":"; else if (Argument *Arg = dyn_cast<Argument>(V)) - std::cerr << Arg->getParent()->getName() << ":"; + llvm_cerr << Arg->getParent()->getName() << ":"; if (V->hasName()) - std::cerr << V->getName(); + llvm_cerr << V->getName(); else - std::cerr << "(unnamed)"; + llvm_cerr << "(unnamed)"; if (isa<GlobalValue>(V) || isa<AllocationInst>(V)) if (N == getObject(V)) - std::cerr << "<mem>"; + llvm_cerr << "<mem>"; } void Andersens::PrintConstraints() { - std::cerr << "Constraints:\n"; + llvm_cerr << "Constraints:\n"; for (unsigned i = 0, e = Constraints.size(); i != e; ++i) { - std::cerr << " #" << i << ": "; + llvm_cerr << " #" << i << ": "; Constraint &C = Constraints[i]; if (C.Type == Constraint::Store) - std::cerr << "*"; + llvm_cerr << "*"; PrintNode(C.Dest); - std::cerr << " = "; + llvm_cerr << " = "; if (C.Type == Constraint::Load) - std::cerr << "*"; + llvm_cerr << "*"; PrintNode(C.Src); - std::cerr << "\n"; + llvm_cerr << "\n"; } } void Andersens::PrintPointsToGraph() { - std::cerr << "Points-to graph:\n"; + llvm_cerr << "Points-to graph:\n"; for (unsigned i = 0, e = GraphNodes.size(); i != e; ++i) { Node *N = &GraphNodes[i]; - std::cerr << "[" << (N->end() - N->begin()) << "] "; + llvm_cerr << "[" << (N->end() - N->begin()) << "] "; PrintNode(N); - std::cerr << "\t--> "; + llvm_cerr << "\t--> "; for (Node::iterator I = N->begin(), E = N->end(); I != E; ++I) { - if (I != N->begin()) std::cerr << ", "; + if (I != N->begin()) llvm_cerr << ", "; PrintNode(*I); } - std::cerr << "\n"; + llvm_cerr << "\n"; } } diff --git a/lib/Analysis/IPA/CallGraph.cpp b/lib/Analysis/IPA/CallGraph.cpp index d9e7242695..9c22b7cc5e 100644 --- a/lib/Analysis/IPA/CallGraph.cpp +++ b/lib/Analysis/IPA/CallGraph.cpp @@ -16,7 +16,8 @@ #include "llvm/Module.h" #include "llvm/Instructions.h" #include "llvm/Support/CallSite.h" -#include <iostream> +#include "llvm/Support/Streams.h" +#include <ostream> using namespace llvm; static bool isOnlyADirectCall(Function *F, CallSite CS) { @@ -72,6 +73,10 @@ public: AU.setPreservesAll(); } + void print(llvm_ostream &o, const Module *M) const { + if (o.stream()) print(*o.stream(), M); + } + virtual void print(std::ostream &o, const Module *M) const { o << "CallGraph Root is: "; if (Function *F = getRoot()->getFunction()) @@ -89,7 +94,7 @@ public: /// dump - Print out this call graph. /// inline void dump() const { - print(std::cerr, Mod); + print(llvm_cerr, Mod); } CallGraphNode* getExternalCallingNode() const { return ExternalCallingNode; } @@ -207,7 +212,7 @@ void CallGraph::print(std::ostream &OS, const Module *M) const { } void CallGraph::dump() const { - print(std::cerr, 0); + print(llvm_cerr, 0); } //===----------------------------------------------------------------------===// @@ -270,7 +275,7 @@ void CallGraphNode::print(std::ostream &OS) const { OS << "\n"; } -void CallGraphNode::dump() const { print(std::cerr); } +void CallGraphNode::dump() const { print(llvm_cerr); } void CallGraphNode::removeCallEdgeTo(CallGraphNode *Callee) { for (unsigned i = CalledFunctions.size(); ; --i) { diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index b6d77b93ae..3865d5f7af 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -174,7 +174,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) { SCEVHandle IH = SCEVUnknown::get(I); // Get I as a "symbolic" SCEV. SCEVHandle V = S->evaluateAtIteration(IH); - //std::cerr << "Evaluated: " << *this << "\n to: " << *V << "\n"; + //llvm_cerr << "Evaluated: " << *this << "\n to: " << *V << "\n"; return expandInTy(V, Ty); } diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index 6ac295ca1c..efb6c436cd 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -31,8 +31,8 @@ using namespace llvm; #if 0 -#include <iostream> -#define SC_DEBUG(X) std::cerr << X +#include "llvm/Support/Streams.h" +#define SC_DEBUG(X) llvm_cerr << X #else #define SC_DEBUG(X) #endif @@ -800,7 +800,7 @@ int SlotCalculator::doInsertValue(const Value *D) { // Used for debugging DefSlot=-1 assertion... //if (Typ == Type::TypeTy) - // cerr << "Inserting type '" << cast<Type>(D)->getDescription() << "'!\n"; + // llvm_cerr << "Inserting type '"<<cast<Type>(D)->getDescription() <<"'!\n"; if (Typ->isDerivedType()) { int ValSlot; diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index f2ded65b07..d8bcce8208 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -29,6 +29,7 @@ #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/Compressor.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Program.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Statistic.h" @@ -275,7 +276,7 @@ void BytecodeWriter::outputType(const Type *T) { break; default: - std::cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize" + llvm_cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize" << " Type '" << T->getDescription() << "'\n"; break; } @@ -384,7 +385,7 @@ void BytecodeWriter::outputConstant(const Constant *CPV) { case Type::VoidTyID: case Type::LabelTyID: default: - std::cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize" + llvm_cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize" << " type '" << *CPV->getType() << "'\n"; break; } @@ -1225,13 +1226,13 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { } } -void llvm::WriteBytecodeToFile(const Module *M, std::ostream &Out, +void llvm::WriteBytecodeToFile(const Module *M, llvm_ostream &Out, bool compress) { assert(M && "You can't write a null module!!"); // Make sure that std::cout is put into binary mode for systems // that care. - if (&Out == std::cout) + if (Out == llvm_cout) sys::Program::ChangeStdoutToBinary(); // Create a vector of unsigned char for the bytecode output. We @@ -1264,21 +1265,21 @@ void llvm::WriteBytecodeToFile(const Module *M, std::ostream &Out, compressed_magic[2] = 'v'; compressed_magic[3] = 'c'; - Out.write(compressed_magic,4); + Out.stream()->write(compressed_magic,4); // Compress everything after the magic number (which we altered) Compressor::compressToStream( (char*)(FirstByte+4), // Skip the magic number Buffer.size()-4, // Skip the magic number - Out // Where to write compressed data + *Out.stream() // Where to write compressed data ); } else { // We're not compressing, so just write the entire block. - Out.write((char*)FirstByte, Buffer.size()); + Out.stream()->write((char*)FirstByte, Buffer.size()); } // make sure it hits disk now - Out.flush(); + Out.stream()->flush(); } diff --git a/projects/Stacker/tools/stkrc/stkrc.cpp b/projects/Stacker/tools/stkrc/stkrc.cpp index 727b044c20..f468330e62 100644 --- a/projects/Stacker/tools/stkrc/stkrc.cpp +++ b/projects/Stacker/tools/stkrc/stkrc.cpp @@ -22,11 +22,11 @@ #include "llvm/Bytecode/Writer.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Signals.h" #include <fstream> #include <iostream> #include <memory> - using namespace llvm; static cl::opt<std::string> @@ -115,7 +115,7 @@ int main(int argc, char **argv) } if (DumpAsm) - std::cerr << "Here's the assembly:" << M.get(); + llvm_cerr << "Here's the assembly:" << M.get(); if (OutputFilename != "") { // Specified an output filename? if (OutputFilename != "-") { // Not stdout? @@ -163,14 +163,15 @@ int main(int argc, char **argv) throw std::string("error opening ") + OutputFilename + "!"; } - WriteBytecodeToFile(M.get(), *Out); + llvm_ostream L(*Out); + WriteBytecodeToFile(M.get(), L); } catch (const ParseError &E) { - std::cerr << argv[0] << ": " << E.getMessage() << "\n"; + llvm_cerr << argv[0] << ": " << E.getMessage() << "\n"; return 1; } } catch (const std::string& msg ) { - std::cerr << argv[0] << ": " << msg << "\n"; + llvm_cerr << argv[0] << ": " << msg << "\n"; return 1; } diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index dddf7ceb61..0ec66baddf 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -27,6 +27,7 @@ #include "llvm/Target/TargetData.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Path.h" #include "llvm/System/Program.h" #include "llvm/Config/alloca.h" @@ -55,7 +56,8 @@ bool BugDriver::writeProgramToFile(const std::string &Filename, std::ofstream Out(Filename.c_str(), io_mode); if (!Out.good()) return true; try { - WriteBytecodeToFile(M ? M : Program, Out, /*compression=*/true); + llvm_ostream L(Out); + WriteBytecodeToFile(M ? M : Program, L, /*compression=*/true); } catch (...) { return true; } @@ -72,15 +74,15 @@ void BugDriver::EmitProgressBytecode(const std::string &ID, bool NoFlyer) { // std::string Filename = "bugpoint-" + ID + ".bc"; if (writeProgramToFile(Filename)) { - std::cerr << "Error opening file '" << Filename << "' for writing!\n"; + llvm_cerr << "Error opening file '" << Filename << "' for writing!\n"; return; } - std::cout << "Emitted bytecode to '" << Filename << "'\n"; + llvm_cout << "Emitted bytecode to '" << Filename << "'\n"; if (NoFlyer || PassesToRun.empty()) return; - std::cout << "\n*** You can reproduce the problem with: "; - std::cout << "opt " << Filename << " "; - std::cout << getPassesString(PassesToRun) << "\n"; + llvm_cout << "\n*** You can reproduce the problem with: "; + llvm_cout << "opt " << Filename << " "; + llvm_cout << getPassesString(PassesToRun) << "\n"; } int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) { @@ -89,7 +91,7 @@ int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) { std::ios::binary; std::ofstream OutFile(ChildOutput.c_str(), io_mode); if (!OutFile.good()) { - std::cerr << "Error opening bytecode file: " << ChildOutput << "\n"; + llvm_cerr << "Error opening bytecode file: " << ChildOutput << "\n"; return 1; } @@ -101,14 +103,15 @@ int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) { if (Passes[i]->getNormalCtor()) PM.add(Passes[i]->getNormalCtor()()); else - std::cerr << "Cannot create pass yet: " << Passes[i]->getPassName() + llvm_cerr << "Cannot create pass yet: " << Passes[i]->getPassName() << "\n"; } // Check that the module is well formed on completion of optimization PM.add(createVerifierPass()); // Write bytecode out to disk as the last step... - PM.add(new WriteBytecodePass(&OutFile)); + llvm_ostream L(OutFile); + PM.add(new WriteBytecodePass(&L)); // Run all queued passes. PM.run(*Program); @@ -128,11 +131,11 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, std::string &OutputFilename, bool DeleteOutput, bool Quiet) const { // setup the output file name - std::cout << std::flush; + llvm_cout << std::flush; sys::Path uniqueFilename("bugpoint-output.bc"); std::string ErrMsg; if (uniqueFilename.makeUnique(true, &ErrMsg)) { - std::cerr << getToolName() << ": Error making unique filename: " + llvm_cerr << getToolName() << ": Error making unique filename: " << ErrMsg << "\n"; return(1); } @@ -141,7 +144,7 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, // set up the input file name sys::Path inputFilename("bugpoint-input.bc"); if (inputFilename.makeUnique(true, &ErrMsg)) { - std::cerr << getToolName() << ": Error making unique filename: " + llvm_cerr << getToolName() << ": Error making unique filename: " << ErrMsg << "\n"; return(1); } @@ -149,10 +152,11 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, std::ios::binary; std::ofstream InFile(inputFilename.c_str(), io_mode); if (!InFile.good()) { - std::cerr << "Error opening bytecode file: " << inputFilename << "\n"; + llvm_cerr << "Error opening bytecode file: " << inputFilename << "\n"; return(1); } - WriteBytecodeToFile(Program,InFile,false); + llvm_ostream L(InFile); + WriteBytecodeToFile(Program,L,false); InFile.close(); // setup the child process' arguments @@ -203,17 +207,17 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, if (!Quiet) { if (result == 0) - std::cout << "Success!\n"; + llvm_cout << "Success!\n"; else if (result > 0) - std::cout << "Exited with error code '" << result << "'\n"; + llvm_cout << "Exited with error code '" << result << "'\n"; else if (result < 0) { if (result == -1) - std::cout << "Execute failed: " << ErrMsg << "\n"; + llvm_cout << "Execute failed: " << ErrMsg << "\n"; else - std::cout << "Crashed with signal #" << abs(result) << "\n"; + llvm_cout << "Crashed with signal #" << abs(result) << "\n"; } if (result & 0x01000000) - std::cout << "Dumped core\n"; + llvm_cout << "Dumped core\n"; } // Was the child successful? @@ -231,7 +235,7 @@ Module *BugDriver::runPassesOn(Module *M, std::string BytecodeResult; if (runPasses(Passes, BytecodeResult, false/*delete*/, true/*quiet*/)) { if (AutoDebugCrashes) { - std::cerr << " Error running this sequence of passes" + llvm_cerr << " Error running this sequence of passes" << " on the input program!\n"; delete OldProgram; EmitProgressBytecode("pass-error", false); @@ -246,7 +250,7 @@ Module *BugDriver::runPassesOn(Module *M, Module *Ret = ParseInputFile(BytecodeResult); if (Ret == 0) { - std::cerr << getToolName() << ": Error reading bytecode file '" + llvm_cerr << getToolName() << ": Error reading bytecode file '" << BytecodeResult << "'!\n"; exit(1); } diff --git a/tools/gccas/gccas.cpp b/tools/gccas/gccas.cpp index c46b29608a..eda7d9b5b5 100644 --- a/tools/gccas/gccas.cpp +++ b/tools/gccas/gccas.cpp @@ -23,10 +23,11 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Signals.h" +#include <iostream> #include <memory> #include <fstream> - using namespace llvm; namespace { @@ -140,7 +141,7 @@ int main(int argc, char **argv) { ParseError Err; std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename,&Err)); if (M.get() == 0) { - std::cerr << argv[0] << ": " << Err.getMessage() << "\n"; + llvm_cerr << argv[0] << ": " << Err.getMessage() << "\n"; return 1; } @@ -175,7 +176,7 @@ int main(int argc, char **argv) { if (!Out->good()) { - std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n"; + llvm_cerr << argv[0] << ": error opening " << OutputFilename << "!\n"; return 1; } @@ -194,7 +195,8 @@ int main(int argc, char **argv) { Passes.add(createVerifierPass()); // Write bytecode to file... - Passes.add(new WriteBytecodePass(Out,false,!NoCompress)); + llvm_ostream L(*Out); + Passes.add(new WriteBytecodePass(&L,false,!NoCompress)); // Run our queue of passes all at once now, efficiently. Passes.run(*M.get()); @@ -202,9 +204,9 @@ int main(int argc, char **argv) { if (Out != &std::cout) delete Out; return 0; } catch (const std::string& msg) { - std::cerr << argv[0] << ": " << msg << "\n"; + llvm_cerr << argv[0] << ": " << msg << "\n"; |