From: Zhongxing Xu Date: Tue, 6 Jul 2010 09:18:02 +0000 (+0000) Subject: Add skeleton code to make wpa call the analysis engine. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65d336b6b9ec96a12e2f165188f80c5e813ff4ec;p=clang Add skeleton code to make wpa call the analysis engine. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107646 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/examples/wpa/Makefile b/examples/wpa/Makefile index 46fba7ca74..bd6ebfdc9b 100644 --- a/examples/wpa/Makefile +++ b/examples/wpa/Makefile @@ -16,7 +16,8 @@ NO_INSTALL = 1 TOOL_NO_EXPORTS = 1 LINK_COMPONENTS := asmparser bitreader mc core -USEDLIBS = clangIndex.a clangFrontend.a clangDriver.a clangSema.a \ - clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a +USEDLIBS = clangChecker.a clangIndex.a clangFrontend.a clangDriver.a \ + clangSema.a clangAnalysis.a clangAST.a clangParse.a clangLex.a \ + clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/examples/wpa/clang-wpa.cpp b/examples/wpa/clang-wpa.cpp index bfac398532..74ec368cfb 100644 --- a/examples/wpa/clang-wpa.cpp +++ b/examples/wpa/clang-wpa.cpp @@ -14,6 +14,10 @@ #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" @@ -21,6 +25,7 @@ #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" @@ -52,6 +57,10 @@ public: virtual ASTContext &getASTContext() { return AST->getASTContext(); } + + virtual Preprocessor &getPreprocessor() { + return AST->getPreprocessor(); + } virtual DeclReferenceMap &getDeclReferenceMap() { return DeclRefMap; @@ -101,8 +110,8 @@ int main(int argc, char **argv) { // Feed all ASTUnits to the Indexer. for (unsigned i = 0, e = ASTUnits.size(); i != e; ++i) { - ASTUnitTU TU(ASTUnits[i]); - Idxer.IndexAST(&TU); + ASTUnitTU *TU = new ASTUnitTU(ASTUnits[i]); + Idxer.IndexAST(TU); } Entity Ent = Entity::get(AnalyzeFunction, Prog); @@ -112,5 +121,25 @@ int main(int argc, char **argv) { 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); + + GRTransferFuncs* TF = MakeCFRefCountTF(AMgr.getASTContext(), /*GC*/false, + AMgr.getLangOptions()); + GRExprEngine Eng(AMgr, TF); + + Eng.ExecuteWorkList(AMgr.getStackFrame(FD), AMgr.getMaxNodes()); + return 0; } diff --git a/include/clang/Index/TranslationUnit.h b/include/clang/Index/TranslationUnit.h index bf9e78f728..b86ba3ee8a 100644 --- a/include/clang/Index/TranslationUnit.h +++ b/include/clang/Index/TranslationUnit.h @@ -16,6 +16,7 @@ namespace clang { class ASTContext; + class Preprocessor; namespace idx { class DeclReferenceMap; @@ -26,6 +27,7 @@ class TranslationUnit { public: virtual ~TranslationUnit(); virtual ASTContext &getASTContext() = 0; + virtual Preprocessor &getPreprocessor() = 0; virtual DeclReferenceMap &getDeclReferenceMap() = 0; virtual SelectorMap &getSelectorMap() = 0; };