diff options
author | Bill Wendling <isanbard@gmail.com> | 2006-11-29 00:19:40 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2006-11-29 00:19:40 +0000 |
commit | 68fe61d6a165ea6090008e281330895a21607daf (patch) | |
tree | 2e0cc1cbd16099aed908dbb3ecda16cf57d04300 /tools | |
parent | a5b31ca85686062408bca0f0a8aa43f9fe58e644 (diff) | |
download | llvm-68fe61d6a165ea6090008e281330895a21607daf.tar.gz llvm-68fe61d6a165ea6090008e281330895a21607daf.tar.bz2 llvm-68fe61d6a165ea6090008e281330895a21607daf.tar.xz |
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
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bugpoint/OptimizerDriver.cpp | 46 | ||||
-rw-r--r-- | tools/gccas/gccas.cpp | 14 | ||||
-rw-r--r-- | tools/gccld/GenerateCode.cpp | 11 | ||||
-rw-r--r-- | tools/gccld/gccld.cpp | 35 | ||||
-rw-r--r-- | tools/llvm-as/llvm-as.cpp | 23 | ||||
-rw-r--r-- | tools/llvm-extract/llvm-extract.cpp | 15 | ||||
-rw-r--r-- | tools/llvm-ld/llvm-ld.cpp | 42 | ||||
-rw-r--r-- | tools/llvm-link/llvm-link.cpp | 39 | ||||
-rw-r--r-- | tools/lto/lto.cpp | 18 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 7 |
10 files changed, 134 insertions, 116 deletions
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index dddf7ceb61..0ec66baddf 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -27,6 +27,7 @@ #include "llvm/Target/TargetData.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Path.h" #include "llvm/System/Program.h" #include "llvm/Config/alloca.h" @@ -55,7 +56,8 @@ bool BugDriver::writeProgramToFile(const std::string &Filename, std::ofstream Out(Filename.c_str(), io_mode); if (!Out.good()) return true; try { - WriteBytecodeToFile(M ? M : Program, Out, /*compression=*/true); + llvm_ostream L(Out); + WriteBytecodeToFile(M ? M : Program, L, /*compression=*/true); } catch (...) { return true; } @@ -72,15 +74,15 @@ void BugDriver::EmitProgressBytecode(const std::string &ID, bool NoFlyer) { // std::string Filename = "bugpoint-" + ID + ".bc"; if (writeProgramToFile(Filename)) { - std::cerr << "Error opening file '" << Filename << "' for writing!\n"; + llvm_cerr << "Error opening file '" << Filename << "' for writing!\n"; return; } - std::cout << "Emitted bytecode to '" << Filename << "'\n"; + llvm_cout << "Emitted bytecode to '" << Filename << "'\n"; if (NoFlyer || PassesToRun.empty()) return; - std::cout << "\n*** You can reproduce the problem with: "; - std::cout << "opt " << Filename << " "; - std::cout << getPassesString(PassesToRun) << "\n"; + llvm_cout << "\n*** You can reproduce the problem with: "; + llvm_cout << "opt " << Filename << " "; + llvm_cout << getPassesString(PassesToRun) << "\n"; } int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) { @@ -89,7 +91,7 @@ int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) { std::ios::binary; std::ofstream OutFile(ChildOutput.c_str(), io_mode); if (!OutFile.good()) { - std::cerr << "Error opening bytecode file: " << ChildOutput << "\n"; + llvm_cerr << "Error opening bytecode file: " << ChildOutput << "\n"; return 1; } @@ -101,14 +103,15 @@ int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) { if (Passes[i]->getNormalCtor()) PM.add(Passes[i]->getNormalCtor()()); else - std::cerr << "Cannot create pass yet: " << Passes[i]->getPassName() + llvm_cerr << "Cannot create pass yet: " << Passes[i]->getPassName() << "\n"; } // Check that the module is well formed on completion of optimization PM.add(createVerifierPass()); // Write bytecode out to disk as the last step... - PM.add(new WriteBytecodePass(&OutFile)); + llvm_ostream L(OutFile); + PM.add(new WriteBytecodePass(&L)); // Run all queued passes. PM.run(*Program); @@ -128,11 +131,11 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, std::string &OutputFilename, bool DeleteOutput, bool Quiet) const { // setup the output file name - std::cout << std::flush; + llvm_cout << std::flush; sys::Path uniqueFilename("bugpoint-output.bc"); std::string ErrMsg; if (uniqueFilename.makeUnique(true, &ErrMsg)) { - std::cerr << getToolName() << ": Error making unique filename: " + llvm_cerr << getToolName() << ": Error making unique filename: " << ErrMsg << "\n"; return(1); } @@ -141,7 +144,7 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, // set up the input file name sys::Path inputFilename("bugpoint-input.bc"); if (inputFilename.makeUnique(true, &ErrMsg)) { - std::cerr << getToolName() << ": Error making unique filename: " + llvm_cerr << getToolName() << ": Error making unique filename: " << ErrMsg << "\n"; return(1); } @@ -149,10 +152,11 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, std::ios::binary; std::ofstream InFile(inputFilename.c_str(), io_mode); if (!InFile.good()) { - std::cerr << "Error opening bytecode file: " << inputFilename << "\n"; + llvm_cerr << "Error opening bytecode file: " << inputFilename << "\n"; return(1); } - WriteBytecodeToFile(Program,InFile,false); + llvm_ostream L(InFile); + WriteBytecodeToFile(Program,L,false); InFile.close(); // setup the child process' arguments @@ -203,17 +207,17 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes, if (!Quiet) { if (result == 0) - std::cout << "Success!\n"; + llvm_cout << "Success!\n"; else if (result > 0) - std::cout << "Exited with error code '" << result << "'\n"; + llvm_cout << "Exited with error code '" << result << "'\n"; else if (result < 0) { if (result == -1) - std::cout << "Execute failed: " << ErrMsg << "\n"; + llvm_cout << "Execute failed: " << ErrMsg << "\n"; else - std::cout << "Crashed with signal #" << abs(result) << "\n"; + llvm_cout << "Crashed with signal #" << abs(result) << "\n"; } if (result & 0x01000000) - std::cout << "Dumped core\n"; + llvm_cout << "Dumped core\n"; } // Was the child successful? @@ -231,7 +235,7 @@ Module *BugDriver::runPassesOn(Module *M, std::string BytecodeResult; if (runPasses(Passes, BytecodeResult, false/*delete*/, true/*quiet*/)) { if (AutoDebugCrashes) { - std::cerr << " Error running this sequence of passes" + llvm_cerr << " Error running this sequence of passes" << " on the input program!\n"; delete OldProgram; EmitProgressBytecode("pass-error", false); @@ -246,7 +250,7 @@ Module *BugDriver::runPassesOn(Module *M, Module *Ret = ParseInputFile(BytecodeResult); if (Ret == 0) { - std::cerr << getToolName() << ": Error reading bytecode file '" + llvm_cerr << getToolName() << ": Error reading bytecode file '" << BytecodeResult << "'!\n"; exit(1); } diff --git a/tools/gccas/gccas.cpp b/tools/gccas/gccas.cpp index c46b29608a..eda7d9b5b5 100644 --- a/tools/gccas/gccas.cpp +++ b/tools/gccas/gccas.cpp @@ -23,10 +23,11 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Signals.h" +#include <iostream> #include <memory> #include <fstream> - using namespace llvm; namespace { @@ -140,7 +141,7 @@ int main(int argc, char **argv) { ParseError Err; std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename,&Err)); if (M.get() == 0) { - std::cerr << argv[0] << ": " << Err.getMessage() << "\n"; + llvm_cerr << argv[0] << ": " << Err.getMessage() << "\n"; return 1; } @@ -175,7 +176,7 @@ int main(int argc, char **argv) { if (!Out->good()) { - std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n"; + llvm_cerr << argv[0] << ": error opening " << OutputFilename << "!\n"; return 1; } @@ -194,7 +195,8 @@ int main(int argc, char **argv) { Passes.add(createVerifierPass()); // Write bytecode to file... - Passes.add(new WriteBytecodePass(Out,false,!NoCompress)); + llvm_ostream L(*Out); + Passes.add(new WriteBytecodePass(&L,false,!NoCompress)); // Run our queue of passes all at once now, efficiently. Passes.run(*M.get()); @@ -202,9 +204,9 @@ int main(int argc, char **argv) { if (Out != &std::cout) delete Out; return 0; } catch (const std::string& msg) { - std::cerr << argv[0] << ": " << msg << "\n"; + llvm_cerr << argv[0] << ": " << msg << "\n"; } 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 e28f4c9fcb..c84c7d3640 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 9401a8acbf..5376425b52 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 <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; } diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index 4a1b9adb00..d8f487ee9d 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 <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; } diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index c675e47c03..4f3236f802 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 <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; } diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp index 82cf674724..fe825f9fed 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 <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; } diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index eb14c1762e..4214a4a260 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 <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; } diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index 6a7677244e..65fcef62d0 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 <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; } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 502118e658..e43b76ff95 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 <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()); |