From 235e031e84dd9d9aeee554db40e480f14650b527 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 2 Jul 2008 18:11:29 +0000 Subject: [PATCH] Move -dump-live-variables logic to AnalysisConsumer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53039 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/ASTConsumers.cpp | 30 ------------------------------ Driver/ASTConsumers.h | 2 -- Driver/AnalysisConsumer.cpp | 26 +++++++++++++++++++++++++- Driver/AnalysisConsumer.h | 1 + Driver/clang.cpp | 8 ++------ 5 files changed, 28 insertions(+), 39 deletions(-) diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index fb8dc80a3d..2d6eb69ac2 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -20,11 +20,6 @@ #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 diff --git a/Driver/ASTConsumers.h b/Driver/ASTConsumers.h index 6bba0bbab9..35ecc89eed 100644 --- a/Driver/ASTConsumers.h +++ b/Driver/ASTConsumers.h @@ -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, diff --git a/Driver/AnalysisConsumer.cpp b/Driver/AnalysisConsumer.cpp index 2f2e76e677..ecb4ad23a0 100644 --- a/Driver/AnalysisConsumer.cpp +++ b/Driver/AnalysisConsumer.cpp @@ -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(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(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); diff --git a/Driver/AnalysisConsumer.h b/Driver/AnalysisConsumer.h index 487706b675..95de6b56a7 100644 --- a/Driver/AnalysisConsumer.h +++ b/Driver/AnalysisConsumer.h @@ -19,6 +19,7 @@ namespace clang { enum Analyses { WarnDeadStores, WarnUninitVals, + DisplayLiveVariables, CheckerCFRef, CheckerSimple }; diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 9de0924330..0816f52fa4 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -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 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); -- 2.40.0