isas and spillers register themselfes in the module constructors now
[libfirm] / ir / be / bemodule.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 "bemodule_t.h"
14 #include "xmalloc.h"
15
16 void be_init_sched(void);
17 void be_init_blocksched(void);
18 void be_init_spill(void);
19 void be_init_listsched(void);
20 void be_init_schedrss(void);
21 void be_init_chordal(void);
22 void be_init_copycoal(void);
23 void be_init_copyheur2(void);
24 void be_init_raextern(void);
25 void be_init_copystat(void);
26 void be_init_arch_ia32(void);
27 void be_init_arch_ppc32(void);
28 void be_init_arch_mips(void);
29 void be_init_arch_arm(void);
30 void be_init_ilpsched(void);
31 void be_init_copyilp(void);
32 void be_init_javacoal(void);
33 void be_init_ra(void);
34 void be_init_spillbelady(void);
35 void be_init_spillmorgan(void);
36 void be_init_spillremat(void);
37
38 void be_quit_copystat(void);
39
40 void be_init_modules(void)
41 {
42         static int run_once = 0;
43
44         if(run_once)
45                 return;
46         run_once = 1;
47
48         be_init_sched();
49         be_init_blocksched();
50         be_init_spill();
51         be_init_listsched();
52         be_init_schedrss();
53         be_init_chordal();
54         be_init_copycoal();
55         be_init_copyheur2();
56         be_init_raextern();
57         be_init_copystat();
58         be_init_ra();
59         be_init_spillbelady();
60         be_init_spillmorgan();
61
62         be_init_arch_ia32();
63         be_init_arch_ppc32();
64         be_init_arch_mips();
65         be_init_arch_arm();
66
67 #ifdef WITH_ILP
68         be_init_ilpsched();
69         be_init_copyilp();
70         be_init_spillremat();
71 #endif
72
73 #ifdef WITH_JVM
74         be_init_javacoal();
75 #endif
76 }
77
78 void be_quit_modules(void)
79 {
80         be_quit_copystat();
81 }
82
83 //---------------------------------------------------------------------------
84
85 #ifdef WITH_LIBCORE
86 typedef struct module_opt_data_t {
87         void **var;
88         be_module_list_entry_t * const *list_head;
89 } module_opt_data_t;
90
91 static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
92                           size_t length, ...)
93 {
94         module_opt_data_t *moddata = data;
95         va_list args;
96         const char* opt;
97         const be_module_list_entry_t *module;
98
99         va_start(args, length);
100         opt = va_arg(args, const char*);
101
102         for(module = *(moddata->list_head); module != NULL; module = module->next) {
103                 if(strcmp(module->name, opt) == 0) {
104                         *(moddata->var) = module->data;
105                         break;
106                 }
107         }
108         va_end(args);
109
110         return 0;
111 }
112
113 int dump_opt_module(char *buf, size_t buflen, const char *name,
114                     lc_opt_type_t type, void *data, size_t length)
115 {
116         module_opt_data_t *moddata = data;
117         const be_module_list_entry_t *module;
118
119         for(module = *(moddata->list_head); module != NULL; module = module->next) {
120                 if(module->data == *(moddata->var)) {
121                         snprintf(buf, buflen, "%s", module->name);
122                         return strlen(buf);
123                 }
124         }
125
126         snprintf(buf, buflen, "none");
127         return strlen(buf);
128 }
129
130 int dump_opt_module_vals(char *buf, size_t buflen, const char *name,
131                          lc_opt_type_t type, void *data, size_t len)
132 {
133         module_opt_data_t *moddata = data;
134         const be_module_list_entry_t *module;
135         char *p = buf;
136
137         for(module = *(moddata->list_head); module != NULL; module = module->next) {
138                 size_t len = strlen(module->name);
139
140                 if(module != *(moddata->list_head)) {
141                         p = strncat(p, ", ", buflen - 1);
142                         buflen -= 2;
143                 }
144
145                 p = strncat(p, module->name, buflen - 1);
146                 if(len >= buflen) {
147                         break;
148                 }
149                 buflen -= len;
150         }
151
152         return strlen(buf);
153 }
154
155
156 void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
157                            void *module)
158 {
159         be_module_list_entry_t *entry = xmalloc(sizeof(entry[0]));
160         entry->name = name;
161         entry->data = module;
162         entry->next = *list_head;
163         *list_head = entry;
164 }
165
166 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
167                             const char *description,
168                             be_module_list_entry_t * const * list_head,
169                             void **var)
170 {
171         module_opt_data_t *moddata = xmalloc(sizeof(moddata[0]));
172         moddata->var = var;
173         moddata->list_head = list_head;
174
175         lc_opt_add_opt(grp, name, description, lc_opt_type_enum,
176                        moddata, sizeof(moddata[0]),
177                        set_opt_module, dump_opt_module, dump_opt_module_vals,
178                                    NULL);
179 }
180
181 #endif