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