diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
commit | 1928da94b55683957759d5c5ff4593a118773394 (patch) | |
tree | 48b44512b5db8ced345df4a1a56b5065cf2a14d9 /examples/wpa | |
parent | 53992adde3eda3ccf9da63bc7e45673f043de18f (diff) | |
download | FreeBSD-src-1928da94b55683957759d5c5ff4593a118773394.zip FreeBSD-src-1928da94b55683957759d5c5ff4593a118773394.tar.gz |
Update clang to r108243.
Diffstat (limited to 'examples/wpa')
-rw-r--r-- | examples/wpa/CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/wpa/Makefile | 17 | ||||
-rw-r--r-- | examples/wpa/clang-wpa.cpp | 101 |
3 files changed, 103 insertions, 17 deletions
diff --git a/examples/wpa/CMakeLists.txt b/examples/wpa/CMakeLists.txt index 8d443d6..c2b2ce6 100644 --- a/examples/wpa/CMakeLists.txt +++ b/examples/wpa/CMakeLists.txt @@ -6,6 +6,8 @@ set(LLVM_USED_LIBS clangDriver clangSema clangAnalysis + clangChecker + clangRewrite clangAST clangParse clangLex diff --git a/examples/wpa/Makefile b/examples/wpa/Makefile index 6b7f407..bd6ebfd 100644 --- a/examples/wpa/Makefile +++ b/examples/wpa/Makefile @@ -7,22 +7,17 @@ # ##===----------------------------------------------------------------------===## -LEVEL = ../../../.. +CLANG_LEVEL := ../.. TOOLNAME = clang-wpa -CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include NO_INSTALL = 1 # No plugins, optimize startup time. TOOL_NO_EXPORTS = 1 -# Include this here so we can get the configuration of the targets that have -# been configured for construction. We have to do this early so we can set up -# LINK_COMPONENTS before including Makefile.rules -include $(LEVEL)/Makefile.config +LINK_COMPONENTS := asmparser bitreader mc core +USEDLIBS = clangChecker.a clangIndex.a clangFrontend.a clangDriver.a \ + clangSema.a clangAnalysis.a clangAST.a clangParse.a clangLex.a \ + clangBasic.a -LINK_COMPONENTS := bitreader mc core -USEDLIBS = clangIndex.a clangFrontend.a clangDriver.a clangSema.a \ - clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a - -include $(LLVM_SRC_ROOT)/Makefile.rules +include $(CLANG_LEVEL)/Makefile diff --git a/examples/wpa/clang-wpa.cpp b/examples/wpa/clang-wpa.cpp index b515e33..74ec368 100644 --- a/examples/wpa/clang-wpa.cpp +++ b/examples/wpa/clang-wpa.cpp @@ -14,9 +14,18 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" +#include "clang/Checker/PathSensitive/AnalysisManager.h" +#include "clang/Checker/PathSensitive/GRExprEngine.h" +#include "clang/Checker/PathSensitive/GRTransferFuncs.h" +#include "clang/Checker/Checkers/LocalCheckers.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Index/CallGraph.h" +#include "clang/Index/Indexer.h" +#include "clang/Index/TranslationUnit.h" +#include "clang/Index/DeclReferenceMap.h" +#include "clang/Index/SelectorMap.h" +#include "clang/Lex/Preprocessor.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" @@ -26,11 +35,50 @@ using namespace idx; static llvm::cl::list<std::string> InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>")); +static llvm::cl::opt<bool> +ViewCallGraph("view-call-graph", llvm::cl::desc("Display the call graph.")); + +static llvm::cl::opt<std::string> +AnalyzeFunction("analyze-function", + llvm::cl::desc("Specify the entry function.")); + +namespace { +// A thin wrapper over ASTUnit implementing the TranslationUnit interface. +class ASTUnitTU : public TranslationUnit { + ASTUnit *AST; + DeclReferenceMap DeclRefMap; + SelectorMap SelMap; + +public: + ASTUnitTU(ASTUnit *ast) + : AST(ast), DeclRefMap(AST->getASTContext()), SelMap(AST->getASTContext()) { + } + + virtual ASTContext &getASTContext() { + return AST->getASTContext(); + } + + virtual Preprocessor &getPreprocessor() { + return AST->getPreprocessor(); + } + + virtual DeclReferenceMap &getDeclReferenceMap() { + return DeclRefMap; + } + + virtual SelectorMap &getSelectorMap() { + return SelMap; + } +}; +} + int main(int argc, char **argv) { llvm::cl::ParseCommandLineOptions(argc, argv, "clang-wpa"); - FileManager FileMgr; std::vector<ASTUnit*> ASTUnits; + Program Prog; + Indexer Idxer(Prog); + if (InputFilenames.empty()) return 0; @@ -46,11 +94,52 @@ int main(int argc, char **argv) { ASTUnits.push_back(AST.take()); } - llvm::OwningPtr<CallGraph> CG; - CG.reset(new CallGraph()); + if (ViewCallGraph) { + llvm::OwningPtr<CallGraph> CG; + CG.reset(new CallGraph(Prog)); + + for (unsigned i = 0, e = ASTUnits.size(); i != e; ++i) + CG->addTU(ASTUnits[i]->getASTContext()); + + CG->ViewCallGraph(); + return 0; + } + + if (AnalyzeFunction.empty()) + return 0; + + // Feed all ASTUnits to the Indexer. + for (unsigned i = 0, e = ASTUnits.size(); i != e; ++i) { + ASTUnitTU *TU = new ASTUnitTU(ASTUnits[i]); + Idxer.IndexAST(TU); + } + + Entity Ent = Entity::get(AnalyzeFunction, Prog); + FunctionDecl *FD; + TranslationUnit *TU; + llvm::tie(FD, TU) = Idxer.getDefinitionFor(Ent); + + if (!FD) + return 0; + + // Create an analysis engine. + Preprocessor &PP = TU->getPreprocessor(); + + // Hard code options for now. + AnalysisManager AMgr(TU->getASTContext(), PP.getDiagnostics(), + PP.getLangOptions(), /* PathDiagnostic */ 0, + CreateRegionStoreManager, + CreateRangeConstraintManager, + /* MaxNodes */ 300000, /* MaxLoop */ 3, + /* VisualizeEG */ false, /* VisualizeEGUbi */ false, + /* PurgeDead */ true, /* EagerlyAssume */ false, + /* TrimGraph */ false, /* InlineCall */ true); - for (unsigned i = 0, e = ASTUnits.size(); i != e; ++i) - CG->addTU(ASTUnits[i]->getASTContext()); + GRTransferFuncs* TF = MakeCFRefCountTF(AMgr.getASTContext(), /*GC*/false, + AMgr.getLangOptions()); + GRExprEngine Eng(AMgr, TF); - CG->ViewCallGraph(); + Eng.ExecuteWorkList(AMgr.getStackFrame(FD), AMgr.getMaxNodes()); + + return 0; } |