changeset 11:bf14d3ed008e

Move code of show arguments from before all_pass to before genericize
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 09 Sep 2010 15:57:08 +0800
parents ecc20b5a4942
children 6fdb0cfdc2a7
files src/Makefile src/cospy.c
diffstat 2 files changed, 37 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile	Thu Sep 09 15:31:23 2010 +0800
+++ b/src/Makefile	Thu Sep 09 15:57:08 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)
+CFLAGS:= -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall $(CFLAGS)
 
 all: cospy.so
 
--- a/src/cospy.c	Thu Sep 09 15:31:23 2010 +0800
+++ b/src/cospy.c	Thu Sep 09 15:57:08 2010 +0800
@@ -113,10 +113,11 @@
  */
 static void
 find_call_expr(tree fn) {
-    tree code_blk;
+    tree bind, body;
     
-    code_blk = DECL_SAVED_TREE(fn);
-    printf("%d:%d\n", TREE_CODE(code_blk), BIND_EXPR);
+    bind = DECL_SAVED_TREE(fn);
+    body = BIND_EXPR_BODY(bind);
+    printf("%d:%d\n", TREE_CODE(body), BIND_EXPR);
 }
 
 /*! \brief This function is called before running all_passes.
@@ -129,11 +130,7 @@
 static void
 handle_all_passes(void *gcc_data, void *user_data) {
     tree decl;
-    tree arg, arg_name;
-    tree arg_type;
     struct cgraph_node *cgn;
-    char *arg_type_str;
-    function_args_iterator itr;
     
     /*
      * GCC uses cgraph_node to save information of functions and
@@ -147,11 +144,41 @@
 	   DECL_SOURCE_FILE(decl));
     
     show_callees(cgn);
+}
+
+/*! \brief Called before every optimization pass.
+ */
+static void
+handle_every_pass(void *gcc_data, void *user_data) {
+#if 0
+    printf("PASS %s (type=%x)\n", current_pass->name, current_pass->type);
+#endif
+}
+
+/*! \brief Callback before any optimization pass.
+ *
+ * It supposed to get function body in GIMPLE statements.  If we don't
+ * do this, here, it, GIMPLE statements, would be destroyed by
+ * optimization passes.
+ */
+static void
+handle_pre_genericize(void *gcc_data, void *user_data) {
+    tree fndecl;
+    /* for arguments */
+    tree arg, arg_name;
+    tree arg_type;
+    char *arg_type_str;
+
+    fndecl = cfun->decl;
+    
+    printf("%s:%d:%s\n", current_function_name(),
+	   DECL_SOURCE_LINE(fndecl),
+	   DECL_SOURCE_FILE(fndecl));
     
     /*
      * Parse and show arguments of the function.
      */
-    arg = DECL_ARGUMENTS(decl);
+    arg = DECL_ARGUMENTS(fndecl);
     while(arg) {
 	/*
 	 * The structure of an argument.
@@ -170,22 +197,7 @@
 	ggc_free(arg_type_str);
 	arg = TREE_CHAIN(arg);
     }
-}
-
-/*! \brief Called before every optimization pass.
- */
-static void
-handle_every_pass(void *gcc_data, void *user_data) {
-#if 0
-    printf("PASS %s (type=%x)\n", current_pass->name, current_pass->type);
-#endif
-}
-
-static void
-handle_pre_genericize(void *gcc_data, void *user_data) {
-    tree fndecl;
-
-    fndecl = cfun->decl;
+    
     find_call_expr(fndecl);
 }
 
@@ -194,8 +206,6 @@
 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);