]> granicus.if.org Git - clang/commitdiff
Moved logic for -dump-cfg and -view-cfg into AnalysisConsumer.
authorTed Kremenek <kremenek@apple.com>
Wed, 2 Jul 2008 18:23:21 +0000 (18:23 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 2 Jul 2008 18:23:21 +0000 (18:23 +0000)
Renamed -dump-cfg to -cfg-dump, and -view-cfg to -cfg-view.  This naming better matches the same options for asts (e.g. -ast-dump).

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

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

index 2d6eb69ac297efd09e0fbbd22f81c8cd3fa50166..4e909fc9086f84e2b4589d1582e1e0c6016deddf 100644 (file)
 #include "ASTConsumers.h"
 #include "HTMLDiagnostics.h"
 #include "clang/AST/TranslationUnit.h"
-#include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/AST/AST.h"
 #include "clang/AST/ASTConsumer.h"
-#include "clang/AST/CFG.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/ADT/OwningPtr.h"
@@ -518,92 +516,6 @@ namespace {
 
 ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); }
 
-
-//===----------------------------------------------------------------------===//
-// CFGVisitor & VisitCFGs - Boilerplate interface and logic to visit
-//   the CFGs for all function definitions.
-
-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, Decl& CD) = 0;
-  virtual bool printFuncDeclStart() { return true; }
-  
-  virtual void HandleTopLevelDecl(Decl *D);
-};
-
-} // end anonymous namespace
-
-void CFGVisitor::HandleTopLevelDecl(Decl *D) {
-  
-  CFG *C = NULL;
-  
-  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-
-    if (!FD->getBody())
-      return;
-  
-    if (FName.size() > 0 && FName != FD->getIdentifier()->getName())
-      return;
-      
-    if (printFuncDeclStart()) {
-      DeclPrinter().PrintFunctionDeclStart(FD);
-      llvm::cerr << '\n';
-    }
-      
-    C = CFG::buildCFG(FD->getBody());
-  }
-  else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
-    
-    if (!MD->getBody())
-      return;
-      
-    if (FName.size() > 0 && FName != MD->getSelector().getName())
-      return;
-    
-    if (printFuncDeclStart()) {
-      DeclPrinter().PrintObjCMethodDecl(MD);
-      llvm::cerr << '\n';
-    }
-    
-    C = CFG::buildCFG(MD->getBody());
-  }
-  
-  if (C) {  
-    VisitCFG(*C, *D);
-    delete C;
-  }
-}
-
-//===----------------------------------------------------------------------===//
-// DumpCFGs - Dump CFGs to stderr or visualize with Graphviz
-
-namespace {
-  class CFGDumper : public CFGVisitor {
-    const bool UseGraphviz;
-  public:
-    CFGDumper(bool use_graphviz, const std::string& fname) 
-     : CFGVisitor(fname), UseGraphviz(use_graphviz) {}
-    
-    virtual void VisitCFG(CFG& C, Decl&) {
-      if (UseGraphviz)
-        C.viewCFG();
-      else
-        C.dump();
-    }
-  }; 
-} // end anonymous namespace 
-  
-ASTConsumer *clang::CreateCFGDumper(bool ViewGraphs, const std::string& FName) {
-  return new CFGDumper(ViewGraphs, FName);
-}
-
 //===----------------------------------------------------------------------===//
 // AST Serializer
 
index 35ecc89eedc794dcebec86332e241ce03daae970..c3cadfdcec47ece89b426292011950e8390fcb47 100644 (file)
@@ -36,8 +36,6 @@ ASTConsumer *CreateASTDumper();
 
 ASTConsumer *CreateASTViewer();
 
-ASTConsumer *CreateCFGDumper(bool ViewGraphs, const std::string& FName);
-
 ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
                                     const std::string& OutFile,
                                     Diagnostic &Diags,
