Driver now passes the top-level FunctionDecl* to GRConstants.

Refactoring: for GREngine and GRConstants, pushed references to CFG, ASTContext,
and the top-level FunctionDecl into ExplodedGraphImpl.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46475 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp
index 30c717f..69f344c 100644
--- a/Driver/ASTConsumers.cpp
+++ b/Driver/ASTConsumers.cpp
@@ -566,14 +566,12 @@
 // GRConstants - Perform intra-procedural, path-sensitive constant propagation.
 
 namespace {
-  class GRConstantsVisitor : public CFGVisitor {
+  class GRConstantsVisitor : public ASTConsumer {
     ASTContext* Ctx;
   public:
-    virtual void Initialize(ASTContext &Context) { Ctx = &Context; }
     
-    virtual void VisitCFG(CFG& C) {
-      RunGRConstants(C, *Ctx);
-    }
+    virtual void Initialize(ASTContext &Context) { Ctx = &Context; }    
+    virtual void HandleTopLevelDecl(Decl *D);
   };
 } // end anonymous namespace
 
@@ -581,6 +579,20 @@
   return new GRConstantsVisitor();
 }
 
+void GRConstantsVisitor::HandleTopLevelDecl(Decl *D) {
+  FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
+
+  if (!FD || !FD->getBody())
+    return;
+
+  DeclPrinter().PrintFunctionDeclStart(FD);
+  llvm::cerr << '\n';
+  
+  CFG *C = CFG::buildCFG(FD->getBody());
+  RunGRConstants(*C, *FD, *Ctx);
+  delete C;
+}
+
 //===----------------------------------------------------------------------===//
 // LLVM Emitter