From 68fe61d6a165ea6090008e281330895a21607daf Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 29 Nov 2006 00:19:40 +0000 Subject: [PATCH] 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 --- examples/ModuleMaker/ModuleMaker.cpp | 5 +-- include/llvm/Analysis/CallGraph.h | 6 +++ include/llvm/Bytecode/WriteBytecodePass.h | 9 ++-- include/llvm/Bytecode/Writer.h | 5 +-- include/llvm/CodeGen/Passes.h | 5 +++ include/llvm/Support/Streams.h | 1 + lib/Analysis/DataStructure/Local.cpp | 5 +-- lib/Analysis/DataStructure/Printer.cpp | 5 ++- lib/Analysis/DataStructure/Steensgaard.cpp | 7 +++- lib/Analysis/IPA/Andersens.cpp | 49 +++++++++++----------- lib/Analysis/IPA/CallGraph.cpp | 13 ++++-- lib/Analysis/ScalarEvolutionExpander.cpp | 2 +- lib/Bytecode/Writer/SlotCalculator.cpp | 6 +-- lib/Bytecode/Writer/Writer.cpp | 17 ++++---- projects/Stacker/tools/stkrc/stkrc.cpp | 11 ++--- tools/bugpoint/OptimizerDriver.cpp | 46 ++++++++++---------- tools/gccas/gccas.cpp | 14 ++++--- tools/gccld/GenerateCode.cpp | 11 ++--- tools/gccld/gccld.cpp | 35 ++++++++-------- tools/llvm-as/llvm-as.cpp | 23 +++++----- tools/llvm-extract/llvm-extract.cpp | 15 ++++--- tools/llvm-ld/llvm-ld.cpp | 42 +++++++++---------- tools/llvm-link/llvm-link.cpp | 39 ++++++++--------- tools/lto/lto.cpp | 18 ++++---- tools/opt/opt.cpp | 7 +++- 25 files changed, 217 insertions(+), 179 deletions(-) diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp index 2ec5437c36b..30f63bb8f44 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 - +#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 b567bab474f..f29aef3a22d 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 198cc026296..a634812498f 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 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 8b89226fa5d..374e5df482c 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 - 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 adccf531eb2..4d27e541d70 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 8048d56e706..a422756c63a 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 34947371c65..436218be9e1 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 // 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(STy)) - std::cerr << "Pointer indexing not handled yet!\n"; + llvm_cerr << "Pointer indexing not handled yet!\n"; else { const ArrayType *ATy = cast(STy); unsigned ElSize = TD.getTypeSize(CurTy); @@ -1062,7 +1061,7 @@ void GraphBuilder::visitCallSite(CallSite CS) { if (DisableDirectCallOpt || !isa(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 b425e4e4729..ef3ed755559 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 +#include #include #include 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 eb5b74ca022..292dfffa0dc 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 +#include 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 73aa231e21c..54e2944b958 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 -#include 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 << ""; + llvm_cerr << ""; return; } else if (N == &GraphNodes[NullPtr]) { - std::cerr << ""; + llvm_cerr << ""; return; } else if (N == &GraphNodes[NullObject]) { - std::cerr << ""; + llvm_cerr << ""; return; } @@ -1120,56 +1119,56 @@ void Andersens::PrintNode(Node *N) { if (Function *F = dyn_cast(V)) { if (isa(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(V)) - std::cerr << I->getParent()->getParent()->getName() << ":"; + llvm_cerr << I->getParent()->getParent()->getName() << ":"; else if (Argument *Arg = dyn_cast(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(V) || isa(V)) if (N == getObject(V)) - std::cerr << ""; + llvm_cerr << ""; } 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 d9e7242695c..9c22b7cc5e2 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 +#include "llvm/Support/Streams.h" +#include 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 b6d77b93ae0..3865d5f7afd 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 6ac295ca1c4..efb6c436cd2 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -31,8 +31,8 @@ using namespace llvm; #if 0 -#include -#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(D)->getDescription() << "'!\n"; + // llvm_cerr << "Inserting type '"<(D)->getDescription() <<"'!\n"; if (Typ->isDerivedType()) { int ValSlot; diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index f2ded65b072..d8bcce82085 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 727b044c20f..f468330e622 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 #include #include - using namespace llvm; static cl::opt @@ -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 dddf7ceb612..0ec66baddf2 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 &Passes) { @@ -89,7 +91,7 @@ int BugDriver::runPassesAsChild(const std::vector &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 &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 &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 &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 &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 &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 c46b29608a2..eda7d9b5b56 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 #include #include - using namespace llvm; namespace { @@ -140,7 +141,7 @@ int main(int argc, char **argv) { ParseError Err; std::auto_ptr 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"; } catch (...) { - std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; + llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; } return 1; } diff --git a/tools/gccld/GenerateCode.cpp b/tools/gccld/GenerateCode.cpp index e28f4c9fcb4..c84c7d36401 100644 --- a/tools/gccld/GenerateCode.cpp +++ b/tools/gccld/GenerateCode.cpp @@ -27,7 +27,7 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Support/SystemUtils.h" #include "llvm/Support/CommandLine.h" - +#include "llvm/Support/Streams.h" using namespace llvm; namespace { @@ -123,10 +123,10 @@ static void RemoveEnv(const char * name, char ** const envp) { } static void dumpArgs(const char **args) { - std::cerr << *args++; + llvm_cerr << *args++; while (*args) - std::cerr << ' ' << *args++; - std::cerr << '\n' << std::flush; + llvm_cerr << ' ' << *args++; + llvm_cerr << '\n' << std::flush; } static inline void addPass(PassManager &PM, Pass *P) { @@ -283,7 +283,8 @@ int llvm::GenerateBytecode(Module *M, int StripLevel, bool Internalize, Passes.add(createVerifierPass()); // Add the pass that writes bytecode to the output file... - addPass(Passes, new WriteBytecodePass(Out, false, !NoCompress)); + llvm_ostream L(*Out); + addPass(Passes, new WriteBytecodePass(&L, false, !NoCompress)); // Run our queue of passes all at once now, efficiently. Passes.run(*M); diff --git a/tools/gccld/gccld.cpp b/tools/gccld/gccld.cpp index 9401a8acbfc..5376425b52a 100644 --- a/tools/gccld/gccld.cpp +++ b/tools/gccld/gccld.cpp @@ -31,6 +31,7 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileUtilities.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Signals.h" #include "llvm/Support/SystemUtils.h" #include @@ -126,7 +127,7 @@ namespace { /// Message - The message to print to standard error. /// static int PrintAndReturn(const char *progname, const std::string &Message) { - std::cerr << progname << ": " << Message << "\n"; + llvm_cerr << progname << ": " << Message << "\n"; return 1; } @@ -140,11 +141,11 @@ static void EmitShellScript(char **argv) { std::string ErrMsg; sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0]); if (llvmstub.isEmpty()) { - std::cerr << "Could not find llvm-stub.exe executable!\n"; + llvm_cerr << "Could not find llvm-stub.exe executable!\n"; exit(1); } if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; exit(1); } @@ -324,18 +325,18 @@ int main(int argc, char **argv, char **envp ) { return PrintAndReturn(argv[0], "Failed to find gcc"); // Generate an assembly language file for the bytecode. - if (Verbose) std::cout << "Generating Assembly Code\n"; + if (Verbose) llvm_cout << "Generating Assembly Code\n"; std::string ErrMsg; if (0 != GenerateAssembly( AssemblyFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 2; } - if (Verbose) std::cout << "Generating Native Code\n"; + if (Verbose) llvm_cout << "Generating Native Code\n"; if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(), LibPaths, Libraries, gcc, envp, LinkAsLibrary, NoInternalize, RPath, SOName, ErrMsg, Verbose) ) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 2; } @@ -364,18 +365,18 @@ int main(int argc, char **argv, char **envp ) { return PrintAndReturn(argv[0], "Failed to find gcc"); // Generate an assembly language file for the bytecode. - if (Verbose) std::cout << "Generating C Source Code\n"; + if (Verbose) llvm_cout << "Generating C Source Code\n"; std::string ErrMsg; if (0 != GenerateCFile( CFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 2; } - if (Verbose) std::cout << "Generating Native Code\n"; + if (Verbose) llvm_cout << "Generating Native Code\n"; if (0 != GenerateNative(OutputFilename, CFile.toString(), LibPaths, Libraries, gcc, envp, LinkAsLibrary, NoInternalize, RPath, SOName, ErrMsg, Verbose)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 2; } @@ -392,11 +393,11 @@ int main(int argc, char **argv, char **envp ) { // Make the bytecode file readable and directly executable in LLEE std::string ErrMsg; if (sys::Path(RealBytecodeOutput).makeExecutableOnDisk(&ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } if (sys::Path(RealBytecodeOutput).makeReadableOnDisk(&ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } } @@ -404,18 +405,18 @@ int main(int argc, char **argv, char **envp ) { // Make the output, whether native or script, executable as well... std::string ErrMsg; if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } } catch (const char*msg) { - std::cerr << argv[0] << ": " << msg << "\n"; + llvm_cerr << argv[0] << ": " << msg << "\n"; exitCode = 1; } catch (const std::string& msg) { - std::cerr << argv[0] << ": " << msg << "\n"; + llvm_cerr << argv[0] << ": " << msg << "\n"; exitCode = 2; } catch (...) { // This really shouldn't happen, but just in case .... - std::cerr << argv[0] << ": An unexpected unknown exception occurred.\n"; + llvm_cerr << argv[0] << ": An unexpected unknown exception occurred.\n"; exitCode = 3; } diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index 4a1b9adb003..d8f487ee9df 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -20,12 +20,12 @@ #include "llvm/Bytecode/Writer.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Streams.h" #include "llvm/Support/SystemUtils.h" #include "llvm/System/Signals.h" #include #include #include - using namespace llvm; static cl::opt @@ -60,27 +60,27 @@ int main(int argc, char **argv) { ParseError Err; std::auto_ptr M(ParseAssemblyFile(InputFilename,&Err)); if (M.get() == 0) { - std::cerr << argv[0] << ": " << Err.getMessage() << "\n"; + llvm_cerr << argv[0] << ": " << Err.getMessage() << "\n"; return 1; } if (!DisableVerify) { std::string Err; if (verifyModule(*M.get(), ReturnStatusAction, &Err)) { - std::cerr << argv[0] + llvm_cerr << argv[0] << ": assembly parsed, but does not verify as correct!\n"; - std::cerr << Err; + llvm_cerr << Err; return 1; } } - if (DumpAsm) std::cerr << "Here's the assembly:\n" << *M.get(); + if (DumpAsm) llvm_cerr << "Here's the assembly:\n" << *M.get(); if (OutputFilename != "") { // Specified an output filename? if (OutputFilename != "-") { // Not stdout? if (!Force && std::ifstream(OutputFilename.c_str())) { // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename + llvm_cerr << argv[0] << ": error opening '" << OutputFilename << "': file exists!\n" << "Use -f command line argument to force output\n"; return 1; @@ -108,7 +108,7 @@ int main(int argc, char **argv) { if (!Force && std::ifstream(OutputFilename.c_str())) { // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename + llvm_cerr << argv[0] << ": error opening '" << OutputFilename << "': file exists!\n" << "Use -f command line argument to force output\n"; return 1; @@ -123,18 +123,19 @@ 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; } if (Force || !CheckBytecodeOutputToConsole(Out,true)) { - WriteBytecodeToFile(M.get(), *Out, !NoCompress); + llvm_ostream L(*Out); + WriteBytecodeToFile(M.get(), L, !NoCompress); } } catch (const std::string& msg) { - std::cerr << argv[0] << ": " << msg << "\n"; + llvm_cerr << argv[0] << ": " << msg << "\n"; exitCode = 1; } catch (...) { - std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; + llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; exitCode = 1; } diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index c675e47c03a..4f3236f802b 100644 --- a/tools/llvm-extract/llvm-extract.cpp +++ b/tools/llvm-extract/llvm-extract.cpp @@ -19,7 +19,9 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Signals.h" +#include #include #include using namespace llvm; @@ -51,14 +53,14 @@ int main(int argc, char **argv) { std::auto_ptr M(ParseBytecodeFile(InputFilename)); if (M.get() == 0) { - std::cerr << argv[0] << ": bytecode didn't read correctly.\n"; + llvm_cerr << argv[0] << ": bytecode didn't read correctly.\n"; return 1; } // Figure out which function we should extract Function *F = M.get()->getNamedFunction(ExtractFunc); if (F == 0) { - std::cerr << argv[0] << ": program doesn't contain function named '" + llvm_cerr << argv[0] << ": program doesn't contain function named '" << ExtractFunc << "'!\n"; return 1; } @@ -78,7 +80,7 @@ int main(int argc, char **argv) { if (OutputFilename != "-") { // Not stdout? if (!Force && std::ifstream(OutputFilename.c_str())) { // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename + llvm_cerr << argv[0] << ": error opening '" << OutputFilename << "': file exists!\n" << "Use -f command line argument to force output\n"; return 1; @@ -91,16 +93,17 @@ int main(int argc, char **argv) { Out = &std::cout; } - Passes.add(new WriteBytecodePass(Out)); // Write bytecode to file... + llvm_ostream L(*Out); + Passes.add(new WriteBytecodePass(&L)); // Write bytecode to file... Passes.run(*M.get()); 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"; } catch (...) { - std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; + llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; } return 1; } diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp index 82cf6747242..fe825f9fed6 100644 --- a/tools/llvm-ld/llvm-ld.cpp +++ b/tools/llvm-ld/llvm-ld.cpp @@ -32,12 +32,11 @@ #include "llvm/Target/TargetMachineRegistry.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileUtilities.h" +#include "llvm/Support/Streams.h" #include "llvm/Support/SystemUtils.h" #include "llvm/System/Signals.h" #include -#include #include - using namespace llvm; // Input/Output Options @@ -109,7 +108,7 @@ static std::string progname; /// Message - The message to print to standard error. /// static int PrintAndReturn(const std::string &Message) { - std::cerr << progname << ": " << Message << "\n"; + llvm_cerr << progname << ": " << Message << "\n"; return 1; } @@ -208,7 +207,8 @@ void GenerateBytecode(Module* M, const std::string& FileName) { sys::RemoveFileOnSignal(sys::Path(FileName)); // Write it out - WriteBytecodeToFile(M, Out, !DisableCompression); + llvm_ostream L(Out); + WriteBytecodeToFile(M, L, !DisableCompression); // Close the bytecode file. Out.close(); @@ -351,12 +351,12 @@ static void EmitShellScript(char **argv) { std::string ErrMsg; sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0]); if (llvmstub.isEmpty()) { - std::cerr << "Could not find llvm-stub.exe executable!\n"; + llvm_cerr << "Could not find llvm-stub.exe executable!\n"; exit(1); } if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; exit(1); } @@ -518,14 +518,14 @@ int main(int argc, char **argv, char **envp) { sys::Path target(RealBytecodeOutput); target.eraseFromDisk(); if (tmp_output.renamePathOnDisk(target, &ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 2; } } else return PrintAndReturn( "Post-link optimization output is not bytecode"); } else { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 2; } } @@ -554,18 +554,18 @@ int main(int argc, char **argv, char **envp) { return PrintAndReturn("Failed to find gcc"); // Generate an assembly language file for the bytecode. - if (Verbose) std::cout << "Generating Assembly Code\n"; + if (Verbose) llvm_cout << "Generating Assembly Code\n"; std::string ErrMsg; if (0 != GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput, llc, ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } - if (Verbose) std::cout << "Generating Native Code\n"; + if (Verbose) llvm_cout << "Generating Native Code\n"; if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(), LinkItems,gcc,envp,ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } @@ -589,18 +589,18 @@ int main(int argc, char **argv, char **envp) { return PrintAndReturn("Failed to find gcc"); // Generate an assembly language file for the bytecode. - if (Verbose) std::cout << "Generating Assembly Code\n"; + if (Verbose) llvm_cout << "Generating Assembly Code\n"; std::string ErrMsg; if (0 != GenerateCFile( CFile.toString(), RealBytecodeOutput, llc, ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } - if (Verbose) std::cout << "Generating Native Code\n"; + if (Verbose) llvm_cout << "Generating Native Code\n"; if (0 != GenerateNative(OutputFilename, CFile.toString(), LinkItems, gcc, envp, ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } @@ -614,26 +614,26 @@ int main(int argc, char **argv, char **envp) { // Make the script executable... std::string ErrMsg; if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } // Make the bytecode file readable and directly executable in LLEE as well if (sys::Path(RealBytecodeOutput).makeExecutableOnDisk(&ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } if (sys::Path(RealBytecodeOutput).makeReadableOnDisk(&ErrMsg)) { - std::cerr << argv[0] << ": " << ErrMsg << "\n"; + llvm_cerr << argv[0] << ": " << ErrMsg << "\n"; return 1; } } return 0; } catch (const std::string& msg) { - std::cerr << argv[0] << ": " << msg << "\n"; + llvm_cerr << argv[0] << ": " << msg << "\n"; } catch (...) { - std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; + llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; } return 1; } diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index eb14c1762e3..4214a4a2609 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -18,12 +18,12 @@ #include "llvm/Bytecode/Reader.h" #include "llvm/Bytecode/Writer.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Signals.h" #include "llvm/System/Path.h" #include #include #include - using namespace llvm; static cl::list @@ -51,23 +51,23 @@ static cl::opt NoCompress("disable-compression", cl::init(false), static inline std::auto_ptr LoadFile(const std::string &FN) { sys::Path Filename; if (!Filename.set(FN)) { - std::cerr << "Invalid file name: '" << FN << "'\n"; + llvm_cerr << "Invalid file name: '" << FN << "'\n"; return std::auto_ptr(); } std::string ErrorMessage; if (Filename.exists()) { - if (Verbose) std::cerr << "Loading '" << Filename.c_str() << "'\n"; + if (Verbose) llvm_cerr << "Loading '" << Filename.c_str() << "'\n"; Module* Result = ParseBytecodeFile(Filename.toString(), &ErrorMessage); if (Result) return std::auto_ptr(Result); // Load successful! if (Verbose) { - std::cerr << "Error opening bytecode file: '" << Filename.c_str() << "'"; - if (ErrorMessage.size()) std::cerr << ": " << ErrorMessage; - std::cerr << "\n"; + llvm_cerr << "Error opening bytecode file: '" << Filename.c_str() << "'"; + if (ErrorMessage.size()) llvm_cerr << ": " << ErrorMessage; + llvm_cerr << "\n"; } } else { - std::cerr << "Bytecode file: '" << Filename.c_str() + llvm_cerr << "Bytecode file: '" << Filename.c_str() << "' does not exist.\n"; } @@ -85,7 +85,7 @@ int main(int argc, char **argv) { std::auto_ptr Composite(LoadFile(InputFilenames[BaseArg])); if (Composite.get() == 0) { - std::cerr << argv[0] << ": error loading file '" + llvm_cerr << argv[0] << ": error loading file '" << InputFilenames[BaseArg] << "'\n"; return 1; } @@ -93,15 +93,15 @@ int main(int argc, char **argv) { for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) { std::auto_ptr M(LoadFile(InputFilenames[i])); if (M.get() == 0) { - std::cerr << argv[0] << ": error loading file '" + llvm_cerr << argv[0] << ": error loading file '" << InputFilenames[i] << "'\n"; return 1; } - if (Verbose) std::cerr << "Linking in '" << InputFilenames[i] << "'\n"; + if (Verbose) llvm_cerr << "Linking in '" << InputFilenames[i] << "'\n"; if (Linker::LinkModules(Composite.get(), M.get(), &ErrorMessage)) { - std::cerr << argv[0] << ": link error in '" << InputFilenames[i] + llvm_cerr << argv[0] << ": link error in '" << InputFilenames[i] << "': " << ErrorMessage << "\n"; return 1; } @@ -110,14 +110,14 @@ int main(int argc, char **argv) { // TODO: Iterate over the -l list and link in any modules containing // global symbols that have not been resolved so far. - if (DumpAsm) std::cerr << "Here's the assembly:\n" << *Composite.get(); + if (DumpAsm) llvm_cerr << "Here's the assembly:\n" << *Composite.get(); // FIXME: cout is not binary! std::ostream *Out = &std::cout; // Default to printing to stdout... if (OutputFilename != "-") { if (!Force && std::ifstream(OutputFilename.c_str())) { // If force is not specified, make sure not to overwrite a file! - std::cerr << argv[0] << ": error opening '" << OutputFilename + llvm_cerr << argv[0] << ": error opening '" << OutputFilename << "': file exists!\n" << "Use -f command line argument to force output\n"; return 1; @@ -126,7 +126,7 @@ int main(int argc, char **argv) { std::ios::binary; Out = new std::ofstream(OutputFilename.c_str(), io_mode); if (!Out->good()) { - std::cerr << argv[0] << ": error opening '" << OutputFilename << "'!\n"; + llvm_cerr << argv[0] << ": error opening '" << OutputFilename << "'!\n"; return 1; } @@ -136,19 +136,20 @@ int main(int argc, char **argv) { } if (verifyModule(*Composite.get())) { - std::cerr << argv[0] << ": linked module is broken!\n"; + llvm_cerr << argv[0] << ": linked module is broken!\n"; return 1; } - if (Verbose) std::cerr << "Writing bytecode...\n"; - WriteBytecodeToFile(Composite.get(), *Out, !NoCompress); + if (Verbose) llvm_cerr << "Writing bytecode...\n"; + llvm_ostream L(*Out); + WriteBytecodeToFile(Composite.get(), L, !NoCompress); 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"; } catch (...) { - std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; + llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; } return 1; } diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index 6a7677244e0..65fcef62d0e 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -37,10 +37,10 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Analysis/LoadValueNumbering.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/Streams.h" #include "llvm/LinkTimeOptimizer.h" #include -#include - +#include using namespace llvm; extern "C" @@ -361,7 +361,8 @@ LTO::optimizeModules(const std::string &OutputFilename, std::string tempFileName(FinalOutputPath.c_str()); tempFileName += "0.bc"; std::ofstream Out(tempFileName.c_str(), io_mode); - WriteBytecodeToFile(bigOne, Out, true); + llvm_ostream L(Out); + WriteBytecodeToFile(bigOne, L, true); } // Strip leading underscore because it was added to match names @@ -377,17 +378,17 @@ LTO::optimizeModules(const std::string &OutputFilename, std::string ErrMsg; sys::Path TempDir = sys::Path::GetTemporaryDirectory(&ErrMsg); if (TempDir.isEmpty()) { - std::cerr << "lto: " << ErrMsg << "\n"; + llvm_cerr << "lto: " << ErrMsg << "\n"; return LTO_WRITE_FAILURE; } sys::Path tmpAsmFilePath(TempDir); if (!tmpAsmFilePath.appendComponent("lto")) { - std::cerr << "lto: " << ErrMsg << "\n"; + llvm_cerr << "lto: " << ErrMsg << "\n"; TempDir.eraseFromDisk(true); return LTO_WRITE_FAILURE; } if (tmpAsmFilePath.createTemporaryFileOnDisk(&ErrMsg)) { - std::cerr << "lto: " << ErrMsg << "\n"; + llvm_cerr << "lto: " << ErrMsg << "\n"; TempDir.eraseFromDisk(true); return LTO_WRITE_FAILURE; } @@ -414,7 +415,8 @@ LTO::optimizeModules(const std::string &OutputFilename, std::string tempFileName(FinalOutputPath.c_str()); tempFileName += "1.bc"; std::ofstream Out(tempFileName.c_str(), io_mode); - WriteBytecodeToFile(bigOne, Out, true); + llvm_ostream L(Out); + WriteBytecodeToFile(bigOne, L, true); } targetTriple = bigOne->getTargetTriple(); @@ -443,7 +445,7 @@ LTO::optimizeModules(const std::string &OutputFilename, args.push_back(0); if (sys::Program::ExecuteAndWait(gcc, &args[0], 0, 0, 1, &ErrMsg)) { - std::cerr << "lto: " << ErrMsg << "\n"; + llvm_cerr << "lto: " << ErrMsg << "\n"; return LTO_ASM_FAILURE; } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 502118e6588..e43b76ff95f 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/Timer.h" #include "llvm/LinkAllPasses.h" #include "llvm/LinkAllVMCore.h" +#include #include #include #include @@ -251,8 +252,10 @@ int main(int argc, char **argv) { Passes.add(createVerifierPass()); // Write bytecode out to disk or cout as the last step... - if (!NoOutput && !AnalyzeOnly) - Passes.add(new WriteBytecodePass(Out, Out != &std::cout, !NoCompress)); + if (!NoOutput && !AnalyzeOnly) { + llvm_ostream L(*Out); + Passes.add(new WriteBytecodePass(&L, Out != &std::cout, !NoCompress)); + } // Now that we have all of the passes ready, run them. Passes.run(*M.get()); -- 2.34.1