remove old/unused code
[libfirm] / ir / be / bemodule.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Backend module interface.
23  * @author      Matthias Braun
24  * @date        29.09.2005
25  * @version     $Id$
26  */
27 #include "config.h"
28
29 #include <stdlib.h>
30 #include <stdbool.h>
31
32 #include "bemodule_t.h"
33 #include "xmalloc.h"
34
35 void be_init_abi(void);
36 void be_init_sched(void);
37 void be_init_blocksched(void);
38 void be_init_spill(void);
39 void be_init_spilloptions(void);
40 void be_init_listsched(void);
41 void be_init_schedrss(void);
42 void be_init_chordal(void);
43 void be_init_pbqp_coloring(void);
44 void be_init_chordal_main(void);
45 void be_init_chordal_common(void);
46 void be_init_copyopt(void);
47 void be_init_copyheur(void);
48 void be_init_copyheur2(void);
49 void be_init_copyheur4(void);
50 void be_init_copyilp2(void);
51 void be_init_copypbqp(void);
52 void be_init_copynone(void);
53 void be_init_copystat(void);
54 void be_init_daemelspill(void);
55 void be_init_dbgout(void);
56 void be_init_arch_ia32(void);
57 void be_init_arch_mips(void);
58 void be_init_arch_arm(void);
59 void be_init_arch_sparc(void);
60 void be_init_arch_amd64(void);
61 void be_init_arch_sta(void);
62 void be_init_arch_sparc(void);
63 void be_init_arch_TEMPLATE(void);
64 void be_init_ilpsched(void);
65 void be_init_copyilp(void);
66 void be_init_peephole(void);
67 void be_init_ra(void);
68 void be_init_spillbelady(void);
69 void be_init_spillbelady2(void);
70 void be_init_ssaconstr(void);
71 void be_init_stabs(void);
72 void be_init_pref_alloc(void);
73 void be_init_irgmod(void);
74 void be_init_loopana(void);
75 void be_init_spillslots(void);
76 void be_init_live(void);
77 void be_init_state(void);
78 void be_init_pbqp(void);
79
80 void be_quit_copystat(void);
81 void be_quit_pbqp(void);
82
83 /**
84  * Driver for module initialization.
85  * Call your module initialization function here.
86  */
87 void be_init_modules(void)
88 {
89         static bool run_once = false;
90
91         if (run_once)
92                 return;
93         run_once = true;
94
95         be_init_abi();
96         be_init_irgmod();
97         be_init_loopana();
98         be_init_live();
99         be_init_spillslots();
100         be_init_sched();
101         be_init_blocksched();
102         be_init_spill();
103         be_init_spilloptions();
104         be_init_dbgout();
105         be_init_listsched();
106         be_init_schedrss();
107         be_init_chordal_main();
108         be_init_chordal_common();
109         be_init_chordal();
110         be_init_copyopt();
111         be_init_copyheur4();
112         be_init_copyheur();
113         be_init_copyheur2();
114 #ifdef WITH_ILP
115         be_init_copyilp2();
116 #endif
117 #ifdef FIRM_KAPS
118         be_init_pbqp_coloring();
119         be_init_copypbqp();
120 #endif
121         be_init_copynone();
122         be_init_copystat();
123         be_init_peephole();
124         be_init_ra();
125         be_init_spillbelady();
126         be_init_spillbelady2();
127         be_init_daemelspill();
128         be_init_ssaconstr();
129         be_init_pref_alloc();
130         be_init_state();
131         be_init_stabs();
132
133         be_init_arch_ia32();
134         be_init_arch_mips();
135         be_init_arch_arm();
136         be_init_arch_sparc();
137         be_init_arch_amd64();
138         be_init_arch_TEMPLATE();
139
140 #ifdef WITH_ILP
141         be_init_ilpsched();
142         be_init_copyilp();
143 #endif /* WITH_ILP */
144
145 #if PLUGIN_IR_BE_STA
146         be_init_arch_sta();
147 #endif /* PLUGIN_IR_BE_STA */
148
149 #ifdef FIRM_GRGEN_BE
150         be_init_pbqp();
151 #endif
152 }
153
154 void be_quit_modules(void)
155 {
156         be_quit_copystat();
157 #ifdef FIRM_GRGEN_BE
158         be_quit_pbqp();
159 #endif
160 }
161
162 //---------------------------------------------------------------------------
163
164 typedef struct module_opt_data_t {
165         void **var;
166         be_module_list_entry_t * const *list_head;
167 } module_opt_data_t;
168
169 /**
170  * Searches in list for module option. If found, set option to given value and return true.
171  * Beware: return value of 0 means error.
172  */
173 static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
174                           size_t length, ...)
175 {
176         module_opt_data_t            *moddata = data;
177         int                          res      = 0;
178         va_list                      args;
179         const char                   *opt;
180         const be_module_list_entry_t *module;
181         (void) type;
182         (void) name;
183
184         va_start(args, length);
185         opt = va_arg(args, const char*);
186
187         for (module = *(moddata->list_head); module != NULL; module = module->next) {
188                 if (strcmp(module->name, opt) == 0) {
189                         *(moddata->var) = module->data;
190                         res = 1;
191                         break;
192                 }
193         }
194         va_end(args);
195
196         return res;
197 }
198
199 /**
200  * Dump the names of all registered module options.
201  */
202 static int dump_opt_module(char *buf, size_t buflen, const char *name,
203                            lc_opt_type_t type, void *data, size_t length)
204 {
205         module_opt_data_t            *moddata = data;
206         const be_module_list_entry_t *module;
207         (void) name;
208         (void) type;
209         (void) length;
210
211         for (module = *(moddata->list_head); module != NULL; module = module->next) {
212                 if (module->data == *(moddata->var)) {
213                         snprintf(buf, buflen, "%s", module->name);
214                         return strlen(buf);
215                 }
216         }
217
218         snprintf(buf, buflen, "none");
219         return strlen(buf);
220 }
221
222 /**
223  * Dump the values of all register module options.
224  */
225 static int dump_opt_module_vals(char *buf, size_t buflen, const char *name,
226                                 lc_opt_type_t type, void *data, size_t len)
227 {
228         module_opt_data_t            *moddata = data;
229         char                         *p       = buf;
230         const be_module_list_entry_t *module;
231         (void) name;
232         (void) type;
233         (void) len;
234
235         for (module = *(moddata->list_head); module != NULL; module = module->next) {
236                 size_t len = strlen(module->name);
237
238                 if (module != *(moddata->list_head)) {
239                         p       = strncat(p, ", ", buflen - 1);
240                         buflen -= 2;
241                 }
242
243                 p = strncat(p, module->name, buflen - 1);
244
245                 if (len >= buflen)
246                         break;
247
248                 buflen -= len;
249         }
250
251         return strlen(buf);
252 }
253
254 /**
255  * Add a new module to list.
256  */
257 void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
258                            void *module)
259 {
260         be_module_list_entry_t *entry = XMALLOC(be_module_list_entry_t);
261         entry->name = name;
262         entry->data = module;
263         entry->next = *list_head;
264         *list_head  = entry;
265 }
266
267 /**
268  * Add an option for a module.
269  */
270 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
271                             const char *description,
272                             be_module_list_entry_t * const * list_head,
273                             void **var)
274 {
275         module_opt_data_t *moddata = XMALLOC(module_opt_data_t);
276         moddata->var       = var;
277         moddata->list_head = list_head;
278
279         lc_opt_add_opt(grp, name, description, lc_opt_type_enum,
280                        moddata, sizeof(moddata[0]),
281                        set_opt_module, dump_opt_module, dump_opt_module_vals,
282                                    NULL);
283 }