[cfe-commits] r88826 - in /cfe/trunk/examples: Makefile PrintFunctionNames/ PrintFunctionNames/CMakeLists.txt PrintFunctionNames/Makefile PrintFunctionNames/PrintFunctionNames.cpp

Daniel Dunbar daniel at zuster.org
Sat Nov 14 16:27:43 PST 2009


Author: ddunbar
Date: Sat Nov 14 18:27:43 2009
New Revision: 88826

URL: http://llvm.org/viewvc/llvm-project?rev=88826&view=rev
Log:
Add a trivial example plugin, which prints the names of the top-level decls.
 - The build scriptage is about twice as long as the code, which is nice. :)

Added:
    cfe/trunk/examples/PrintFunctionNames/
    cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
    cfe/trunk/examples/PrintFunctionNames/Makefile
    cfe/trunk/examples/PrintFunctionNames/PrintFunctionNames.cpp
Modified:
    cfe/trunk/examples/Makefile

Modified: cfe/trunk/examples/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/Makefile?rev=88826&r1=88825&r2=88826&view=diff

==============================================================================
--- cfe/trunk/examples/Makefile (original)
+++ cfe/trunk/examples/Makefile Sat Nov 14 18:27:43 2009
@@ -9,6 +9,6 @@
 
 LEVEL = ../../..
 
-PARALLEL_DIRS := wpa
+PARALLEL_DIRS := PrintFunctionNames wpa
 
 include $(LEVEL)/Makefile.common

Added: cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt?rev=88826&view=auto

==============================================================================
--- cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt (added)
+++ cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt Sat Nov 14 18:27:43 2009
@@ -0,0 +1,17 @@
+set(SHARED_LIBRARY TRUE)
+
+set(LLVM_NO_RTTI 1)
+
+set(LLVM_USED_LIBS
+  clangFrontend clangIndex clangSema clangAnalysis clangAST clangParse clangLex clangBasic)
+
+set( LLVM_LINK_COMPONENTS
+  MC
+  support
+  )
+
+add_clang_library(PrintFunctionNames PrintFunctionNames.cpp)
+
+set_target_properties(PrintFunctionNames
+  PROPERTIES
+  LINKER_LANGUAGE CXX)

Added: cfe/trunk/examples/PrintFunctionNames/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/PrintFunctionNames/Makefile?rev=88826&view=auto

==============================================================================
--- cfe/trunk/examples/PrintFunctionNames/Makefile (added)
+++ cfe/trunk/examples/PrintFunctionNames/Makefile Sat Nov 14 18:27:43 2009
@@ -0,0 +1,27 @@
+##===- 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 := MC support
+USEDLIBS = clangFrontend.a clangIndex.a clangSema.a clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a
+
+include $(LEVEL)/Makefile.common

Added: cfe/trunk/examples/PrintFunctionNames/PrintFunctionNames.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/PrintFunctionNames/PrintFunctionNames.cpp?rev=88826&view=auto

==============================================================================
--- cfe/trunk/examples/PrintFunctionNames/PrintFunctionNames.cpp (added)
+++ cfe/trunk/examples/PrintFunctionNames/PrintFunctionNames.cpp Sat Nov 14 18:27:43 2009
@@ -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-cc 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");





More information about the cfe-commits mailing list