aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/HeaderIncludeGen.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2011-02-03 03:45:00 +0000
committerDaniel Dunbar <daniel@zuster.org>2011-02-03 03:45:00 +0000
commit9aa47fcb55a54263793650e1e2e665614c363bdb (patch)
tree6f5389aff396e8b133b45da8256c1ac78b42cf99 /clang/lib/Frontend/HeaderIncludeGen.cpp
parent4fed88704d87eaa9b64f9901f380476f4134a8dc (diff)
downloadllvm-9aa47fcb55a54263793650e1e2e665614c363bdb.zip
llvm-9aa47fcb55a54263793650e1e2e665614c363bdb.tar.gz
llvm-9aa47fcb55a54263793650e1e2e665614c363bdb.tar.bz2
Frontend: Switch -header-include-file output to use unbuffered raw_ostreams with
the atomic writes option, since the intent is that this option be set for an entire build, which may have any number of compiler instances writing to the same output file. llvm-svn: 124772
Diffstat (limited to 'clang/lib/Frontend/HeaderIncludeGen.cpp')
-rw-r--r--clang/lib/Frontend/HeaderIncludeGen.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/clang/lib/Frontend/HeaderIncludeGen.cpp b/clang/lib/Frontend/HeaderIncludeGen.cpp
index 0d478d7..45ff1d2 100644
--- a/clang/lib/Frontend/HeaderIncludeGen.cpp
+++ b/clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -9,14 +9,15 @@
#include "clang/Frontend/Utils.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Lex/Preprocessor.h"
-#include <cstdio>
+#include "llvm/Support/raw_ostream.h"
using namespace clang;
namespace {
class HeaderIncludesCallback : public PPCallbacks {
SourceManager &SM;
- FILE *OutputFile;
+ llvm::raw_ostream *OutputFile;
unsigned CurrentIncludeDepth;
bool HasProcessedPredefines;
bool OwnsOutputFile;
@@ -24,14 +25,14 @@ class HeaderIncludesCallback : public PPCallbacks {
public:
HeaderIncludesCallback(const Preprocessor *PP, bool ShowAllHeaders_,
- FILE *OutputFile_, bool OwnsOutputFile_)
+ llvm::raw_ostream *OutputFile_, bool OwnsOutputFile_)
: SM(PP->getSourceManager()), OutputFile(OutputFile_),
CurrentIncludeDepth(0), HasProcessedPredefines(false),
OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_) {}
~HeaderIncludesCallback() {
if (OwnsOutputFile)
- fclose(OutputFile);
+ delete OutputFile;
}
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
@@ -41,16 +42,24 @@ public:
void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
llvm::StringRef OutputPath) {
- FILE *OutputFile;
- bool OwnsOutputFile;
+ llvm::raw_ostream *OutputFile = &llvm::errs();
+ bool OwnsOutputFile = false;
// Open the output file, if used.
- if (OutputPath.empty()) {
- OutputFile = stderr;
- OwnsOutputFile = false;
- } else {
- OutputFile = fopen(OutputPath.str().c_str(), "a");
- OwnsOutputFile = true;
+ if (!OutputPath.empty()) {
+ std::string Error;
+ llvm::raw_fd_ostream *OS = new llvm::raw_fd_ostream(
+ OutputPath.str().c_str(), Error, llvm::raw_fd_ostream::F_Append);
+ if (!Error.empty()) {
+ PP.getDiagnostics().Report(
+ clang::diag::warn_fe_cc_print_header_failure) << Error;
+ delete OS;
+ } else {
+ OS->SetUnbuffered();
+ OS->SetUseAtomicWrites(true);
+ OutputFile = OS;
+ OwnsOutputFile = true;
+ }
}
PP.addPPCallbacks(new HeaderIncludesCallback(&PP, ShowAllHeaders,
@@ -99,7 +108,6 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
Msg += Filename;
Msg += '\n';
- fwrite(Msg.data(), Msg.size(), 1, OutputFile);
+ OutputFile->write(Msg.data(), Msg.size());
}
}
-