beloopana: Remove duplicate comments.
[libfirm] / ir / ir / irhooks.c
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief    Generic hooks for various libFirm functions.
9  * @author   Michael Beck
10  */
11 #include "config.h"
12
13 #include <assert.h>
14
15 #include "irhooks.h"
16
17 hook_entry_t *hooks[hook_last];
18
19 void register_hook(hook_type_t hook, hook_entry_t *entry)
20 {
21   /* check if a hook function is specified. It's a union, so no matter which one */
22   if (! entry->hook._hook_turn_into_id)
23     return;
24
25   /* hook should not be registered yet */
26   assert(entry->next == NULL && hooks[hook] != entry);
27
28   entry->next = hooks[hook];
29   hooks[hook] = entry;
30 }
31
32 void unregister_hook(hook_type_t hook, hook_entry_t *entry)
33 {
34   hook_entry_t *p;
35
36   if (hooks[hook] == entry) {
37     hooks[hook] = entry->next;
38     entry->next = NULL;
39     return;
40   }
41
42   for (p = hooks[hook]; p && p->next != entry; p = p->next) {
43   }
44
45   if (p) {
46     p->next     = entry->next;
47     entry->next = NULL;
48   }
49 }