[cfe-commits] r75874 - in /cfe/trunk/tools/wpa: ./ Makefile clang-wpa.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Wed Jul 15 18:00:26 PDT 2009
Author: zhongxingxu
Date: Wed Jul 15 20:00:25 2009
New Revision: 75874
URL: http://llvm.org/viewvc/llvm-project?rev=75874&view=rev
Log:
Add a primitive clang whole primitive analyzer tool.
Added:
cfe/trunk/tools/wpa/
cfe/trunk/tools/wpa/Makefile
cfe/trunk/tools/wpa/clang-wpa.cpp
Added: cfe/trunk/tools/wpa/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/wpa/Makefile?rev=75874&view=auto
==============================================================================
--- cfe/trunk/tools/wpa/Makefile (added)
+++ cfe/trunk/tools/wpa/Makefile Wed Jul 15 20:00:25 2009
@@ -0,0 +1,15 @@
+LEVEL = ../../../..
+
+TOOLNAME = clang-wpa
+CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
+CXXFLAGS = -fno-rtti
+
+# No plugins, optimize startup time.
+TOOL_NO_EXPORTS = 1
+
+include $(LEVEL)/Makefile.config
+
+LINK_COMPONENTS := bitreader
+USEDLIBS = clangFrontend.a clangSema.a clangAST.a clangLex.a clangBasic.a clangAnalysis.a clangIndex.a
+
+include $(LLVM_SRC_ROOT)/Makefile.rules
Added: cfe/trunk/tools/wpa/clang-wpa.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/wpa/clang-wpa.cpp?rev=75874&view=auto
==============================================================================
--- cfe/trunk/tools/wpa/clang-wpa.cpp (added)
+++ cfe/trunk/tools/wpa/clang-wpa.cpp Wed Jul 15 20:00:25 2009
@@ -0,0 +1,55 @@
+#include "clang/Analysis/CallGraph.h"
+
+#include "clang/Basic/FileManager.h"
+#include "clang/Index/TranslationUnit.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/raw_ostream.h"
+using namespace clang;
+using namespace idx;
+
+static llvm::cl::list<std::string>
+InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>"));
+
+// FIXME: this duplicates the one in index-test.cpp.
+class TUnit : public TranslationUnit {
+public:
+ TUnit(ASTUnit *ast, const std::string &filename)
+ : AST(ast), Filename(filename) {}
+ ASTContext &getASTContext() { return AST->getASTContext(); }
+ llvm::OwningPtr<ASTUnit> AST;
+ std::string Filename;
+};
+
+int main(int argc, char **argv) {
+ llvm::cl::ParseCommandLineOptions(argc, argv, "clang-wpa");
+ FileManager FileMgr;
+ std::vector<TUnit*> TUnits;
+
+ if (InputFilenames.empty())
+ return 0;
+
+ for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
+ const std::string &InFile = InputFilenames[i];
+
+ std::string ErrMsg;
+ llvm::OwningPtr<ASTUnit> AST;
+
+ AST.reset(ASTUnit::LoadFromPCHFile(InFile, FileMgr, &ErrMsg));
+
+ if (!AST) {
+ llvm::errs() << "[" << InFile << "] error: " << ErrMsg << '\n';
+ return 1;
+ }
+
+ TUnit *TU = new TUnit(AST.take(), InFile);
+ TUnits.push_back(TU);
+ }
+
+ llvm::OwningPtr<CallGraph> CG;
+ CG.reset(new CallGraph());
+
+ for (unsigned i = 0, e = TUnits.size(); i != e; ++i)
+ CG->addTU(*(TUnits[i]->AST));
+
+ CG->dump();
+}
More information about the cfe-commits
mailing list