diff options
author | Chris Lattner <sabre@nondot.org> | 2009-08-23 02:51:22 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-08-23 02:51:22 +0000 |
commit | 17e9edc4a7bbeadf756494cf39fcacc9eff72202 (patch) | |
tree | 9aace188da0c44dfbbedde8b592702b9dcbc2cc0 /tools | |
parent | 1d7fb4eae53c7ec5f9c5c18d603b50dfb9425862 (diff) | |
download | external_llvm-17e9edc4a7bbeadf756494cf39fcacc9eff72202.zip external_llvm-17e9edc4a7bbeadf756494cf39fcacc9eff72202.tar.gz external_llvm-17e9edc4a7bbeadf756494cf39fcacc9eff72202.tar.bz2 |
Change raw_fd_ostream to take flags as an optional bitmask
instead of as two bools. Use this to add a F_Append flag
which has the obvious behavior.
Other unrelated changes conflated into this patch:
1. REmove EH stuff from llvm-dis and llvm-as, the try blocks
are dead.
2. Simplify the filename inference code in llvm-as/llvm-dis,
because raw_fd_ostream does the right thing with '-'.
3. Switch machine verifier to use raw_ostream instead of ostream
(Which is the thing that needed append in the first place).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79807 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-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 |
11 files changed, 145 insertions, 182 deletions
diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 9fdcc1b..b2e427c 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 9554b8a..16b3471 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 cbc1d7b..423cf47 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 942dbeb..06b3ad2 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 65e97c3..2066fff 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 6b7846f..16e039b 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 17035e2..f789b15 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 a287c47..3d10ee3 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 4f5b8a0..af72fbc 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 f76168e..36be523 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 40f3fb9..4f24198 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) |