From 9779e92fa4e659381b86f75726da0848fcc66bd3 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Thu, 18 Sep 2008 14:10:13 +0000 Subject: [PATCH] Add driver support for invoking block rewriter. Also tweaked the create function to take an explicit output file. llvm-svn: 56305 --- clang/Driver/ASTConsumers.h | 1 + clang/Driver/RewriteBlocks.cpp | 31 ++++++++++++++++++++----------- clang/Driver/clang.cpp | 6 ++++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/clang/Driver/ASTConsumers.h b/clang/Driver/ASTConsumers.h index 8375a8d67008..c1bf2300cebc 100644 --- a/clang/Driver/ASTConsumers.h +++ b/clang/Driver/ASTConsumers.h @@ -59,6 +59,7 @@ ASTConsumer *CreateASTSerializer(const std::string& InFile, Diagnostic &Diags); ASTConsumer *CreateBlockRewriter(const std::string& InFile, + const std::string& OutFile, Diagnostic &Diags, const LangOptions &LangOpts); } // end clang namespace diff --git a/clang/Driver/RewriteBlocks.cpp b/clang/Driver/RewriteBlocks.cpp index 753f4ffa2ef7..4f91606bfa42 100644 --- a/clang/Driver/RewriteBlocks.cpp +++ b/clang/Driver/RewriteBlocks.cpp @@ -55,17 +55,11 @@ class RewriteBlocks : public ASTConsumer { ObjCMethodDecl *CurMethodDef; bool IsHeader; + std::string InFileName; + std::string OutFileName; public: - RewriteBlocks(bool isHeader, Diagnostic &D, const LangOptions &LOpts) : - Diags(D), LangOpts(LOpts) { - IsHeader = isHeader; - CurFunctionDef = 0; - CurMethodDef = 0; - RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning, - "rewriting failed"); - NoNestedBlockCalls = Diags.getCustomDiagID(Diagnostic::Warning, - "Rewrite support for closure calls nested within closure blocks is incomplete"); - } + RewriteBlocks(std::string inFile, std::string outFile, Diagnostic &D, + const LangOptions &LOpts); ~RewriteBlocks() { // Get the buffer corresponding to MainFileID. // If we haven't changed it, then we are done. @@ -155,10 +149,25 @@ static bool IsHeaderFile(const std::string &Filename) { return Ext == "h" || Ext == "hh" || Ext == "H"; } +RewriteBlocks::RewriteBlocks(std::string inFile, std::string outFile, + Diagnostic &D, const LangOptions &LOpts) : + Diags(D), LangOpts(LOpts) { + IsHeader = IsHeaderFile(inFile); + InFileName = inFile; + OutFileName = outFile; + CurFunctionDef = 0; + CurMethodDef = 0; + RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning, + "rewriting failed"); + NoNestedBlockCalls = Diags.getCustomDiagID(Diagnostic::Warning, + "Rewrite support for closure calls nested within closure blocks is incomplete"); +} + ASTConsumer *clang::CreateBlockRewriter(const std::string& InFile, + const std::string& OutFile, Diagnostic &Diags, const LangOptions &LangOpts) { - return new RewriteBlocks(IsHeaderFile(InFile), Diags, LangOpts); + return new RewriteBlocks(InFile, OutFile, Diags, LangOpts); } void RewriteBlocks::Initialize(ASTContext &context) { diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 0efe56a35073..ff98bff9dc8b 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -61,6 +61,7 @@ Stats("print-stats", enum ProgActions { RewriteObjC, // ObjC->C Rewriter. + RewriteBlocks, // ObjC->C Rewriter for Blocks. RewriteMacros, // Expand macros but not #includes. HTMLTest, // HTML displayer testing stuff. EmitLLVM, // Emit a .ll file. @@ -116,6 +117,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, "Rewrite ObjC into C (code rewriter example)"), clEnumValN(RewriteMacros, "rewrite-macros", "Expand macros without full preprocessing"), + clEnumValN(RewriteBlocks, "rewrite-blocks", + "Rewrite Blocks to C"), clEnumValEnd)); @@ -989,6 +992,9 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, case RewriteObjC: return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts); + + case RewriteBlocks: + return CreateBlockRewriter(InFile, OutputFile, Diag, LangOpts); case RunAnalysis: assert (!AnalysisList.empty());