Add driver support for invoking block rewriter.
Also tweaked the create function to take an explicit output file.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56305 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/ASTConsumers.h b/Driver/ASTConsumers.h
index 8375a8d..c1bf230 100644
--- a/Driver/ASTConsumers.h
+++ b/Driver/ASTConsumers.h
@@ -59,6 +59,7 @@
                                  Diagnostic &Diags);
 
 ASTConsumer *CreateBlockRewriter(const std::string& InFile,
+                                 const std::string& OutFile,
                                  Diagnostic &Diags,
                                  const LangOptions &LangOpts);
 } // end clang namespace
diff --git a/Driver/RewriteBlocks.cpp b/Driver/RewriteBlocks.cpp
index 753f4ff..4f91606 100644
--- a/Driver/RewriteBlocks.cpp
+++ b/Driver/RewriteBlocks.cpp
@@ -55,17 +55,11 @@
   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 @@
   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/Driver/clang.cpp b/Driver/clang.cpp
index 0efe56a..ff98bff 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -61,6 +61,7 @@
 
 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 @@
                         "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 @@
       
     case RewriteObjC:
       return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts);
+
+    case RewriteBlocks:
+      return CreateBlockRewriter(InFile, OutputFile, Diag, LangOpts);
       
     case RunAnalysis:
       assert (!AnalysisList.empty());