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/PrintFunctionNames | |
| parent | 34d02d0b37f16015f317a935c48ce8b7b64ae77b (diff) | |
Notes
Diffstat (limited to 'examples/PrintFunctionNames')
| -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 |
4 files changed, 108 insertions, 0 deletions
diff --git a/examples/PrintFunctionNames/CMakeLists.txt b/examples/PrintFunctionNames/CMakeLists.txt new file mode 100644 index 0000000000000..49dd22ad8d0d6 --- /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 0000000000000..3c0c1f82ad8af --- /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 0000000000000..5b7b66a4f7ffd --- /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 0000000000000..ee6f7e865e910 --- /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 +-- |
