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