[cfe-commits] r47497 - in /cfe/trunk/Driver: ASTConsumers.cpp ASTConsumers.h clang.cpp

Ted Kremenek kremenek at apple.com
Fri Feb 22 12:00:31 PST 2008


Author: kremenek
Date: Fri Feb 22 14:00:31 2008
New Revision: 47497

URL: http://llvm.org/viewvc/llvm-project?rev=47497&view=rev
Log:
clang driver options --dump-cfg and --view-cfg now (optionally) use the
--analyze-function option to dump/view the CFGs of specific functions.

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/ASTConsumers.h
    cfe/trunk/Driver/clang.cpp

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=47497&r1=47496&r2=47497&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Fri Feb 22 14:00:31 2008
@@ -453,7 +453,11 @@
 namespace {
 
 class CFGVisitor : public ASTConsumer {
+  std::string FName;
 public:
+  CFGVisitor(const std::string& fname) : FName(fname) {}
+  CFGVisitor() : FName("") {}
+  
   // CFG Visitor interface to be implemented by subclass.
   virtual void VisitCFG(CFG& C, FunctionDecl& FD) = 0;
   virtual bool printFuncDeclStart() { return true; }
@@ -465,8 +469,12 @@
 
 void CFGVisitor::HandleTopLevelDecl(Decl *D) {
   FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
+
   if (!FD || !FD->getBody())
     return;
+  
+  if (FName.size() > 0 && FName != FD->getIdentifier()->getName())
+    return;
       
   if (printFuncDeclStart()) {
     DeclPrinter().PrintFunctionDeclStart(FD);
@@ -485,7 +493,8 @@
   class CFGDumper : public CFGVisitor {
     const bool UseGraphviz;
   public:
-    CFGDumper(bool use_graphviz) : UseGraphviz(use_graphviz) {}
+    CFGDumper(bool use_graphviz, const std::string& fname) 
+     : CFGVisitor(fname), UseGraphviz(use_graphviz) {}
     
     virtual void VisitCFG(CFG& C, FunctionDecl&) {
       if (UseGraphviz)
@@ -496,8 +505,8 @@
   }; 
 } // end anonymous namespace 
   
-ASTConsumer *clang::CreateCFGDumper(bool ViewGraphs) {
-  return new CFGDumper(ViewGraphs);
+ASTConsumer *clang::CreateCFGDumper(bool ViewGraphs, const std::string& FName) {
+  return new CFGDumper(ViewGraphs, FName);
 }
 
 //===----------------------------------------------------------------------===//
@@ -582,10 +591,10 @@
     Diagnostic &Diags;
     ASTContext* Ctx;
     bool Visualize;
-    std::string FName;
   public:
-    GRSimpleValsVisitor(Diagnostic &diags, const std::string& fname, bool visualize)
-      : Diags(diags), Visualize(visualize), FName(fname) {}
+    GRSimpleValsVisitor(Diagnostic &diags, const std::string& fname,
+                        bool visualize)
+      : CFGVisitor(fname), Diags(diags), Visualize(visualize) {}
     
     virtual void Initialize(ASTContext &Context) { Ctx = &Context; }    
     virtual void VisitCFG(CFG& C, FunctionDecl&);
@@ -601,8 +610,6 @@
 }
 
 void GRSimpleValsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
-  if (FName.size() > 0 && FName != FD.getIdentifier()->getName())
-    return;
   
   SourceLocation Loc = FD.getLocation();
   

Modified: cfe/trunk/Driver/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=47497&r1=47496&r2=47497&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Fri Feb 22 14:00:31 2008
@@ -34,7 +34,7 @@
 
 ASTConsumer *CreateASTViewer();
 
-ASTConsumer *CreateCFGDumper(bool ViewGraphs = false);
+ASTConsumer *CreateCFGDumper(bool ViewGraphs, const std::string& FName);
 
 ASTConsumer *CreateLiveVarAnalyzer();
 

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=47497&r1=47496&r2=47497&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Fri Feb 22 14:00:31 2008
@@ -978,7 +978,8 @@
       
     case ParseCFGDump:
     case ParseCFGView:
-      return CreateCFGDumper(ProgAction == ParseCFGView);
+      return CreateCFGDumper(ProgAction == ParseCFGView,
+                             AnalyzeSpecificFunction);
       
     case AnalysisLiveVariables:
       return CreateLiveVarAnalyzer();





More information about the cfe-commits mailing list