diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-04-16 05:21:09 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-04-16 05:21:09 +0000 |
| commit | dffe0f7db5fc6f7556c3513fc99f24d414c1b0f5 (patch) | |
| tree | 170ea68e00c02fe2204cea77b83aba409b5053de /clang/Driver | |
| parent | 088d12e7410c56a049ececfeb5c298c7444a61f8 (diff) | |
| download | bcm5719-llvm-dffe0f7db5fc6f7556c3513fc99f24d414c1b0f5.tar.gz bcm5719-llvm-dffe0f7db5fc6f7556c3513fc99f24d414c1b0f5.zip | |
Add -o support for -emit-html, make it not produce a file on an error.
llvm-svn: 49777
Diffstat (limited to 'clang/Driver')
| -rw-r--r-- | clang/Driver/ASTConsumers.h | 2 | ||||
| -rw-r--r-- | clang/Driver/HTMLPrint.cpp | 40 | ||||
| -rw-r--r-- | clang/Driver/clang.cpp | 8 |
3 files changed, 37 insertions, 13 deletions
diff --git a/clang/Driver/ASTConsumers.h b/clang/Driver/ASTConsumers.h index 30dac34292f..91ee8fbf938 100644 --- a/clang/Driver/ASTConsumers.h +++ b/clang/Driver/ASTConsumers.h @@ -57,7 +57,7 @@ ASTConsumer *CreateCodeRewriterTest(const std::string& InFile, Diagnostic &Diags, const LangOptions &LOpts); -ASTConsumer* CreateHTMLPrinter(); + ASTConsumer* CreateHTMLPrinter(const std::string &OutFile, Diagnostic &D); ASTConsumer *CreateSerializationTest(Diagnostic &Diags, FileManager& FMgr, diff --git a/clang/Driver/HTMLPrint.cpp b/clang/Driver/HTMLPrint.cpp index a0a76a566e7..44cd6244ecc 100644 --- a/clang/Driver/HTMLPrint.cpp +++ b/clang/Driver/HTMLPrint.cpp @@ -15,6 +15,7 @@ #include "clang/AST/ASTConsumer.h" #include "clang/Rewrite/Rewriter.h" #include "clang/Rewrite/HTMLRewrite.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/AST/ASTContext.h" @@ -27,33 +28,54 @@ using namespace clang; namespace { class HTMLPrinter : public ASTConsumer { Rewriter R; + std::string OutFilename; + Diagnostic &Diags; public: - HTMLPrinter() {} + HTMLPrinter(const std::string &OutFile, Diagnostic &D) + : OutFilename(OutFile), Diags(D) {} virtual ~HTMLPrinter(); void Initialize(ASTContext &context); }; } -ASTConsumer* clang::CreateHTMLPrinter() { return new HTMLPrinter(); } +ASTConsumer* clang::CreateHTMLPrinter(const std::string &OutFile, + Diagnostic &D) { + return new HTMLPrinter(OutFile, D); +} void HTMLPrinter::Initialize(ASTContext &context) { R.setSourceMgr(context.getSourceManager()); } HTMLPrinter::~HTMLPrinter() { - + if (Diags.hasErrorOccurred()) + return; + + // Format the file. unsigned FileID = R.getSourceMgr().getMainFileID(); html::EscapeText(R, FileID, false, true); html::AddLineNumbers(R, FileID); html::AddHeaderFooterInternalBuiltinCSS(R, FileID); + + // Open the output. + FILE *OutputFILE; + if (OutFilename.empty() || OutFilename == "-") + OutputFILE = stdout; + else { + OutputFILE = fopen(OutFilename.c_str(), "w+"); + if (OutputFILE == 0) { + fprintf(stderr, "Error opening output file '%s'.\n", OutFilename.c_str()); + exit(1); + } + } // Emit the HTML. + const RewriteBuffer &RewriteBuf = R.getEditBuffer(FileID); + char *Buffer = (char*)malloc(RewriteBuf.size()); + std::copy(RewriteBuf.begin(), RewriteBuf.end(), Buffer); + fwrite(Buffer, 1, RewriteBuf.size(), OutputFILE); + free(Buffer); - if (const RewriteBuffer *RewriteBuf = R.getRewriteBufferFor(FileID)) { - char *Buffer = (char*)malloc(RewriteBuf->size()); - std::copy(RewriteBuf->begin(), RewriteBuf->end(), Buffer); - fwrite(Buffer, 1, RewriteBuf->size(), stdout); - free(Buffer); - } + if (OutputFILE != stdout) fclose(OutputFILE); } diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 7a2996a3098..09140c942e0 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -918,8 +918,10 @@ static void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers, // Fedora 8 AddPath("/usr/include/c++/4.1.2", System, true, false, false, Headers); - AddPath("/usr/include/c++/4.1.2/i386-redhat-linux", System, true, false, false, Headers); - AddPath("/usr/include/c++/4.1.2/backward", System, true, false, false, Headers); + AddPath("/usr/include/c++/4.1.2/i386-redhat-linux", System, true, false, + false, Headers); + AddPath("/usr/include/c++/4.1.2/backward", System, true, false, false, + Headers); } AddPath("/usr/local/include", System, false, false, false, Headers); @@ -1046,7 +1048,7 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, return CreateASTViewer(); case EmitHTML: - return CreateHTMLPrinter(); + return CreateHTMLPrinter(OutputFile, Diag); case ParseCFGDump: case ParseCFGView: |

