diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-01-01 10:34:51 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-01-01 10:34:51 +0000 |
commit | abe15e553e58165e7692c0d0842865c488ed7b45 (patch) | |
tree | 1e68501209c9133fbda8d45171e59f8d6f12dd55 /examples | |
parent | 34d02d0b37f16015f317a935c48ce8b7b64ae77b (diff) | |
download | src-abe15e553e58165e7692c0d0842865c488ed7b45.tar.gz src-abe15e553e58165e7692c0d0842865c488ed7b45.zip |
Updaet clang to 92395.
Notes
Notes:
svn path=/vendor/clang/dist/; revision=201361
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 3 | ||||
-rw-r--r-- | examples/Makefile | 14 | ||||
-rw-r--r-- | examples/PrintFunctionNames/CMakeLists.txt | 26 | ||||
-rw-r--r-- | examples/PrintFunctionNames/Makefile | 28 | ||||
-rw-r--r-- | examples/PrintFunctionNames/PrintFunctionNames.cpp | 44 | ||||
-rw-r--r-- | examples/PrintFunctionNames/README.txt | 10 | ||||
-rw-r--r-- | examples/wpa/CMakeLists.txt | 23 | ||||
-rw-r--r-- | examples/wpa/Makefile | 17 | ||||
-rw-r--r-- | examples/wpa/clang-wpa.cpp | 56 |
9 files changed, 221 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 000000000000..04332b7025d3 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(PrintFunctionNames) +add_subdirectory(wpa) + diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 000000000000..ced158f9d0b7 --- /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 := PrintFunctionNames wpa + +include $(LEVEL)/Makefile.common diff --git a/examples/PrintFunctionNames/CMakeLists.txt b/examples/PrintFunctionNames/CMakeLists.txt new file mode 100644 index 000000000000..49dd22ad8d0d --- /dev/null +++ b/examples/PrintFunctionNames/CMakeLists.txt @@ -0,0 +1,26 @@ +set(SHARED_LIBRARY TRUE) + +set(LLVM_NO_RTTI 1) + +set(LLVM_USED_LIBS + clangIndex + clangFrontend + clangDriver + clangSema + clangAnalysis + clangAST + clangParse + clangLex + clangBasic) + +set( LLVM_LINK_COMPONENTS + bitreader + mc + core + ) + +add_clang_library(PrintFunctionNames PrintFunctionNames.cpp) + +set_target_properties(PrintFunctionNames + PROPERTIES + LINKER_LANGUAGE CXX) diff --git a/examples/PrintFunctionNames/Makefile b/examples/PrintFunctionNames/Makefile new file mode 100644 index 000000000000..3c0c1f82ad8a --- /dev/null +++ b/examples/PrintFunctionNames/Makefile @@ -0,0 +1,28 @@ +##===- examples/PrintFunctionNames/Makefile ----------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../../.. +LIBRARYNAME = PrintFunctionNames + +CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include +CXXFLAGS = -fno-rtti + +# 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_LIBS_IN_SHARED = 1 +SHARED_LIBRARY = 1 + +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 $(LEVEL)/Makefile.common diff --git a/examples/PrintFunctionNames/PrintFunctionNames.cpp b/examples/PrintFunctionNames/PrintFunctionNames.cpp new file mode 100644 index 000000000000..5b7b66a4f7ff --- /dev/null +++ b/examples/PrintFunctionNames/PrintFunctionNames.cpp @@ -0,0 +1,44 @@ +//===- PrintFunctionNames.cpp ---------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Example clang plugin which simply prints the names of all the top-level decls +// in the input file. +// +//===----------------------------------------------------------------------===// + +#include "clang/Frontend/FrontendPluginRegistry.h" +#include "clang/AST/ASTConsumer.h" +#include "clang/AST/AST.h" +#include "llvm/Support/raw_ostream.h" +using namespace clang; + +namespace { + +class PrintFunctionsConsumer : public ASTConsumer { +public: + virtual void HandleTopLevelDecl(DeclGroupRef DG) { + for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) { + const Decl *D = *i; + if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) + llvm::errs() << "top-level-decl: \"" << ND->getNameAsString() << "\"\n"; + } + } +}; + +class PrintFunctionNamesAction : public ASTFrontendAction { +protected: + ASTConsumer *CreateASTConsumer(CompilerInstance &CI, llvm::StringRef) { + return new PrintFunctionsConsumer(); + } +}; + +} + +FrontendPluginRegistry::Add<PrintFunctionNamesAction> +X("print-fns", "print function names"); diff --git a/examples/PrintFunctionNames/README.txt b/examples/PrintFunctionNames/README.txt new file mode 100644 index 000000000000..ee6f7e865e91 --- /dev/null +++ b/examples/PrintFunctionNames/README.txt @@ -0,0 +1,10 @@ +This is a simple example demonstrating how to use clang's facility for +providing AST consumers using a plugin. + +You will probably need to build clang so that it exports all symbols (disable +TOOL_NO_EXPORT in the tools/clang Makefile). + +Once the plugin is built, you can run it using: +-- +$ clang -cc1 -load path/to/PrintFunctionNames.so -plugin=print-fns some-input-file.c +-- diff --git a/examples/wpa/CMakeLists.txt b/examples/wpa/CMakeLists.txt new file mode 100644 index 000000000000..8d443d6e3149 --- /dev/null +++ b/examples/wpa/CMakeLists.txt @@ -0,0 +1,23 @@ +set(LLVM_NO_RTTI 1) + +set(LLVM_USED_LIBS + clangIndex + clangFrontend + clangDriver + clangSema + clangAnalysis + clangAST + clangParse + clangLex + clangBasic) + +set( LLVM_LINK_COMPONENTS + bitreader + mc + core + ) + +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 000000000000..54b61d08571a --- /dev/null +++ b/examples/wpa/Makefile @@ -0,0 +1,17 @@ +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 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 diff --git a/examples/wpa/clang-wpa.cpp b/examples/wpa/clang-wpa.cpp new file mode 100644 index 000000000000..ae789fa9ae3c --- /dev/null +++ b/examples/wpa/clang-wpa.cpp @@ -0,0 +1,56 @@ +//===--- 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/Basic/FileManager.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Frontend/ASTUnit.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Index/CallGraph.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; + + DiagnosticOptions DiagOpts; + llvm::OwningPtr<Diagnostic> Diags( + CompilerInstance::createDiagnostics(DiagOpts, argc, argv)); + + for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { + const std::string &InFile = InputFilenames[i]; + llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, *Diags)); + if (!AST) + 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(); +} |