]> granicus.if.org Git - clang/commitdiff
clang driver options --dump-cfg and --view-cfg now (optionally) use the
authorTed Kremenek <kremenek@apple.com>
Fri, 22 Feb 2008 20:00:31 +0000 (20:00 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 22 Feb 2008 20:00:31 +0000 (20:00 +0000)
--analyze-function option to dump/view the CFGs of specific functions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47497 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/ASTConsumers.cpp
Driver/ASTConsumers.h
Driver/clang.cpp

index 2b205f0941ce009784e4adc01ee816c22e8e2ec5..316bcd4c7bd1274f5ea7485626cb32b04f031c66 100644 (file)
@@ -453,7 +453,11 @@ ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); }
 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 @@ public:
 
 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 @@ namespace {
   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 @@ namespace {
   }; 
 } // 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 @@ namespace {
     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 @@ ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags,
 }
 
 void GRSimpleValsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
-  if (FName.size() > 0 && FName != FD.getIdentifier()->getName())
-    return;
   
   SourceLocation Loc = FD.getLocation();
   
index 005f797e431f2c56a573668ec07d98d00bcd8d9f..a0745cd792b9b0c12a1cffd08a69f05072e12b16 100644 (file)
@@ -34,7 +34,7 @@ ASTConsumer *CreateASTDumper();
 
 ASTConsumer *CreateASTViewer();
 
-ASTConsumer *CreateCFGDumper(bool ViewGraphs = false);
+ASTConsumer *CreateCFGDumper(bool ViewGraphs, const std::string& FName);
 
 ASTConsumer *CreateLiveVarAnalyzer();
 
index 08eef52acc585d0acba8be87162108faec3d5c03..15384c5f1c21c6cbe0e455f851fb9b285ab9c973 100644 (file)
@@ -978,7 +978,8 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
       
     case ParseCFGDump:
     case ParseCFGView:
-      return CreateCFGDumper(ProgAction == ParseCFGView);
+      return CreateCFGDumper(ProgAction == ParseCFGView,
+                             AnalyzeSpecificFunction);
       
     case AnalysisLiveVariables:
       return CreateLiveVarAnalyzer();