summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-11-15 00:22:33 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-11-15 00:22:33 +0000
commit297b0833ad283e0e0a9003fe6c5eadeedc6614d5 (patch)
tree1a2583805aaec57e27f316781c20f01ef87bf273 /examples
parentd10c5b88334d860d19284032a7126dc2219f57ed (diff)
downloadclang-297b0833ad283e0e0a9003fe6c5eadeedc6614d5.tar.gz
Add examples dir, built with BUILD_EXAMPLES=1 (Makefiles, no CMake equivalent yet).
Move tools/wpa to examples/wpa, and unbreak its build. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88825 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile14
-rw-r--r--examples/wpa/CMakeLists.txt20
-rw-r--r--examples/wpa/Makefile16
-rw-r--r--examples/wpa/clang-wpa.cpp61
4 files changed, 111 insertions, 0 deletions
diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644
index 0000000000..e6ae4b32cb
--- /dev/null
+++ b/examples/Makefile
@@ -0,0 +1,14 @@
+##===- examples/Makefile -----------------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../..
+
+PARALLEL_DIRS := wpa
+
+include $(LEVEL)/Makefile.common
diff --git a/examples/wpa/CMakeLists.txt b/examples/wpa/CMakeLists.txt
new file mode 100644
index 0000000000..5553474b4b
--- /dev/null
+++ b/examples/wpa/CMakeLists.txt
@@ -0,0 +1,20 @@
+set(LLVM_NO_RTTI 1)
+
+set( LLVM_USED_LIBS
+ clangFrontend
+ clangAnalysis
+ clangSema
+ clangAST
+ clangLex
+ clangBasic
+ clangIndex
+ )
+
+set( LLVM_LINK_COMPONENTS
+ mc
+ )
+
+add_clang_executable(clang-wpa
+ clang-wpa.cpp
+ )
+add_dependencies(clang-wpa clang-headers)
diff --git a/examples/wpa/Makefile b/examples/wpa/Makefile
new file mode 100644
index 0000000000..01dbd11b8d
--- /dev/null
+++ b/examples/wpa/Makefile
@@ -0,0 +1,16 @@
+LEVEL = ../../../..
+
+TOOLNAME = clang-wpa
+CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
+CXXFLAGS = -fno-rtti
+NO_INSTALL = 1
+
+# No plugins, optimize startup time.
+TOOL_NO_EXPORTS = 1
+
+include $(LEVEL)/Makefile.config
+
+LINK_COMPONENTS := bitreader mc
+USEDLIBS = clangFrontend.a clangSema.a clangAST.a clangLex.a clangBasic.a clangAnalysis.a clangIndex.a
+
+include $(LLVM_SRC_ROOT)/Makefile.rules
diff --git a/examples/wpa/clang-wpa.cpp b/examples/wpa/clang-wpa.cpp
new file mode 100644
index 0000000000..4a0fe49939
--- /dev/null
+++ b/examples/wpa/clang-wpa.cpp
@@ -0,0 +1,61 @@
+//===--- clang-wpa.cpp - clang whole program analyzer ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This tool reads a sequence of precompiled AST files, and do various
+// cross translation unit analyses.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/CallGraph.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/TextDiagnosticBuffer.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>"));
+
+int main(int argc, char **argv) {
+ llvm::cl::ParseCommandLineOptions(argc, argv, "clang-wpa");
+ FileManager FileMgr;
+ std::vector<ASTUnit*> ASTUnits;
+
+ if (InputFilenames.empty())
+ return 0;
+
+ TextDiagnosticBuffer DiagClient;
+
+ 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, &ErrMsg, &DiagClient));
+
+ if (!AST) {
+ llvm::errs() << "[" << InFile << "] error: " << ErrMsg << '\n';
+ return 1;
+ }
+
+ ASTUnits.push_back(AST.take());
+ }
+
+ llvm::OwningPtr<CallGraph> CG;
+ CG.reset(new CallGraph());
+
+ for (unsigned i = 0, e = ASTUnits.size(); i != e; ++i)
+ CG->addTU(ASTUnits[i]->getASTContext());
+
+ CG->ViewCallGraph();
+}