Mercurial > cospy
changeset 10:ecc20b5a4942
Get function body
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Thu, 09 Sep 2010 15:31:23 +0800 |
parents | 958c2366e682 |
children | bf14d3ed008e |
files | src/cospy.c |
diffstat | 1 files changed, 40 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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; }