summaryrefslogtreecommitdiffstats
path: root/clang/Driver
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-02-22 20:00:31 +0000
committerTed Kremenek <kremenek@apple.com>2008-02-22 20:00:31 +0000
commit88329bf0ea6dab94f2496f8304884604b7ee4056 (patch)
treea8b260b2f27444240461770052c752a81ed0963e /clang/Driver
parenta1977d32f04c60d2f415b6bc197dbd48ae519696 (diff)
downloadbcm5719-llvm-88329bf0ea6dab94f2496f8304884604b7ee4056.tar.gz
bcm5719-llvm-88329bf0ea6dab94f2496f8304884604b7ee4056.zip
clang driver options --dump-cfg and --view-cfg now (optionally) use the
--analyze-function option to dump/view the CFGs of specific functions. llvm-svn: 47497
Diffstat (limited to 'clang/Driver')
-rw-r--r--clang/Driver/ASTConsumers.cpp23
-rw-r--r--clang/Driver/ASTConsumers.h2
-rw-r--r--clang/Driver/clang.cpp3
3 files changed, 18 insertions, 10 deletions
diff --git a/clang/Driver/ASTConsumers.cpp b/clang/Driver/ASTConsumers.cpp
index 2b205f0941c..316bcd4c7bd 100644
--- a/clang/Driver/ASTConsumers.cpp
+++ b/clang/Driver/ASTConsumers.cpp
@@ -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();
diff --git a/clang/Driver/ASTConsumers.h b/clang/Driver/ASTConsumers.h
index 005f797e431..a0745cd792b 100644
--- a/clang/Driver/ASTConsumers.h
+++ b/clang/Driver/ASTConsumers.h
@@ -34,7 +34,7 @@ ASTConsumer *CreateASTDumper();
ASTConsumer *CreateASTViewer();
-ASTConsumer *CreateCFGDumper(bool ViewGraphs = false);
+ASTConsumer *CreateCFGDumper(bool ViewGraphs, const std::string& FName);
ASTConsumer *CreateLiveVarAnalyzer();
diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp
index 08eef52acc5..15384c5f1c2 100644
--- a/clang/Driver/clang.cpp
+++ b/clang/Driver/clang.cpp
@@ -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();
OpenPOWER on IntegriCloud