From d8c7e4553425e1560db45874e14e63106227ad19 Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Tue, 2 Feb 2010 19:21:58 -0500 Subject: [PATCH] Added cleanup for registered passes. --- src/aop-main.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/aop-main.c b/src/aop-main.c index 1ed8274..547dc38 100644 --- a/src/aop-main.c +++ b/src/aop-main.c @@ -52,6 +52,13 @@ static const char *aop_plugin_name; +/* Store a list of all struct opt_pass objects we create so that we + can free them at cleanup time. */ +typedef struct opt_pass *aop_pass; +DEF_VEC_P (aop_pass); +DEF_VEC_ALLOC_P (aop_pass, heap); +static VEC (aop_pass, heap) *aop_pass_list; + static struct opt_pass template_pass = { .type = GIMPLE_PASS, .name = NULL, @@ -74,6 +81,8 @@ void aop_register_pass (const char *pass_name, pass_callback callback) struct register_pass_info pass_info; pass_aop = xmalloc (sizeof (struct opt_pass)); + memcpy (pass_aop, &template_pass, sizeof (struct opt_pass)); + pass_aop->name = xstrdup (pass_name); pass_aop->execute = callback; @@ -82,14 +91,34 @@ void aop_register_pass (const char *pass_name, pass_callback callback) pass_info.ref_pass_instance_number = 0; pass_info.pos_op = PASS_POS_INSERT_BEFORE; + /* Safe the pointer to this object so we can free it later. */ + VEC_safe_push(aop_pass, heap, aop_pass_list, pass_aop); + register_callback (aop_plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info); } +/* Free memory taken up by struct opt_pass objects saved in the + aop_pass_list vector as well as the vector itself. */ +static void cleanup_passes () +{ + int i; + struct opt_pass *pass; + + for (i = 0 ; VEC_iterate (aop_pass, aop_pass_list, i, pass) ; i++) + { + free ((char *)pass->name); + free (pass); + } + VEC_free(aop_pass, heap, aop_pass_list); + aop_pass_list = NULL; +} + /* This is the last plug-in function called before GCC exits. Clean up all the memory we allocated. */ static void aop_cleanup (void *event_date, void *data) { + cleanup_passes(); } /* GCC calls this to initialize a plug-in. Once InterAspect @@ -100,7 +129,7 @@ int plugin_init (struct plugin_name_args *plugin_info, { fprintf (stderr, "InterAspect init.\n"); - plugin_info->base_name; + aop_plugin_name = plugin_info->base_name; /* Register our cleanup function. */ register_callback (aop_plugin_name, PLUGIN_FINISH, aop_cleanup, NULL); -- 2.43.0