[llvm-commits] [llvm] r75801 - in /llvm/trunk: include/llvm/Support/raw_ostream.h lib/Support/raw_ostream.cpp tools/bugpoint/ToolRunner.cpp tools/gold/gold-plugin.cpp tools/llc/llc.cpp tools/llvm-as/llvm-as.cpp tools/llvm-dis/llvm-dis.cpp tools/l
Daniel Dunbar
daniel at zuster.org
Wed Jul 15 13:49:56 PDT 2009
Stupid request, can someone fix it so we don't get errors like this:
--
ddunbar at giles:llvm$ llvm-as < /dev/null -o /dev/null
Error opening output file '/dev/null'
Use -f command line argument to force output
--
Is it reasonable to just ignore the "Force" flag if the file is a device?
- Daniel
On Wed, Jul 15, 2009 at 10:29 AM, Dan Gohman<gohman at apple.com> wrote:
> Author: djg
> Date: Wed Jul 15 12:29:42 2009
> New Revision: 75801
>
> URL: http://llvm.org/viewvc/llvm-project?rev=75801&view=rev
> Log:
> Add a Force option to raw_fd_ostream to specify whether opening
> an existing file is considered an error. Convert several tools
> to use raw_fd_ostream instead of std::ostream, and to use this
> new option instead of doing a manual check.
>
> Modified:
> llvm/trunk/include/llvm/Support/raw_ostream.h
> llvm/trunk/lib/Support/raw_ostream.cpp
> llvm/trunk/tools/bugpoint/ToolRunner.cpp
> llvm/trunk/tools/gold/gold-plugin.cpp
> llvm/trunk/tools/llc/llc.cpp
> llvm/trunk/tools/llvm-as/llvm-as.cpp
> llvm/trunk/tools/llvm-dis/llvm-dis.cpp
> llvm/trunk/tools/llvm-extract/llvm-extract.cpp
> llvm/trunk/tools/llvm-link/llvm-link.cpp
> llvm/trunk/tools/lto/LTOCodeGenerator.cpp
> llvm/trunk/tools/opt/opt.cpp
> llvm/trunk/utils/TableGen/TableGen.cpp
>
> Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
> +++ llvm/trunk/include/llvm/Support/raw_ostream.h Wed Jul 15 12:29:42 2009
> @@ -251,7 +251,10 @@
> /// stream will use stdout instead.
> /// \param Binary - The file should be opened in binary mode on
> /// platforms that support this distinction.
> - raw_fd_ostream(const char *Filename, bool Binary, std::string &ErrorInfo);
> + /// \param Force - Don't consider the case where the file already
> + /// exists to be an error.
> + raw_fd_ostream(const char *Filename, bool Binary, bool Force,
> + std::string &ErrorInfo);
>
> /// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
> /// ShouldClose is true, this closes the file when the stream is destroyed.
>
> Modified: llvm/trunk/lib/Support/raw_ostream.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Support/raw_ostream.cpp (original)
> +++ llvm/trunk/lib/Support/raw_ostream.cpp Wed Jul 15 12:29:42 2009
> @@ -246,7 +246,7 @@
> /// occurs, information about the error is put into ErrorInfo, and the
> /// stream should be immediately destroyed; the string will be empty
> /// if no error occurred.
> -raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary,
> +raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force,
> std::string &ErrorInfo) : pos(0) {
> ErrorInfo.clear();
>
> @@ -266,6 +266,8 @@
> if (Binary)
> Flags |= O_BINARY;
> #endif
> + if (!Force)
> + Flags |= O_EXCL;
> FD = open(Filename, Flags, 0664);
> if (FD < 0) {
> ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";
>
> Modified: llvm/trunk/tools/bugpoint/ToolRunner.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ToolRunner.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/bugpoint/ToolRunner.cpp (original)
> +++ llvm/trunk/tools/bugpoint/ToolRunner.cpp Wed Jul 15 12:29:42 2009
> @@ -20,7 +20,6 @@
> #include "llvm/Support/FileUtilities.h"
> #include <fstream>
> #include <sstream>
> -#include <iostream>
> using namespace llvm;
>
> namespace {
> @@ -158,7 +157,7 @@
> LLIArgs.push_back(Args[i].c_str());
> LLIArgs.push_back(0);
>
> - std::cout << "<lli>" << std::flush;
> + outs() << "<lli>"; outs().flush();
> DEBUG(errs() << "\nAbout to run:\t";
> for (unsigned i=0, e = LLIArgs.size()-1; i != e; ++i)
> errs() << " " << LLIArgs[i];
> @@ -312,7 +311,7 @@
> LLCArgs.push_back (Bitcode.c_str()); // This is the input bitcode
> LLCArgs.push_back (0);
>
> - std::cout << "<llc>" << std::flush;
> + outs() << "<llc>"; outs().flush();
> DEBUG(errs() << "\nAbout to run:\t";
> for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
> errs() << " " << LLCArgs[i];
> @@ -429,7 +428,7 @@
> JITArgs.push_back(Args[i].c_str());
> JITArgs.push_back(0);
>
> - std::cout << "<jit>" << std::flush;
> + outs() << "<jit>"; outs().flush();
> DEBUG(errs() << "\nAbout to run:\t";
> for (unsigned i=0, e = JITArgs.size()-1; i != e; ++i)
> errs() << " " << JITArgs[i];
> @@ -478,7 +477,7 @@
> LLCArgs.push_back (Bitcode.c_str()); // This is the input bitcode
> LLCArgs.push_back (0);
>
> - std::cout << "<cbe>" << std::flush;
> + outs() << "<cbe>"; outs().flush();
> DEBUG(errs() << "\nAbout to run:\t";
> for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
> errs() << " " << LLCArgs[i];
> @@ -621,7 +620,7 @@
> #endif
> GCCArgs.push_back(0); // NULL terminator
>
> - std::cout << "<gcc>" << std::flush;
> + outs() << "<gcc>"; outs().flush();
> DEBUG(errs() << "\nAbout to run:\t";
> for (unsigned i=0, e = GCCArgs.size()-1; i != e; ++i)
> errs() << " " << GCCArgs[i];
> @@ -665,7 +664,7 @@
> ProgramArgs.push_back(0); // NULL terminator
>
> // Now that we have a binary, run it!
> - std::cout << "<program>" << std::flush;
> + outs() << "<program>"; outs().flush();
> DEBUG(errs() << "\nAbout to run:\t";
> for (unsigned i=0, e = ProgramArgs.size()-1; i != e; ++i)
> errs() << " " << ProgramArgs[i];
> @@ -680,7 +679,7 @@
> sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
> Timeout, MemoryLimit);
> } else {
> - std::cout << "<run remotely>" << std::flush;
> + outs() << "<run remotely>"; outs().flush();
> int RemoteClientStatus = RunProgramWithTimeout(sys::Path(RemoteClientPath),
> &ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
> sys::Path(OutputFile), Timeout, MemoryLimit);
> @@ -756,7 +755,7 @@
>
>
>
> - std::cout << "<gcc>" << std::flush;
> + outs() << "<gcc>"; outs().flush();
> DEBUG(errs() << "\nAbout to run:\t";
> for (unsigned i=0, e = GCCArgs.size()-1; i != e; ++i)
> errs() << " " << GCCArgs[i];
>
> Modified: llvm/trunk/tools/gold/gold-plugin.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/gold/gold-plugin.cpp (original)
> +++ llvm/trunk/tools/gold/gold-plugin.cpp Wed Jul 15 12:29:42 2009
> @@ -362,7 +362,9 @@
> (*message)(LDPL_ERROR, "%s", ErrMsg.c_str());
> return LDPS_ERR;
> }
> - raw_fd_ostream *objFile = new raw_fd_ostream(uniqueObjPath.c_str(), true,
> + raw_fd_ostream *objFile = new raw_fd_ostream(uniqueObjPath.c_str(),
> + /*Binary=*/true,
> + /*Force=*/true,
> ErrMsg);
> if (!ErrMsg.empty()) {
> delete objFile;
>
> Modified: llvm/trunk/tools/llc/llc.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llc/llc.cpp (original)
> +++ llvm/trunk/tools/llc/llc.cpp Wed Jul 15 12:29:42 2009
> @@ -41,8 +41,6 @@
> #include "llvm/Config/config.h"
> #include "llvm/LinkAllVMCore.h"
> #include "llvm/Target/TargetSelect.h"
> -#include <fstream>
> -#include <iostream>
> #include <memory>
> using namespace llvm;
>
> @@ -133,28 +131,22 @@
> if (OutputFilename == "-")
> return &fouts();
>
> - // Specified an output filename?
> - if (!Force && std::ifstream(OutputFilename.c_str())) {
> - // If force is not specified, make sure not to overwrite a file!
> - errs() << ProgName << ": error opening '" << OutputFilename
> - << "': file exists!\n"
> - << "Use -f command line argument to force output\n";
> - return 0;
> - }
> // Make sure that the Out file gets unlinked from the disk if we get a
> // SIGINT
> sys::RemoveFileOnSignal(sys::Path(OutputFilename));
>
> std::string error;
> raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(),
> - true, error);
> - formatted_raw_ostream *Out =
> - new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM);
> + /*Binary=*/true, Force, error);
> if (!error.empty()) {
> errs() << error << '\n';
> - delete Out;
> + if (!Force)
> + errs() << "Use -f command line argument to force output\n";
> + delete FDOut;
> return 0;
> }
> + formatted_raw_ostream *Out =
> + new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM);
>
> return Out;
> }
> @@ -189,29 +181,24 @@
> break;
> }
>
> - if (!Force && std::ifstream(OutputFilename.c_str())) {
> - // If force is not specified, make sure not to overwrite a file!
> - errs() << ProgName << ": error opening '" << OutputFilename
> - << "': file exists!\n"
> - << "Use -f command line argument to force output\n";
> - return 0;
> - }
> -
> // Make sure that the Out file gets unlinked from the disk if we get a
> // SIGINT
> sys::RemoveFileOnSignal(sys::Path(OutputFilename));
>
> std::string error;
> raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(),
> - Binary, error);
> - formatted_raw_ostream *Out =
> - new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM);
> + Binary, Force, error);
> if (!error.empty()) {
> errs() << error << '\n';
> - delete Out;
> + if (!Force)
> + errs() << "Use -f command line argument to force output\n";
> + delete FDOut;
> return 0;
> }
>
> + formatted_raw_ostream *Out =
> + new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM);
> +
> return Out;
> }
>
>
> Modified: llvm/trunk/tools/llvm-as/llvm-as.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-as/llvm-as.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-as/llvm-as.cpp (original)
> +++ llvm/trunk/tools/llvm-as/llvm-as.cpp Wed Jul 15 12:29:42 2009
> @@ -28,8 +28,6 @@
> #include "llvm/Support/SystemUtils.h"
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/System/Signals.h"
> -#include <fstream>
> -#include <iostream>
> #include <memory>
> using namespace llvm;
>
> @@ -62,7 +60,7 @@
> cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
>
> int exitCode = 0;
> - std::ostream *Out = 0;
> + raw_ostream *Out = 0;
> try {
> // Parse the file now...
> SMDiagnostic Err;
> @@ -86,23 +84,24 @@
>
> 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!
> - cerr << argv[0] << ": error opening '" << OutputFilename
> - << "': file exists!\n"
> - << "Use -f command line argument to force output\n";
> + std::string ErrorInfo;
> + Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
> + Force, ErrorInfo);
> + if (!ErrorInfo.empty()) {
> + errs() << ErrorInfo << '\n';
> + if (!Force)
> + errs() << "Use -f command line argument to force output\n";
> + delete Out;
> return 1;
> }
> - Out = new std::ofstream(OutputFilename.c_str(), std::ios::out |
> - std::ios::trunc | std::ios::binary);
> } else { // Specified stdout
> - // FIXME: cout is not binary!
> - Out = &std::cout;
> + // FIXME: outs() is not binary!
> + Out = &outs();
> }
> } else {
> if (InputFilename == "-") {
> OutputFilename = "-";
> - Out = &std::cout;
> + Out = &outs();
> } else {
> std::string IFN = InputFilename;
> int Len = IFN.length();
> @@ -114,27 +113,22 @@
> }
> OutputFilename += ".bc";
>
> - if (!Force && std::ifstream(OutputFilename.c_str())) {
> - // If force is not specified, make sure not to overwrite a file!
> - cerr << argv[0] << ": error opening '" << OutputFilename
> - << "': file exists!\n"
> - << "Use -f command line argument to force output\n";
> + std::string ErrorInfo;
> + Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
> + Force, ErrorInfo);
> + if (!ErrorInfo.empty()) {
> + errs() << ErrorInfo << '\n';
> + if (!Force)
> + errs() << "Use -f command line argument to force output\n";
> + delete Out;
> return 1;
> }
> -
> - Out = new std::ofstream(OutputFilename.c_str(), std::ios::out |
> - std::ios::trunc | std::ios::binary);
> // Make sure that the Out file gets unlinked from the disk if we get a
> // SIGINT
> sys::RemoveFileOnSignal(sys::Path(OutputFilename));
> }
> }
>
> - if (!Out->good()) {
> - cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
> - return 1;
> - }
> -
> if (!DisableOutput)
> if (Force || !CheckBitcodeOutputToConsole(Out,true))
> WriteBitcodeToFile(M.get(), *Out);
> @@ -146,7 +140,7 @@
> exitCode = 1;
> }
>
> - if (Out != &std::cout) delete Out;
> + if (Out != &outs()) delete Out;
> return exitCode;
> }
>
>
> Modified: llvm/trunk/tools/llvm-dis/llvm-dis.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dis/llvm-dis.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-dis/llvm-dis.cpp (original)
> +++ llvm/trunk/tools/llvm-dis/llvm-dis.cpp Wed Jul 15 12:29:42 2009
> @@ -28,8 +28,6 @@
> #include "llvm/Support/Streams.h"
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/System/Signals.h"
> -#include <iostream>
> -#include <fstream>
> #include <memory>
> using namespace llvm;
>
> @@ -56,7 +54,7 @@
> try {
> cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
>
> - std::ostream *Out = &std::cout; // Default to printing to stdout.
> + raw_ostream *Out = &outs(); // Default to printing to stdout.
> std::string ErrorMessage;
>
> std::auto_ptr<Module> M;
> @@ -80,12 +78,15 @@
> // Just use stdout. We won't actually print anything on it.
> } else 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!
> - cerr << argv[0] << ": error opening '" << OutputFilename
> - << "': file exists! Sending to standard output.\n";
> - } else {
> - Out = new std::ofstream(OutputFilename.c_str());
> + std::string ErrorInfo;
> + Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
> + Force, ErrorInfo);
> + if (!ErrorInfo.empty()) {
> + errs() << ErrorInfo << '\n';
> + if (!Force)
> + errs() << "Use -f command line argument to force output\n";
> + delete Out;
> + return 1;
> }
> }
> } else {
> @@ -101,38 +102,32 @@
> OutputFilename = IFN+".ll";
> }
>
> - if (!Force && std::ifstream(OutputFilename.c_str())) {
> - // If force is not specified, make sure not to overwrite a file!
> - cerr << argv[0] << ": error opening '" << OutputFilename
> - << "': file exists! Sending to standard output.\n";
> - } else {
> - Out = new std::ofstream(OutputFilename.c_str());
> -
> - // Make sure that the Out file gets unlinked from the disk if we get a
> - // SIGINT
> - sys::RemoveFileOnSignal(sys::Path(OutputFilename));
> + std::string ErrorInfo;
> + Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
> + Force, ErrorInfo);
> + if (!ErrorInfo.empty()) {
> + errs() << ErrorInfo << '\n';
> + if (!Force)
> + errs() << "Use -f command line argument to force output\n";
> + delete Out;
> + return 1;
> }
> - }
> - }
>
> - if (!Out->good()) {
> - cerr << argv[0] << ": error opening " << OutputFilename
> - << ": sending to stdout instead!\n";
> - Out = &std::cout;
> + // Make sure that the Out file gets unlinked from the disk if we get a
> + // SIGINT
> + sys::RemoveFileOnSignal(sys::Path(OutputFilename));
> + }
> }
>
> // All that llvm-dis does is write the assembly to a file.
> if (!DontPrint) {
> PassManager Passes;
> - raw_os_ostream L(*Out);
> - Passes.add(createPrintModulePass(&L));
> + Passes.add(createPrintModulePass(Out));
> Passes.run(*M.get());
> }
>
> - if (Out != &std::cout) {
> - ((std::ofstream*)Out)->close();
> + if (Out != &outs())
> delete Out;
> - }
> return 0;
> } catch (const std::string& msg) {
> cerr << argv[0] << ": " << msg << "\n";
>
> Modified: llvm/trunk/tools/llvm-extract/llvm-extract.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-extract/llvm-extract.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-extract/llvm-extract.cpp (original)
> +++ llvm/trunk/tools/llvm-extract/llvm-extract.cpp Wed Jul 15 12:29:42 2009
> @@ -22,10 +22,9 @@
> #include "llvm/Support/ManagedStatic.h"
> #include "llvm/Support/MemoryBuffer.h"
> #include "llvm/Support/PrettyStackTrace.h"
> +#include "llvm/Support/raw_ostream.h"
> #include "llvm/System/Signals.h"
> -#include <iostream>
> #include <memory>
> -#include <fstream>
> using namespace llvm;
>
> // InputFilename - The filename to read from.
> @@ -111,28 +110,28 @@
> Passes.add(createDeadTypeEliminationPass()); // Remove dead types...
> Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
>
> - std::ostream *Out = 0;
> + raw_ostream *Out = 0;
>
> if (OutputFilename != "-") { // Not stdout?
> - if (!Force && std::ifstream(OutputFilename.c_str())) {
> - // If force is not specified, make sure not to overwrite a file!
> - cerr << argv[0] << ": error opening '" << OutputFilename
> - << "': file exists!\n"
> - << "Use -f command line argument to force output\n";
> + std::string ErrorInfo;
> + Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
> + Force, ErrorInfo);
> + if (!ErrorInfo.empty()) {
> + errs() << ErrorInfo << '\n';
> + if (!Force)
> + errs() << "Use -f command line argument to force output\n";
> + delete Out;
> return 1;
> }
> - std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
> - std::ios::binary;
> - Out = new std::ofstream(OutputFilename.c_str(), io_mode);
> } else { // Specified stdout
> - // FIXME: cout is not binary!
> - Out = &std::cout;
> + // FIXME: errs() is not binary!
> + Out = &errs();
> }
>
> - Passes.add(CreateBitcodeWriterPass(*Out));
> + Passes.add(createBitcodeWriterPass(*Out));
> Passes.run(*M.get());
>
> - if (Out != &std::cout)
> + if (Out != &errs())
> delete Out;
> return 0;
> }
>
> Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
> +++ llvm/trunk/tools/llvm-link/llvm-link.cpp Wed Jul 15 12:29:42 2009
> @@ -24,8 +24,6 @@
> #include "llvm/Support/Streams.h"
> #include "llvm/System/Signals.h"
> #include "llvm/System/Path.h"
> -#include <fstream>
> -#include <iostream>
> #include <memory>
> using namespace llvm;
>
> @@ -122,20 +120,16 @@
> if (DumpAsm) cerr << "Here's the assembly:\n" << *Composite.get();
>
> // FIXME: cout is not binary!
> - std::ostream *Out = &std::cout; // Default to printing to stdout...
> + raw_ostream *Out = &outs(); // 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!
> - cerr << argv[0] << ": error opening '" << OutputFilename
> - << "': file exists!\n"
> - << "Use -f command line argument to force output\n";
> - return 1;
> - }
> - std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
> - std::ios::binary;
> - Out = new std::ofstream(OutputFilename.c_str(), io_mode);
> - if (!Out->good()) {
> - cerr << argv[0] << ": error opening '" << OutputFilename << "'!\n";
> + std::string ErrorInfo;
> + Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
> + Force, ErrorInfo);
> + if (!ErrorInfo.empty()) {
> + errs() << ErrorInfo << '\n';
> + if (!Force)
> + errs() << "Use -f command line argument to force output\n";
> + delete Out;
> return 1;
> }
>
> @@ -152,6 +146,6 @@
> if (Verbose) cerr << "Writing bitcode...\n";
> WriteBitcodeToFile(Composite.get(), *Out);
>
> - if (Out != &std::cout) delete Out;
> + if (Out != &outs()) delete Out;
> return 0;
> }
>
> Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
> +++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Wed Jul 15 12:29:42 2009
> @@ -186,7 +186,8 @@
> bool genResult = false;
> {
> raw_fd_ostream asmFD(raw_fd_ostream(uniqueAsmPath.c_str(),
> - false, errMsg));
> + /*Binary=*/false, /*Force=*/true,
> + errMsg));
> formatted_raw_ostream asmFile(asmFD);
> if (!errMsg.empty())
> return NULL;
>
> Modified: llvm/trunk/tools/opt/opt.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/opt/opt.cpp (original)
> +++ llvm/trunk/tools/opt/opt.cpp Wed Jul 15 12:29:42 2009
> @@ -35,8 +35,6 @@
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/LinkAllPasses.h"
> #include "llvm/LinkAllVMCore.h"
> -#include <iostream>
> -#include <fstream>
> #include <memory>
> #include <algorithm>
> using namespace llvm;
> @@ -342,21 +340,16 @@
>
> // Figure out what stream we are supposed to write to...
> // FIXME: cout is not binary!
> - std::ostream *Out = &std::cout; // Default to printing to stdout...
> + raw_ostream *Out = &outs(); // 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!
> - cerr << argv[0] << ": error opening '" << OutputFilename
> - << "': file exists!\n"
> - << "Use -f command line argument to force output\n";
> - return 1;
> - }
> - std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
> - std::ios::binary;
> - Out = new std::ofstream(OutputFilename.c_str(), io_mode);
> -
> - if (!Out->good()) {
> - cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
> + std::string ErrorInfo;
> + Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true,
> + Force, ErrorInfo);
> + if (!ErrorInfo.empty()) {
> + errs() << ErrorInfo << '\n';
> + if (!Force)
> + errs() << "Use -f command line argument to force output\n";
> + delete Out;
> return 1;
> }
>
> @@ -479,13 +472,13 @@
>
> // Write bitcode out to disk or cout as the last step...
> if (!NoOutput && !AnalyzeOnly)
> - Passes.add(CreateBitcodeWriterPass(*Out));
> + Passes.add(createBitcodeWriterPass(*Out));
>
> // Now that we have all of the passes ready, run them.
> Passes.run(*M.get());
>
> // Delete the ofstream.
> - if (Out != &std::cout)
> + if (Out != &outs())
> delete Out;
> return 0;
>
>
> Modified: llvm/trunk/utils/TableGen/TableGen.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TableGen.cpp?rev=75801&r1=75800&r2=75801&view=diff
>
> ==============================================================================
> --- llvm/trunk/utils/TableGen/TableGen.cpp (original)
> +++ llvm/trunk/utils/TableGen/TableGen.cpp Wed Jul 15 12:29:42 2009
> @@ -171,7 +171,8 @@
> raw_ostream *Out = &outs();
> if (OutputFilename != "-") {
> std::string Error;
> - Out = new raw_fd_ostream(OutputFilename.c_str(), false, Error);
> + Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
> + /*Force=*/true, Error);
>
> if (!Error.empty()) {
> errs() << argv[0] << ": error opening " << OutputFilename
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list