]> granicus.if.org Git - clang/commitdiff
Move -dump-live-variables logic to AnalysisConsumer.
authorTed Kremenek <kremenek@apple.com>
Wed, 2 Jul 2008 18:11:29 +0000 (18:11 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 2 Jul 2008 18:11:29 +0000 (18:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53039 91177308-0d34-0410-b5e6-96231b3b80d8

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

index fb8dc80a3d56e94d16528ba64f2e0bf074c9a6ec..2d6eb69ac297efd09e0fbbd22f81c8cd3fa50166 100644 (file)
 #include "clang/AST/AST.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/CFG.h"
-#include "clang/AST/ParentMap.h"
-#include "clang/Analysis/Analyses/LiveVariables.h"
-#include "clang/Analysis/LocalCheckers.h"
-#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
-#include "clang/Analysis/PathSensitive/GRExprEngine.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/ADT/OwningPtr.h"
@@ -609,31 +604,6 @@ ASTConsumer *clang::CreateCFGDumper(bool ViewGraphs, const std::string& FName) {
   return new CFGDumper(ViewGraphs, FName);
 }
 
-//===----------------------------------------------------------------------===//
-// AnalyzeLiveVariables - perform live variable analysis and dump results
-
-namespace {
-  class LivenessVisitor : public CFGVisitor {
-    SourceManager *SM;
-  public:
-    LivenessVisitor(const std::string& fname) : CFGVisitor(fname) {}
-    
-    virtual void Initialize(ASTContext &Context) {
-      SM = &Context.getSourceManager();
-    }
-
-    virtual void VisitCFG(CFG& C, Decl& CD) {
-      LiveVariables L(C);
-      L.runOnCFG(C);
-      L.dumpBlockLiveness(*SM);
-    }
-  };
-} // end anonymous namespace
-  
-ASTConsumer *clang::CreateLiveVarAnalyzer(const std::string& fname) {
-  return new LivenessVisitor(fname);
-}
-
 //===----------------------------------------------------------------------===//
 // AST Serializer
 
index 6bba0bbab90195e90eef88124a883b3201226eac..35ecc89eedc794dcebec86332e241ce03daae970 100644 (file)
@@ -38,8 +38,6 @@ ASTConsumer *CreateASTViewer();
 
 ASTConsumer *CreateCFGDumper(bool ViewGraphs, const std::string& FName);
 
-ASTConsumer *CreateLiveVarAnalyzer(const std::string& fname);
-
 ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
                                     const std::string& OutFile,
                                     Diagnostic &Diags,
index 2f2e76e67718ef732ccbddb6e80522614eca7979..ecb4ad23a0050108b59a0b0b92e2de11df17ef39 100644 (file)
@@ -131,6 +131,10 @@ namespace {
       return *C.Ctx;
     }
     
+    SourceManager& getSourceManager() {
+      return getContext().getSourceManager();
+    }
+    
     Diagnostic& getDiagnostic() {
       return C.Diags;
     }
@@ -147,7 +151,10 @@ namespace {
     }
       
     LiveVariables* getLiveVariables() {
-      if (!liveness) liveness.reset(new LiveVariables(*getCFG()));
+      if (!liveness) {
+        liveness.reset(new LiveVariables(*getCFG()));
+        liveness->runOnCFG(*getCFG());
+      }
       return liveness.get();
     }
     
@@ -200,6 +207,10 @@ void AnalysisConsumer::HandleTopLevelDecl(Decl *D) {
   switch (D->getKind()) {
     case Decl::Function: {
       FunctionDecl* FD = cast<FunctionDecl>(D);
+
+      if (FName.size() > 0 && FName != FD->getIdentifier()->getName())
+        break;
+      
       Stmt* Body = FD->getBody();
       if (Body) HandleCode(FD, Body, FunctionActions);
       break;
@@ -207,6 +218,10 @@ void AnalysisConsumer::HandleTopLevelDecl(Decl *D) {
       
     case Decl::ObjCMethod: {
       ObjCMethodDecl* MD = cast<ObjCMethodDecl>(D);
+      
+      if (FName.size() > 0 && FName != MD->getSelector().getName())
+        return;
+      
       Stmt* Body = MD->getBody();
       if (Body) HandleCode(MD, Body, ObjCMethodActions);
       break;
@@ -317,6 +332,11 @@ static void ActionSimpleChecks(AnalysisManager& mgr) {
   ActionGRExprEngine(mgr, MakeGRSimpleValsTF());
 }
 
+static void ActionLiveness(AnalysisManager& mgr) {
+  mgr.DisplayFunction();
+  mgr.getLiveVariables()->dumpBlockLiveness(mgr.getSourceManager());
+}
+
 //===----------------------------------------------------------------------===//
 // AnalysisConsumer creation.
 //===----------------------------------------------------------------------===//
@@ -343,6 +363,10 @@ ASTConsumer* clang::CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
       case WarnUninitVals:
         C->addCodeAction(&ActionUninitVals);
         break;
+      
+      case DisplayLiveVariables:
+        C->addCodeAction(&ActionLiveness);
+        break;
         
       case CheckerCFRef:
         C->addCodeAction(&ActionRefLeakChecker);
index 487706b67591bbd8b26b71a1bb434dc2127b4b7d..95de6b56a794662f0458e90180d685e68979f762 100644 (file)
@@ -19,6 +19,7 @@ namespace clang {
 enum Analyses {
   WarnDeadStores,
   WarnUninitVals,
+  DisplayLiveVariables,
   CheckerCFRef,
   CheckerSimple
 };
index 9de09243305a1aac87a410579c20ea02ebca1cc5..0816f52fa46708899e2348d75efa8b5f42496bbf 100644 (file)
@@ -74,7 +74,6 @@ enum ProgActions {
   ASTView,                      // Parse ASTs and view them in Graphviz.
   ParseCFGDump,                 // Parse ASTS. Build CFGs. Print CFGs.
   ParseCFGView,                 // Parse ASTS. Build CFGs. View CFGs.
-  AnalysisLiveVariables,        // Print results of live-variable analysis.
   TestSerialization,            // Run experimental serialization code.
   ParsePrintCallbacks,          // Parse and print each callback.
   ParseSyntaxOnly,              // Parse and perform semantic analysis.
@@ -113,8 +112,6 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
                         "Run parser, then build and print CFGs"),
              clEnumValN(ParseCFGView, "view-cfg",
                         "Run parser, then build and view CFGs with Graphviz"),
-             clEnumValN(AnalysisLiveVariables, "dump-live-variables",
-                        "Print results of live variable analysis"),
              clEnumValN(TestSerialization, "test-pickling",
                         "Run prototype serialization code"),
              clEnumValN(EmitLLVM, "emit-llvm",
@@ -171,6 +168,8 @@ AnalyzeAll("checker-opt-analyze-headers",
 static llvm::cl::list<Analyses>
 AnalysisList(llvm::cl::desc("Available Source Code Analyses:"),
 llvm::cl::values(
+clEnumValN(DisplayLiveVariables, "dump-live-variables",
+           "Print results of live variable analysis"),
 clEnumValN(WarnDeadStores, "warn-dead-stores",
            "Flag warnings of stores to dead variables"),
 clEnumValN(WarnUninitVals, "warn-uninit-values",
@@ -1196,9 +1195,6 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
       return CreateCFGDumper(ProgAction == ParseCFGView,
                              AnalyzeSpecificFunction);
       
-    case AnalysisLiveVariables:
-      return CreateLiveVarAnalyzer(AnalyzeSpecificFunction);
-
     case TestSerialization:
       return CreateSerializationTest(Diag, FileMgr);