changeset 4:8855f7d934ae

Get name of functions before exceuting all_passes
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 08 Sep 2010 17:46:29 +0800
parents 92347d3a3bf3
children a32f4bd19eda
files src/Makefile src/cospy.c src/test.c
diffstat 3 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile	Tue Sep 07 10:07:19 2010 +0800
+++ b/src/Makefile	Wed Sep 08 17:46:29 2010 +0800
@@ -2,7 +2,7 @@
 PLUGIN_SOURCE_FILES= cospy.c
 PLUGIN_OBJECT_FILES= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
 GCCPLUGINS_DIR:= $(shell $(GCC) -print-file-name=plugin)
-CFLAGS+= -I$(GCCPLUGINS_DIR)/include -fPIC -O2
+CFLAGS:= -I$(GCCPLUGINS_DIR)/include -fPIC -O2 $(CFLAGS)
 
 all: cospy.so
 
--- a/src/cospy.c	Tue Sep 07 10:07:19 2010 +0800
+++ b/src/cospy.c	Wed Sep 08 17:46:29 2010 +0800
@@ -1,14 +1,34 @@
 #include "gcc-plugin.h"
 #include "plugin-version.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tree-pass.h"
+#include "tree.h"
+#include "gimple.h"
+#include "cgraph.h"
 #include <stdio.h>
 
 int plugin_is_GPL_compatible;
 
+static void
+handle_all_passes(void *gcc_data, void *user_data) {
+    tree decl;
+    
+    decl = cfun->decl;
+    printf("decl %x\n", decl);
+    printf("  %s\n", current_function_name());
+}
+
 int
 plugin_init(struct plugin_name_args *plugin_info,
 	    struct plugin_gcc_version *version) {
+    struct cgraph_node_hook_list *hook;
+    
     if (!plugin_default_version_check (version, &gcc_version))
 	return 1;
     printf("Initialize plugin %s\n", plugin_info->base_name);
+
+    register_callback(plugin_info->base_name, PLUGIN_ALL_PASSES_START,
+		      handle_all_passes, NULL);
     return 0;
 }
--- a/src/test.c	Tue Sep 07 10:07:19 2010 +0800
+++ b/src/test.c	Wed Sep 08 17:46:29 2010 +0800
@@ -1,7 +1,11 @@
 #include <stdio.h>
 
+int value(int a) {
+    return a + 1;
+}
+
 int
 main(int argc, const char *argv[]) {
-    printf("test\n");
+    printf("test %d\n", value(12));
     return 0;
 }