index ecb4ad23a0050108b59a0b0b92e2de11df17ef39..f8d9a250baf80161c34a93f7d84935d683c71997 100644 (file)
@@ -337,6 +337,16 @@ static void ActionLiveness(AnalysisManager& mgr) {
   mgr.getLiveVariables()->dumpBlockLiveness(mgr.getSourceManager());
 }
 
+static void ActionCFGDump(AnalysisManager& mgr) {
+  mgr.DisplayFunction();
+  mgr.getCFG()->dump();
+}
+
+static void ActionCFGView(AnalysisManager& mgr) {
+  mgr.DisplayFunction();
+  mgr.getCFG()->viewCFG();  
+}
+
 //===----------------------------------------------------------------------===//
 // AnalysisConsumer creation.
 //===----------------------------------------------------------------------===//
@@ -376,6 +386,14 @@ ASTConsumer* clang::CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
         C->addCodeAction(&ActionSimpleChecks);
         break;
         
+      case CFGDump:
+        C->addCodeAction(&ActionCFGDump);
+        break;
+        
+      case CFGView:
+        C->addCodeAction(&ActionCFGView);
+        break;
+        
       default: break;
     }
   
index 95de6b56a794662f0458e90180d685e68979f762..83f3cf67eb2c0c79ffb213c9c51b875ee2bb7dd0 100644 (file)
@@ -17,6 +17,8 @@
 namespace clang {
 
 enum Analyses {
+  CFGDump,
+  CFGView,
   WarnDeadStores,
   WarnUninitVals,
   DisplayLiveVariables,
index 0816f52fa46708899e2348d75efa8b5f42496bbf..0c6f30e20aa21006ee26fa7ce3c2c47778c06a80 100644 (file)
@@ -72,8 +72,6 @@ enum ProgActions {
   ASTPrint,                     // Parse ASTs and print them.
   ASTDump,                      // Parse ASTs and dump them.
   ASTView,                      // Parse ASTs and view them in Graphviz.
-  ParseCFGDump,                 // Parse ASTS. Build CFGs. Print CFGs.
-  ParseCFGView,                 // Parse ASTS. Build CFGs. View CFGs.
   TestSerialization,            // Run experimental serialization code.
   ParsePrintCallbacks,          // Parse and print each callback.
   ParseSyntaxOnly,              // Parse and perform semantic analysis.
@@ -108,10 +106,6 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
                         "Build ASTs and then debug dump them"),
              clEnumValN(ASTView, "ast-view",
                         "Build ASTs and view them with GraphViz"),
-             clEnumValN(ParseCFGDump, "dump-cfg",
-                        "Run parser, then build and print CFGs"),
-             clEnumValN(ParseCFGView, "view-cfg",
-                        "Run parser, then build and view CFGs with Graphviz"),
              clEnumValN(TestSerialization, "test-pickling",
                         "Run prototype serialization code"),
              clEnumValN(EmitLLVM, "emit-llvm",
@@ -168,6 +162,8 @@ AnalyzeAll("checker-opt-analyze-headers",
 static llvm::cl::list<Analyses>
 AnalysisList(llvm::cl::desc("Available Source Code Analyses:"),
 llvm::cl::values(
+clEnumValN(CFGDump, "cfg-dump", "Display Control-Flow Graphs"),
+clEnumValN(CFGView, "cfg-view", "View Control-Flow Graphs using GraphViz"),
 clEnumValN(DisplayLiveVariables, "dump-live-variables",
            "Print results of live variable analysis"),
 clEnumValN(WarnDeadStores, "warn-dead-stores",
@@ -1189,12 +1185,7 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
       
     case EmitHTML:
       return CreateHTMLPrinter(OutputFile, Diag, PP, PPF);
-      
-    case ParseCFGDump:
-    case ParseCFGView:
-      return CreateCFGDumper(ProgAction == ParseCFGView,
-                             AnalyzeSpecificFunction);
-      
+
     case TestSerialization:
       return CreateSerializationTest(Diag, FileMgr);