From 3a87a0c2dba077ff709f7bd55d6a986fb75ad66d Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Fri, 21 Oct 2005 13:53:44 +0000 Subject: [PATCH] unregister function added [r6778] --- ir/ir/irhooks.c | 26 +++++++++++++++++++++++--- ir/ir/irhooks.h | 12 ++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ir/ir/irhooks.c b/ir/ir/irhooks.c index 3854f0049..db98c0ca3 100644 --- a/ir/ir/irhooks.c +++ b/ir/ir/irhooks.c @@ -29,6 +29,7 @@ hook_entry_t *hooks[hook_last]; /* register a hook */ void register_hook(hook_type_t hook, hook_entry_t *entry) { + /* check if a hook function is specifyed. It's a union, so no matter which one */ if (! entry->hook._hook_turn_into_id) return; @@ -36,13 +37,32 @@ void register_hook(hook_type_t hook, hook_entry_t *entry) { hooks[hook] = entry; } +/* unregister a hook */ +void unregister_hook(hook_type_t hook, hook_entry_t *entry) { + hook_entry_t *p; + + if (hooks[hook] == entry) { + hooks[hook] = entry->next; + entry->next = NULL; + return; + } + + for (p = hooks[hook]; p && p->next != entry; p = p->next); + + if (p) { + p->next = entry->next; + entry->next = NULL; + } +} + + #else void register_hook(hook_type_t hook, hook_entry_t *entry) {} +void unregister_hook(hook_type_t hook, hook_entry_t *entry) {} #endif /* FIRM_ENABLE_HOOKS */ -int init_hooks(void) -{ - return (int)register_hook; +int init_hooks(void) { + return (int)register_hook + (int)unregister_hook; } diff --git a/ir/ir/irhooks.h b/ir/ir/irhooks.h index d785e2915..d834a8d92 100644 --- a/ir/ir/irhooks.h +++ b/ir/ir/irhooks.h @@ -183,17 +183,25 @@ typedef enum { hook_arch_dep_replace_mul_with_shifts, hook_arch_dep_replace_division_by_const, hook_new_mode, - hook_last, + hook_last } hook_type_t; /** - * register the hook entry. + * register a hook entry. * * @param hook the hook type * @param entry the hook entry */ void register_hook(hook_type_t hook, hook_entry_t *entry); +/** + * unregister a hook entry. + * + * @param hook the hook type + * @param entry the hook entry + */ +void unregister_hook(hook_type_t hook, hook_entry_t *entry); + #ifdef FIRM_ENABLE_HOOKS extern hook_entry_t *hooks[hook_last]; -- 2.20.1