Replacing std::iostreams with llvm iostreams. Some of these changes involve
authorBill Wendling <isanbard@gmail.com>
Wed, 29 Nov 2006 00:19:40 +0000 (00:19 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 29 Nov 2006 00:19:40 +0000 (00:19 +0000)
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:
examples/ModuleMaker/ModuleMaker.cpp
include/llvm/Analysis/CallGraph.h
include/llvm/Bytecode/WriteBytecodePass.h
include/llvm/Bytecode/Writer.h
include/llvm/CodeGen/Passes.h
include/llvm/Support/Streams.h
lib/Analysis/DataStructure/Local.cpp
lib/Analysis/DataStructure/Printer.cpp
lib/Analysis/DataStructure/Steensgaard.cpp
lib/Analysis/IPA/Andersens.cpp
lib/Analysis/IPA/CallGraph.cpp
lib/Analysis/ScalarEvolutionExpander.cpp
lib/Bytecode/Writer/SlotCalculator.cpp
lib/Bytecode/Writer/Writer.cpp
projects/Stacker/tools/stkrc/stkrc.cpp
tools/bugpoint/OptimizerDriver.cpp
tools/gccas/gccas.cpp
tools/gccld/GenerateCode.cpp
tools/gccld/gccld.cpp
tools/llvm-as/llvm-as.cpp
tools/llvm-extract/llvm-extract.cpp
tools/llvm-ld/llvm-ld.cpp
tools/llvm-link/llvm-link.cpp
tools/lto/lto.cpp
tools/opt/opt.cpp

index 2ec5437c36be373d58b03778d28e30d4a83f9545..30f63bb8f4496698b13746fd6219e6fe20882460 100644 (file)
@@ -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;
index b567bab474f158b2b21991efe482bf5425d08e87..f29aef3a22df3a48e550f3ef855a7827134db80e 100644 (file)
@@ -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;
 
   //===---------------------------------------------------------------------
index 198cc026296507b17a1e1c28fd5a59cbe8476a58..a634812498fd066f84349cad4dd6c925d5f114f0 100644 (file)
 
 #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() {
index 8b89226fa5d3df88bf9a0bfce9182809ea4f1846..374e5df482c96c0107a3f3e34ffab2478936815c 100644 (file)
 #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
 
index adccf531eb2219072c5b1cbb10de2a2937bda5a3..4d27e541d7079eef24ff43849f8cdf5763d7207b 100644 (file)
@@ -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.
   ///
index 8048d56e7065daa27c541b85475392a404261b04..a422756c63a72f63bf745bd330bb202cbffed240 100644 (file)
@@ -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;
index 34947371c65bf16c02b3e223323709fd32bfad64..436218be9e1af03e60ef0b4e56e8d0702761de1d 100644 (file)
@@ -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?
     }
   }
index b425e4e4729bfa1d2f691493617db475bccc8812..ef3ed755559c238a3061c0bb45ed1208d9ec2a92 100644 (file)
 #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;
index eb5b74ca0227e10704b24538afdecf3c39a9d685..292dfffa0dcb3dcb83d12c8e48d2624231cd21b9 100644 (file)
@@ -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;
 }
 
index 73aa231e21c8c3243f736e10493a4b41478d7705..54e2944b958834367792642556c20809feecc9e5 100644 (file)
@@ -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";
   }
 }
index d9e7242695cffb4cf205a001e8512e1b71ae0584..9c22b7cc5e260ab4b73364a4ce3953807be6326f 100644 (file)
@@ -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) {
index b6d77b93ae053ee9ccf65edfcb68a81e2d32e61b..3865d5f7afd6831de8e0a36b22d36da4bb027dbd 100644 (file)
@@ -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);
 }
index 6ac295ca1c416354e534a484e800f407e8f170c7..efb6c436cd24213fb1c216229a7a051ef8181277 100644 (file)
@@ -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;
index f2ded65b0722fd631c2944c3c4c9dc02ffbbfc1f..d8bcce8208596cf1502aa2e0392e1f53bd90d205 100644 (file)
@@ -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();
 }
index 727b044c20fdc4a68458f9d0b2249c00265f7e15..f468330e622032e60f1728cbf51f6ab120306f1b 100644 (file)
 #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;
   }
 
index dddf7ceb6123ebb6970c6f994d293bcdc0b6bd87..0ec66baddf246494a30a39516d538a1bc6de7cb4 100644 (file)
@@ -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);
   }
index c46b29608a2d8bc94ba0be96b1c1687d353d8783..eda7d9b5b5671e48e2fd64c789b72c8e8b0af965 100644 (file)
 #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";
   } catch (...) {
-    std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
+    llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
   }
   return 1;
 }
index e28f4c9fcb41789ee952d1ec2c40e00dd691b293..c84c7d364017b23e7619f19b33cce95dabd13f37 100644 (file)
@@ -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);
index 9401a8acbfc16b474d1366a8d7783f09de531b73..5376425b52aedb9e1e4cce937f9c0308d48f9838 100644 (file)
@@ -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 <fstream>
@@ -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;
   }
 
index 4a1b9adb00316c8c60cff167b792ad08b8aaac10..d8f487ee9df54d8b7abc64f1b1a58122b1b85061 100644 (file)
 #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 <fstream>
 #include <iostream>
 #include <memory>
-
 using namespace llvm;
 
 static cl::opt<std::string>
@@ -60,27 +60,27 @@ 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;
     }
 
     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;
   }
 
index c675e47c03aff4a20a379e11d97bbbb7f69d827c..4f3236f802bb1927c2aafe953ef9ad4f7b980a61 100644 (file)
@@ -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 <iostream>
 #include <memory>
 #include <fstream>
 using namespace llvm;
@@ -51,14 +53,14 @@ int main(int argc, char **argv) {
 
     std::auto_ptr<Module> 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;
 }
index 82cf674724255fd2d426fe95756c97c62a3d9d2e..fe825f9fed6efd1bcd0ab195cf7dc675d39e4a02 100644 (file)
 #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 <fstream>
-#include <iostream>
 #include <memory>
-
 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;
 }
index eb14c1762e3b98b978a6b9ce2a9defd6256d7b6b..4214a4a2609eefffaed8788891021bffc68aad5d 100644 (file)
 #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 <fstream>
 #include <iostream>
 #include <memory>
-
 using namespace llvm;
 
 static cl::list<std::string>
@@ -51,23 +51,23 @@ static cl::opt<bool> NoCompress("disable-compression", cl::init(false),
 static inline std::auto_ptr<Module> 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<Module>();
   }
 
   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<Module>(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<Module> 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<Module> 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;
 }
index 6a7677244e0c939e39cf11490f2ee8d3e82f5ba7..65fcef62d0e810d5838fe619007d7c7ff6311225 100644 (file)
 #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 <fstream>
-#include <iostream>
-
+#include <ostream>
 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;
   }
 
index 502118e65885707a94070a41737cd647b4d46986..e43b76ff95ff147c4279f93e2bce111031e11284 100644 (file)
@@ -28,6 +28,7 @@
 #include "llvm/Support/Timer.h"
 #include "llvm/LinkAllPasses.h"
 #include "llvm/LinkAllVMCore.h"
+#include <iostream>
 #include <fstream>
 #include <memory>
 #include <algorithm>
@@ -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());