remove unmaintained mips backend
[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_arm(void);
58 void be_init_arch_sparc(void);
59 void be_init_arch_amd64(void);
60 void be_init_arch_sta(void);
61 void be_init_arch_sparc(void);
62 void be_init_arch_TEMPLATE(void);
63 void be_init_ilpsched(void);
64 void be_init_copyilp(void);
65 void be_init_peephole(void);
66 void be_init_ra(void);
67 void be_init_spillbelady(void);
68 void be_init_spillbelady2(void);
69 void be_init_ssaconstr(void);
70 void be_init_stabs(void);
71 void be_init_pref_alloc(void);
72 void be_init_irgmod(void);
73 void be_init_loopana(void);
74 void be_init_spillslots(void);
75 void be_init_live(void);
76 void be_init_state(void);
77 void be_init_pbqp(void);
78
79 void be_quit_copystat(void);
80 void be_quit_pbqp(void);
81
82 /**
83  * Driver for module initialization.
84  * Call your module initialization function here.
85  */
86 void be_init_modules(void)
87 {
88         static bool run_once = false;
89
90         if (run_once)
91                 return;
92         run_once = true;
93
94         be_init_abi();
95         be_init_irgmod();
96         be_init_loopana();
97         be_init_live();
98         be_init_spillslots();
99         be_init_sched();
100         be_init_blocksched();
101         be_init_spill();
102         be_init_spilloptions();
103         be_init_dbgout();
104         be_init_listsched();
105         be_init_schedrss();
106         be_init_chordal_main();
107         be_init_chordal_common();
108         be_init_chordal();
109         be_init_copyopt();
110         be_init_copyheur4();
111         be_init_copyheur();
112         be_init_copyheur2();
113 #ifdef WITH_ILP
114         be_init_copyilp2();
115 #endif
116 #ifdef FIRM_KAPS
117         be_init_pbqp_coloring();
118         be_init_copypbqp();
119 #endif
120         be_init_copynone();
121         be_init_copystat();
122         be_init_peephole();
123         be_init_ra();
124         be_init_spillbelady();
125         be_init_spillbelady2();
126         be_init_daemelspill();
127         be_init_ssaconstr();
128         be_init_pref_alloc();
129         be_init_state();
130         be_init_stabs();
131
132         be_init_arch_ia32();
133         be_init_arch_arm();
134         be_init_arch_sparc();
135         be_init_arch_amd64();
136         be_init_arch_TEMPLATE();
137
138 #ifdef WITH_ILP
139         be_init_ilpsched();
140         be_init_copyilp();
141 #endif /* WITH_ILP */
142
143 #if PLUGIN_IR_BE_STA
144         be_init_arch_sta();
145 #endif /* PLUGIN_IR_BE_STA */
146
147 #ifdef FIRM_GRGEN_BE
148         be_init_pbqp();
149 #endif
150 }
151
152 void be_quit_modules(void)
153 {
154         be_quit_copystat();
155 #ifdef FIRM_GRGEN_BE
156         be_quit_pbqp();
157 #endif
158 }
159
160 //---------------------------------------------------------------------------
161
162 typedef struct module_opt_data_t {
163         void **var;
164         be_module_list_entry_t * const *list_head;
165 } module_opt_data_t;
166
167 /**
168  * Searches in list for module option. If found, set option to given value and return true.
169  * Beware: return value of 0 means error.
170  */
171 static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
172                           size_t length, ...)
173 {
174         module_opt_data_t            *moddata = data;
175         int                          res      = 0;
176         va_list                      args;
177         const char                   *opt;
178         const be_module_list_entry_t *module;
179         (void) type;
180         (void) name;
181
182         va_start(args, length);
183         opt = va_arg(args, const char*);
184
185         for (module = *(moddata->list_head); module != NULL; module = module->next) {
186                 if (strcmp(module->name, opt) == 0) {
187                         *(moddata->var) = module->data;
188                         res = 1;
189                         break;
190                 }
191         }
192         va_end(args);
193
194         return res;
195 }
196
197 /**
198  * Dump the names of all registered module options.
199  */
200 static int dump_opt_module(char *buf, size_t buflen, const char *name,
201                            lc_opt_type_t type, void *data, size_t length)
202 {
203         module_opt_data_t            *moddata = data;
204         const be_module_list_entry_t *module;
205         (void) name;
206         (void) type;
207         (void) length;
208
209         for (module = *(moddata->list_head); module != NULL; module = module->next) {
210                 if (module->data == *(moddata->var)) {
211                         snprintf(buf, buflen, "%s", module->name);
212                         return strlen(buf);
213                 }
214         }
215
216         snprintf(buf, buflen, "none");
217         return strlen(buf);
218 }
219
220 /**
221  * Dump the values of all register module options.
222  */
223 static int dump_opt_module_vals(char *buf, size_t buflen, const char *name,
224                                 lc_opt_type_t type, void *data, size_t len)
225 {
226         module_opt_data_t            *moddata = data;
227         char                         *p       = buf;
228         const be_module_list_entry_t *module;
229         (void) name;
230         (void) type;
231         (void) len;
232
233         for (module = *(moddata->list_head); module != NULL; module = module->next) {
234                 size_t len = strlen(module->name);
235
236                 if (module != *(moddata->list_head)) {
237                         p       = strncat(p, ", ", buflen - 1);
238                         buflen -= 2;
239                 }
240
241                 p = strncat(p, module->name, buflen - 1);
242
243                 if (len >= buflen)
244                         break;
245
246                 buflen -= len;
247         }
248
249         return strlen(buf);
250 }
251
252 /**
253  * Add a new module to list.
254  */
255 void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
256                            void *module)
257 {
258         be_module_list_entry_t *entry = XMALLOC(be_module_list_entry_t);
259         entry->name = name;
260         entry->data = module;
261         entry->next = *list_head;
262         *list_head  = entry;
263 }
264
265 /**
266  * Add an option for a module.
267  */
268 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
269                             const char *description,
270                             be_module_list_entry_t * const * list_head,
271                             void **var)
272 {
273         module_opt_data_t *moddata = XMALLOC(module_opt_data_t);
274         moddata->var       = var;
275         moddata->list_head = list_head;
276
277         lc_opt_add_opt(grp, name, description, lc_opt_type_enum,
278                        moddata, sizeof(moddata[0]),
279                        set_opt_module, dump_opt_module, dump_opt_module_vals,
280                                    NULL);
281 }