unregister function added
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 21 Oct 2005 13:53:44 +0000 (13:53 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 21 Oct 2005 13:53:44 +0000 (13:53 +0000)
[r6778]

ir/ir/irhooks.c
ir/ir/irhooks.h

index 3854f00..db98c0c 100644 (file)
@@ -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;
 }
index d785e29..d834a8d 100644 (file)
@@ -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];