[cfe-commits] r107646 - in /cfe/trunk: examples/wpa/Makefile examples/wpa/clang-wpa.cpp include/clang/Index/TranslationUnit.h

Zhongxing Xu xuzhongxing at gmail.com
Tue Jul 6 02:18:02 PDT 2010


Author: zhongxingxu
Date: Tue Jul  6 04:18:02 2010
New Revision: 107646

URL: http://llvm.org/viewvc/llvm-project?rev=107646&view=rev
Log:
Add skeleton code to make wpa call the analysis engine.

Modified:
    cfe/trunk/examples/wpa/Makefile
    cfe/trunk/examples/wpa/clang-wpa.cpp
    cfe/trunk/include/clang/Index/TranslationUnit.h

Modified: cfe/trunk/examples/wpa/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/wpa/Makefile?rev=107646&r1=107645&r2=107646&view=diff
==============================================================================
--- cfe/trunk/examples/wpa/Makefile (original)
+++ cfe/trunk/examples/wpa/Makefile Tue Jul  6 04:18:02 2010
@@ -16,7 +16,8 @@
 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

Modified: cfe/trunk/examples/wpa/clang-wpa.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/wpa/clang-wpa.cpp?rev=107646&r1=107645&r2=107646&view=diff
==============================================================================
--- cfe/trunk/examples/wpa/clang-wpa.cpp (original)
+++ cfe/trunk/examples/wpa/clang-wpa.cpp Tue Jul  6 04:18:02 2010
@@ -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 @@
   virtual ASTContext &getASTContext() {
     return AST->getASTContext();
   }
+  
+  virtual Preprocessor &getPreprocessor() {
+    return AST->getPreprocessor();
+  }
 
   virtual DeclReferenceMap &getDeclReferenceMap() {
     return DeclRefMap;
@@ -101,8 +110,8 @@
 
   // 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 @@
 
   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;
 }

Modified: cfe/trunk/include/clang/Index/TranslationUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/TranslationUnit.h?rev=107646&r1=107645&r2=107646&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/TranslationUnit.h (original)
+++ cfe/trunk/include/clang/Index/TranslationUnit.h Tue Jul  6 04:18:02 2010
@@ -16,6 +16,7 @@
 
 namespace clang {
   class ASTContext;
+  class Preprocessor;
 
 namespace idx {
   class DeclReferenceMap;
@@ -26,6 +27,7 @@
 public:
   virtual ~TranslationUnit();
   virtual ASTContext &getASTContext() = 0;
+  virtual Preprocessor &getPreprocessor() = 0;
   virtual DeclReferenceMap &getDeclReferenceMap() = 0;
   virtual SelectorMap &getSelectorMap() = 0;
 };





More information about the cfe-commits mailing list