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,
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;
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
{
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);