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 | 9e6f1f160ab6810625629fd1e2dc8a809db83565 (patch) | |
| tree | 1165e8689cce0feb59958dfe42477fa586042971 /llvm/lib/CodeGen | |
| parent | 622ddae92b84022892d31e64de88a643e988a707 (diff) | |
| download | bcm5719-llvm-9e6f1f160ab6810625629fd1e2dc8a809db83565.tar.gz bcm5719-llvm-9e6f1f160ab6810625629fd1e2dc8a809db83565.zip | |
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).
llvm-svn: 79807
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/MachineVerifier.cpp | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp index 238f90568fc..ea2f8279d74 100644 --- a/llvm/lib/CodeGen/MachineVerifier.cpp +++ b/llvm/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" |

