diff options
-rw-r--r-- | include/llvm/Support/raw_ostream.h | 33 | ||||
-rw-r--r-- | lib/CodeGen/MachineVerifier.cpp | 41 | ||||
-rw-r--r-- | lib/Support/raw_ostream.cpp | 38 | ||||
-rw-r--r-- | tools/bugpoint/ExtractFunction.cpp | 5 | ||||
-rw-r--r-- | tools/gold/gold-plugin.cpp | 7 | ||||
-rw-r--r-- | tools/llc/llc.cpp | 13 | ||||
-rw-r--r-- | tools/llvm-as/llvm-as.cpp | 126 | ||||
-rw-r--r-- | tools/llvm-dis/llvm-dis.cpp | 134 | ||||
-rw-r--r-- | tools/llvm-extract/llvm-extract.cpp | 5 | ||||
-rw-r--r-- | tools/llvm-ld/llvm-ld.cpp | 8 | ||||
-rw-r--r-- | tools/llvm-link/llvm-link.cpp | 5 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 14 | ||||
-rw-r--r-- | tools/lto/LTOCodeGenerator.cpp | 5 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 5 | ||||
-rw-r--r-- | utils/FileUpdate/FileUpdate.cpp | 4 | ||||
-rw-r--r-- | utils/TableGen/TableGen.cpp | 4 |
16 files changed, 215 insertions, 232 deletions
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h index c9a8787429..d9d023cc27 100644 --- a/include/llvm/Support/raw_ostream.h +++ b/include/llvm/Support/raw_ostream.h @@ -334,19 +334,32 @@ class raw_fd_ostream : public raw_ostream { virtual size_t preferred_buffer_size(); public: - /// raw_fd_ostream - Open the specified file for writing. If an - /// error 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. + + enum { + /// F_Force - When opening a file, this flag makes raw_fd_ostream overwrite + /// a file if it already exists instead of emitting an error. This may not + /// be specified with F_Append. + F_Force = 1, + + /// F_Append - When opening a file, if it already exists append to the + /// existing file instead of returning an error. This may not be specified + /// with F_Force. + F_Append = 2, + + /// F_Binary - The file should be opened in binary mode on platforms that + /// support this distinction. + F_Binary = 4 + }; + + /// raw_fd_ostream - Open the specified file for writing. If an error 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. + /// This allows optional flags to control how the file will be opened. /// /// \param Filename - The file to open. If this is "-" then the /// stream will use stdout instead. - /// \param Binary - The file should be opened in binary mode on - /// platforms that support this distinction. - /// \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(const char *Filename, std::string &ErrorInfo, + unsigned Flags = 0); /// 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. diff --git a/lib/CodeGen/MachineVerifier.cpp b/lib/CodeGen/MachineVerifier.cpp index 238f90568f..ea2f8279d7 100644 --- a/lib/CodeGen/MachineVerifier.cpp +++ b/lib/CodeGen/MachineVerifier.cpp @@ -39,8 +39,6 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" -#include <fstream> - using namespace llvm; namespace { @@ -65,7 +63,7 @@ namespace { const bool allowPhysDoubleDefs; const char *const OutFileName; - std::ostream *OS; + raw_ostream *OS; const MachineFunction *MF; const TargetMachine *TM; const TargetRegisterInfo *TRI; @@ -173,21 +171,24 @@ static RegisterPass<MachineVerifier> MachineVer("machineverifier", "Verify generated machine code"); static const PassInfo *const MachineVerifyID = &MachineVer; -FunctionPass * -llvm::createMachineVerifierPass(bool allowPhysDoubleDefs) -{ +FunctionPass *llvm::createMachineVerifierPass(bool allowPhysDoubleDefs) { return new MachineVerifier(allowPhysDoubleDefs); } -bool -MachineVerifier::runOnMachineFunction(MachineFunction &MF) -{ - std::ofstream OutFile; +bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) { + raw_ostream *OutFile = 0; if (OutFileName) { - OutFile.open(OutFileName, std::ios::out | std::ios::app); - OS = &OutFile; + std::string ErrorInfo; + OutFile = new raw_fd_ostream(OutFileName, ErrorInfo, + raw_fd_ostream::F_Append); + if (!ErrorInfo.empty()) { + errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n'; + exit(1); + } + + OS = OutFile; } else { - OS = cerr.stream(); + OS = &errs(); } foundErrors = 0; @@ -212,14 +213,10 @@ MachineVerifier::runOnMachineFunction(MachineFunction &MF) } visitMachineFunctionAfter(); - if (OutFileName) - OutFile.close(); - else if (foundErrors) { - std::string msg; - raw_string_ostream Msg(msg); - Msg << "Found " << foundErrors << " machine code errors."; - llvm_report_error(Msg.str()); - } + if (OutFile) + delete OutFile; + else if (foundErrors) + llvm_report_error("Found "+Twine(foundErrors)+" machine code errors."); // Clean up. regsLive.clear(); @@ -234,7 +231,7 @@ MachineVerifier::runOnMachineFunction(MachineFunction &MF) void MachineVerifier::report(const char *msg, const MachineFunction *MF) { assert(MF); - *OS << "\n"; + *OS << '\n'; if (!foundErrors++) MF->print(*OS); *OS << "*** Bad machine code: " << msg << " ***\n" diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 94507bd67b..2e151118d6 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -322,8 +322,12 @@ void format_object_base::home() { /// 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, bool Force, - std::string &ErrorInfo) : pos(0) { +raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo, + unsigned Flags) : pos(0) { + // Verify that we don't have both "append" and "force". + assert((!(Flags & F_Force) || !(Flags & F_Append)) && + "Cannot specify both 'force' and 'append' file creation flags!"); + ErrorInfo.clear(); // Handle "-" as stdout. @@ -331,20 +335,26 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force, FD = STDOUT_FILENO; // If user requested binary then put stdout into binary mode if // possible. - if (Binary) + if (Flags & F_Binary) sys::Program::ChangeStdoutToBinary(); ShouldClose = false; return; } - int Flags = O_WRONLY|O_CREAT|O_TRUNC; + int OpenFlags = O_WRONLY|O_CREAT; #ifdef O_BINARY if (Binary) - Flags |= O_BINARY; + OpenFlags |= O_BINARY; #endif - if (!Force) - Flags |= O_EXCL; - FD = open(Filename, Flags, 0664); + + if (Flags & F_Force) + OpenFlags |= O_TRUNC; + else if (Flags & F_Append) + OpenFlags |= O_APPEND; + else + OpenFlags |= O_EXCL; + + FD = open(Filename, OpenFlags, 0664); if (FD < 0) { ErrorInfo = "Error opening output file '" + std::string(Filename) + "'"; ShouldClose = false; @@ -354,14 +364,14 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force, } raw_fd_ostream::~raw_fd_ostream() { - if (FD >= 0) { - flush(); - if (ShouldClose) - if (::close(FD) != 0) - error_detected(); - } + if (FD < 0) return; + flush(); + if (ShouldClose) + if (::close(FD) != 0) + error_detected(); } + void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { assert (FD >= 0 && "File already closed."); pos += Size; diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 9fdcc1bdea..b2e427c9bf 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -336,9 +336,8 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const sys::RemoveFileOnSignal(uniqueFilename); std::string ErrorInfo; - raw_fd_ostream BlocksToNotExtractFile(uniqueFilename.c_str(), - /*Binary=*/false, /*Force=*/true, - ErrorInfo); + raw_fd_ostream BlocksToNotExtractFile(uniqueFilename.c_str(), ErrorInfo, + raw_fd_ostream::F_Force); if (!ErrorInfo.empty()) { outs() << "*** Basic Block extraction failed!\n"; errs() << "Error writing list of blocks to not extract: " << ErrorInfo diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 9554b8adc3..16b3471853 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -362,10 +362,9 @@ ld_plugin_status all_symbols_read_hook(void) { (*message)(LDPL_ERROR, "%s", ErrMsg.c_str()); return LDPS_ERR; } - raw_fd_ostream *objFile = new raw_fd_ostream(uniqueObjPath.c_str(), - /*Binary=*/true, - /*Force=*/true, - ErrMsg); + raw_fd_ostream *objFile = + new raw_fd_ostream(uniqueObjPath.c_str(), ErrMsg, + raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary); if (!ErrMsg.empty()) { delete objFile; (*message)(LDPL_ERROR, "%s", ErrMsg.c_str()); diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index cbc1d7b1ad..423cf471ee 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -137,8 +137,10 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName, sys::RemoveFileOnSignal(sys::Path(OutputFilename)); std::string error; - raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(), - /*Binary=*/true, Force, error); + raw_fd_ostream *FDOut = + new raw_fd_ostream(OutputFilename.c_str(), error, + (Force ? raw_fd_ostream::F_Force : 0)| + raw_fd_ostream::F_Binary); if (!error.empty()) { errs() << error << '\n'; if (!Force) @@ -187,8 +189,11 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName, sys::RemoveFileOnSignal(sys::Path(OutputFilename)); std::string error; - raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(), - Binary, Force, error); + unsigned OpenFlags = 0; + if (Force) OpenFlags |= raw_fd_ostream::F_Force; + if (Binary) OpenFlags |= raw_fd_ostream::F_Binary; + raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(), error, + OpenFlags); if (!error.empty()) { errs() << error << '\n'; if (!Force) diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index 942dbebfa1..06b3ad254e 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -58,88 +58,64 @@ int main(int argc, char **argv) { llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n"); - int exitCode = 0; - raw_ostream *Out = 0; - try { - // Parse the file now... - SMDiagnostic Err; - std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, Context)); - if (M.get() == 0) { - Err.Print(argv[0], errs()); - return 1; - } + // Parse the file now... + SMDiagnostic Err; + std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, Context)); + if (M.get() == 0) { + Err.Print(argv[0], errs()); + return 1; + } - if (!DisableVerify) { - std::string Err; - if (verifyModule(*M.get(), ReturnStatusAction, &Err)) { - errs() << argv[0] - << ": assembly parsed, but does not verify as correct!\n"; - errs() << Err; - return 1; - } - } + if (!DisableVerify) { + std::string Err; + if (verifyModule(*M.get(), ReturnStatusAction, &Err)) { + errs() << argv[0] + << ": assembly parsed, but does not verify as correct!\n"; + errs() << Err; + return 1; + } + } - if (DumpAsm) errs() << "Here's the assembly:\n" << *M.get(); + if (DumpAsm) errs() << "Here's the assembly:\n" << *M.get(); - if (OutputFilename != "") { // Specified an output filename? - if (OutputFilename != "-") { // Not stdout? - 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; - } - } else { // Specified stdout - // FIXME: outs() is not binary! - Out = &outs(); - } + // Infer the output filename if needed. + if (OutputFilename.empty()) { + if (InputFilename == "-") { + OutputFilename = "-"; } else { - if (InputFilename == "-") { - OutputFilename = "-"; - Out = &outs(); + std::string IFN = InputFilename; + int Len = IFN.length(); + if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') { + // Source ends in .ll + OutputFilename = std::string(IFN.begin(), IFN.end()-3); } else { - std::string IFN = InputFilename; - int Len = IFN.length(); - if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') { - // Source ends in .ll - OutputFilename = std::string(IFN.begin(), IFN.end()-3); - } else { - OutputFilename = IFN; // Append a .bc to it - } - OutputFilename += ".bc"; - - 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; - } - // Make sure that the Out file gets unlinked from the disk if we get a - // SIGINT - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); + OutputFilename = IFN; // Append a .bc to it } + OutputFilename += ".bc"; } - - if (!DisableOutput) - if (Force || !CheckBitcodeOutputToConsole(Out,true)) - WriteBitcodeToFile(M.get(), *Out); - } catch (const std::string& msg) { - errs() << argv[0] << ": " << msg << "\n"; - exitCode = 1; - } catch (...) { - errs() << argv[0] << ": Unexpected unknown exception occurred.\n"; - exitCode = 1; } - - if (Out != &outs()) delete Out; - return exitCode; + + std::string ErrorInfo; + std::auto_ptr<raw_ostream> Out + (new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, + (Force?raw_fd_ostream::F_Force : 0) | + raw_fd_ostream::F_Binary)); + if (!ErrorInfo.empty()) { + errs() << ErrorInfo << '\n'; + if (!Force) + errs() << "Use -f command line argument to force output\n"; + return 1; + } + + + // Make sure that the Out file gets unlinked from the disk if we get a + // SIGINT. + if (OutputFilename != "-") + sys::RemoveFileOnSignal(sys::Path(OutputFilename)); + + if (!DisableOutput) + if (Force || !CheckBitcodeOutputToConsole(Out.get(), true)) + WriteBitcodeToFile(M.get(), *Out); + return 0; } diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index 65e97c37df..2066fffd29 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -50,90 +50,70 @@ int main(int argc, char **argv) { LLVMContext &Context = getGlobalContext(); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - try { - cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n"); - - raw_ostream *Out = &outs(); // Default to printing to stdout. - std::string ErrorMessage; + + + cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n"); - std::auto_ptr<Module> M; - - if (MemoryBuffer *Buffer - = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) { - M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage)); - delete Buffer; - } + std::string ErrorMessage; + std::auto_ptr<Module> M; + + if (MemoryBuffer *Buffer + = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) { + M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage)); + delete Buffer; + } - if (M.get() == 0) { - errs() << argv[0] << ": "; - if (ErrorMessage.size()) - errs() << ErrorMessage << "\n"; - else - errs() << "bitcode didn't read correctly.\n"; - return 1; - } - - if (DontPrint) { - // Just use stdout. We won't actually print anything on it. - } else if (OutputFilename != "") { // Specified an output filename? - if (OutputFilename != "-") { // Not stdout? - 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 (M.get() == 0) { + errs() << argv[0] << ": "; + if (ErrorMessage.size()) + errs() << ErrorMessage << "\n"; + else + errs() << "bitcode didn't read correctly.\n"; + return 1; + } + + // Just use stdout. We won't actually print anything on it. + if (DontPrint) + OutputFilename = "-"; + + if (OutputFilename.empty()) { // Unspecified output, infer it. + if (InputFilename == "-") { + OutputFilename = "-"; } else { - if (InputFilename == "-") { - OutputFilename = "-"; - } else { - std::string IFN = InputFilename; - int Len = IFN.length(); - if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') { - // Source ends in .bc - OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll"; - } else { - OutputFilename = IFN+".ll"; - } - - 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; - } - - // Make sure that the Out file gets unlinked from the disk if we get a - // SIGINT - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); - } + const std::string &IFN = InputFilename; + int Len = IFN.length(); + // If the source ends in .bc, strip it off. + if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') + OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll"; + else + OutputFilename = IFN+".ll"; } + } + + std::string ErrorInfo; + std::auto_ptr<raw_fd_ostream> + Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, + (Force?raw_fd_ostream::F_Force : 0) | + raw_fd_ostream::F_Binary)); + if (!ErrorInfo.empty()) { + errs() << ErrorInfo << '\n'; + if (!Force) + errs() << "Use -f command line argument to force output\n"; + return 1; + } - // All that llvm-dis does is write the assembly to a file. - if (!DontPrint) { - PassManager Passes; - Passes.add(createPrintModulePass(Out)); - Passes.run(*M.get()); - } + // Make sure that the Out file gets unlinked from the disk if we get a + // SIGINT. + if (OutputFilename != "-") + sys::RemoveFileOnSignal(sys::Path(OutputFilename)); - if (Out != &outs()) - delete Out; - return 0; - } catch (const std::string& msg) { - errs() << argv[0] << ": " << msg << "\n"; - } catch (...) { - errs() << argv[0] << ": Unexpected unknown exception occurred.\n"; + // All that llvm-dis does is write the assembly to a file. + if (!DontPrint) { + PassManager Passes; + Passes.add(createPrintModulePass(Out.get())); + Passes.run(*M.get()); } - return 1; + return 0; } diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index 6b7846f38e..16e039bcbf 100644 --- a/tools/llvm-extract/llvm-extract.cpp +++ b/tools/llvm-extract/llvm-extract.cpp @@ -114,8 +114,9 @@ int main(int argc, char **argv) { if (OutputFilename != "-") { // Not stdout? std::string ErrorInfo; - Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true, - Force, ErrorInfo); + Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, + raw_fd_ostream::F_Binary | + (Force ? raw_fd_ostream::F_Force : 0)); if (!ErrorInfo.empty()) { errs() << ErrorInfo << '\n'; if (!Force) diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp index 17035e2a31..f789b15d3a 100644 --- a/tools/llvm-ld/llvm-ld.cpp +++ b/tools/llvm-ld/llvm-ld.cpp @@ -229,8 +229,8 @@ void GenerateBitcode(Module* M, const std::string& FileName) { // Create the output file. std::string ErrorInfo; - raw_fd_ostream Out(FileName.c_str(), /*Binary=*/true, /*Force=*/true, - ErrorInfo); + raw_fd_ostream Out(FileName.c_str(), ErrorInfo, + raw_fd_ostream::F_Force | raw_fd_ostream::F_Binary); if (!ErrorInfo.empty()) PrintAndExit(ErrorInfo); @@ -427,8 +427,8 @@ static void EmitShellScript(char **argv) { // Output the script to start the program... std::string ErrorInfo; - raw_fd_ostream Out2(OutputFilename.c_str(), /*Binary=*/false, /*Force=*/true, - ErrorInfo); + raw_fd_ostream Out2(OutputFilename.c_str(), ErrorInfo, + llvm::raw_fd_ostream::F_Force); if (!ErrorInfo.empty()) PrintAndExit(ErrorInfo); diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index a287c479a7..3d10ee3c4d 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -122,8 +122,9 @@ int main(int argc, char **argv) { raw_ostream *Out = &outs(); // Default to printing to stdout... if (OutputFilename != "-") { std::string ErrorInfo; - Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true, - Force, ErrorInfo); + Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, + raw_fd_ostream::F_Binary | + (Force ? raw_fd_ostream::F_Force : 0)); if (!ErrorInfo.empty()) { errs() << ErrorInfo << '\n'; if (!Force) diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 4f5b8a0ba2..af72fbcf49 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -174,16 +174,18 @@ static const Target *GetTarget(const char *ProgName) { } static formatted_raw_ostream *GetOutputStream() { - if (OutputFilename == "" || OutputFilename == "-") - return &fouts(); + if (OutputFilename == "") + OutputFilename = "-"; // Make sure that the Out file gets unlinked from the disk if we get a - // SIGINT - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); + // SIGINT. + if (OutputFilename != "-") + sys::RemoveFileOnSignal(sys::Path(OutputFilename)); std::string Err; - raw_fd_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), - /*Binary=*/false, Force, Err); + raw_fd_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), Err, + raw_fd_ostream::F_Binary | + (Force ? raw_fd_ostream::F_Force : 0)); if (!Err.empty()) { errs() << Err << '\n'; if (!Force) diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index f76168e3f5..36be523181 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -178,9 +178,8 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) // generate assembly code bool genResult = false; { - raw_fd_ostream asmFD(uniqueAsmPath.c_str(), - /*Binary=*/false, /*Force=*/true, - errMsg); + raw_fd_ostream asmFD(uniqueAsmPath.c_str(), errMsg, + raw_fd_ostream::F_Force); formatted_raw_ostream asmFile(asmFD); if (!errMsg.empty()) return NULL; diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 40f3fb9307..4f24198640 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -376,8 +376,9 @@ int main(int argc, char **argv) { raw_ostream *Out = &outs(); // Default to printing to stdout... if (OutputFilename != "-") { std::string ErrorInfo; - Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/true, - Force, ErrorInfo); + Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, + raw_fd_ostream::F_Binary | + (Force ? raw_fd_ostream::F_Force : 0)); if (!ErrorInfo.empty()) { errs() << ErrorInfo << '\n'; if (!Force) diff --git a/utils/FileUpdate/FileUpdate.cpp b/utils/FileUpdate/FileUpdate.cpp index 8d5d6b1b90..da760e65e8 100644 --- a/utils/FileUpdate/FileUpdate.cpp +++ b/utils/FileUpdate/FileUpdate.cpp @@ -65,8 +65,8 @@ int main(int argc, char **argv) { if (!Quiet) outs() << argv[0] << ": Updating '" << OutputFilename << "', contents changed.\n"; - raw_fd_ostream OutStream(OutputFilename.c_str(), /*Binary=*/true, - /*Force=*/true, ErrorStr); + raw_fd_ostream OutStream(OutputFilename.c_str(), ErrorStr, + raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary); if (!ErrorStr.empty()) { errs() << argv[0] << ": Unable to write output '" << OutputFilename << "': " << ErrorStr << '\n'; diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp index 315bb657a0..3e284f9419 100644 --- a/utils/TableGen/TableGen.cpp +++ b/utils/TableGen/TableGen.cpp @@ -171,8 +171,8 @@ int main(int argc, char **argv) { raw_ostream *Out = &outs(); if (OutputFilename != "-") { std::string Error; - Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false, - /*Force=*/true, Error); + Out = new raw_fd_ostream(OutputFilename.c_str(), Error, + raw_fd_ostream::F_Force); if (!Error.empty()) { errs() << argv[0] << ": error opening " << OutputFilename |