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