summaryrefslogtreecommitdiffhomepage
path: root/ir/ir/irhooks.c
blob: fe75ad8517390f3122cec30f441cfc4c4bd9e0a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * This file is part of libFirm.
 * Copyright (C) 2012 University of Karlsruhe.
 */

/**
 * @file
 * @brief    Generic hooks for various libFirm functions.
 * @author   Michael Beck
 */
#include "irhooks.h"

#include <assert.h>

hook_entry_t *hooks[hook_last];

void register_hook(hook_type_t hook, hook_entry_t *entry)
{
	/* check if a hook function is specified. It's a union, so no matter which one */
	if (!entry->hook._hook_node_info)
		return;

	/* hook should not be registered yet */
	assert(entry->next == NULL && hooks[hook] != entry);

	entry->next = hooks[hook];
	hooks[hook] = entry;
}

void unregister_hook(hook_type_t hook, hook_entry_t *entry)
{
	for (hook_entry_t **p = &hooks[hook]; *p; p = &(*p)->next) {
		if (*p == entry) {
			*p          = entry->next;
			entry->next = NULL;
			break;
		}
	}
}