fix things when WITH_JVM and WITH_ILP is defined
[libfirm] / ir / be / bemodules.c
1 /*
2  * Author:      Matthias Braun
3  * Date:        29.09.2005
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  */
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10
11 #include <stdlib.h>
12
13 #include "bemodules.h"
14 #include "xmalloc.h"
15
16 typedef struct _constructor_list_entry_t {
17         struct _constructor_list_entry_t *next;
18         be_module_constructor_func func;
19 } constructor_list_entry_t;
20
21 static constructor_list_entry_t *constructors = NULL;
22
23 static void free_constructor_list(void)
24 {
25         constructor_list_entry_t *entry = constructors;
26
27         while(entry != NULL) {
28                 constructor_list_entry_t *next = entry->next;
29                 free(entry);
30                 entry = next;
31         }
32 }
33
34 void be_module_add_constructor(be_module_constructor_func func)
35 {
36         static int initialized = 0;
37         constructor_list_entry_t *entry;
38
39         if(!initialized) {
40                 atexit(free_constructor_list);
41                 initialized = 1;
42         }
43
44         entry = xmalloc(sizeof(entry[0]));
45         entry->next = constructors;
46         entry->func = func;
47
48         constructors = entry;
49 }
50
51 void be_module_call_constructors()
52 {
53         constructor_list_entry_t *entry;
54
55         for(entry = constructors; entry != NULL; entry = entry->next) {
56                 entry->func();
57         }
58 }