# HG changeset patch # User Thinker K.F. Li # Date 1284017483 -28800 # Node ID ecc20b5a49427f12fa3bae24b31cc2a9082b19ed # Parent 958c2366e6825427f15e20f311fd7c2c54481f6e Get function body diff -r 958c2366e682 -r ecc20b5a4942 src/cospy.c --- a/src/cospy.c Thu Sep 09 08:20:15 2010 +0800 +++ b/src/cospy.c Thu Sep 09 15:31:23 2010 +0800 @@ -109,6 +109,16 @@ } } +/*! \brief Find all call expression in a code block. + */ +static void +find_call_expr(tree fn) { + tree code_blk; + + code_blk = DECL_SAVED_TREE(fn); + printf("%d:%d\n", TREE_CODE(code_blk), BIND_EXPR); +} + /*! \brief This function is called before running all_passes. * * all_passes is a list of optimization passes of GCC. See @@ -119,7 +129,6 @@ static void handle_all_passes(void *gcc_data, void *user_data) { tree decl; - tree fntype; tree arg, arg_name; tree arg_type; struct cgraph_node *cgn; @@ -132,7 +141,7 @@ */ decl = cfun->decl; cgn = cgraph_node(decl); - + printf("%s:%d:%s\n", current_function_name(), DECL_SOURCE_LINE(decl), DECL_SOURCE_FILE(decl)); @@ -163,6 +172,23 @@ } } +/*! \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); +} + /*! \brief Initialize function for the plugin. */ int @@ -179,5 +205,17 @@ */ register_callback(plugin_info->base_name, PLUGIN_ALL_PASSES_START, handle_all_passes, NULL); + + register_callback(plugin_info->base_name, PLUGIN_PASS_EXECUTION, + handle_every_pass, NULL); + + /* + * Call handle_pre_genericize before genericize a function. + * + * This callback is run before any optimization pass. It is just + * after finishing (parsing) a function. + */ + register_callback(plugin_info->base_name, PLUGIN_PRE_GENERICIZE, + handle_pre_genericize, NULL); return 0; }