summaryrefslogtreecommitdiffstats
path: root/utils/TableGen/TableGen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/TableGen/TableGen.cpp')
-rw-r--r--utils/TableGen/TableGen.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp
index 038cde2..6015814 100644
--- a/utils/TableGen/TableGen.cpp
+++ b/utils/TableGen/TableGen.cpp
@@ -18,11 +18,11 @@
#include "Record.h"
#include "TGParser.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Streams.h"
#include "llvm/System/Signals.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/raw_ostream.h"
#include "CallingConvEmitter.h"
#include "CodeEmitterGen.h"
#include "RegisterInfoEmitter.h"
@@ -37,8 +37,6 @@
#include "ClangDiagnosticsEmitter.h"
#include <algorithm>
#include <cstdio>
-#include <fstream>
-#include <ios>
using namespace llvm;
enum ActionType {
@@ -127,7 +125,7 @@ RecordKeeper llvm::Records;
static SourceMgr SrcMgr;
void llvm::PrintError(SMLoc ErrorLoc, const std::string &Msg) {
- SrcMgr.PrintMessage(ErrorLoc, Msg);
+ SrcMgr.PrintMessage(ErrorLoc, Msg, "error");
}
@@ -140,7 +138,8 @@ static bool ParseFile(const std::string &Filename,
std::string ErrorStr;
MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
if (F == 0) {
- cerr << "Could not open input file '" + Filename + "': " << ErrorStr <<"\n";
+ errs() << "Could not open input file '" + Filename + "': "
+ << ErrorStr <<"\n";
return true;
}
@@ -166,12 +165,14 @@ int main(int argc, char **argv) {
if (ParseFile(InputFilename, IncludeDirs, SrcMgr))
return 1;
- std::ostream *Out = cout.stream();
+ raw_ostream *Out = &outs();
if (OutputFilename != "-") {
- Out = new std::ofstream(OutputFilename.c_str());
+ std::string Error;
+ Out = new raw_fd_ostream(OutputFilename.c_str(), false, Error);
- if (!Out->good()) {
- cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
+ if (!Error.empty()) {
+ errs() << argv[0] << ": error opening " << OutputFilename
+ << ":" << Error << "\n";
return 1;
}
@@ -246,23 +247,23 @@ int main(int argc, char **argv) {
return 1;
}
- if (Out != cout.stream())
+ if (Out != &outs())
delete Out; // Close the file
return 0;
} catch (const TGError &Error) {
- cerr << argv[0] << ": error:\n";
+ errs() << argv[0] << ": error:\n";
PrintError(Error.getLoc(), Error.getMessage());
} catch (const std::string &Error) {
- cerr << argv[0] << ": " << Error << "\n";
+ errs() << argv[0] << ": " << Error << "\n";
} catch (const char *Error) {
- cerr << argv[0] << ": " << Error << "\n";
+ errs() << argv[0] << ": " << Error << "\n";
} catch (...) {
- cerr << argv[0] << ": Unknown unexpected exception occurred.\n";
+ errs() << argv[0] << ": Unknown unexpected exception occurred.\n";
}
- if (Out != cout.stream()) {
+ if (Out != &outs()) {
delete Out; // Close the file
std::remove(OutputFilename.c_str()); // Remove the file, it's broken
}
OpenPOWER on IntegriCloud