- Implement all the state switching stuff needed for efficient fpu mode
[libfirm] / ir / be / bemodule.c
1 /*
2  * Author:      Matthias Braun
3  * Date:        29.09.2005
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  * CVS-Id:      $Id$
7  */
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif /* HAVE_CONFIG_H */
11
12 #include <stdlib.h>
13
14 #include "bemodule_t.h"
15 #include "xmalloc.h"
16
17 void be_init_sched(void);
18 void be_init_blocksched(void);
19 void be_init_spill(void);
20 void be_init_listsched(void);
21 void be_init_schedrss(void);
22 void be_init_chordal(void);
23 void be_init_chordal_main(void);
24 void be_init_copycoal(void);
25 void be_init_copyheur2(void);
26 void be_init_copystat(void);
27 void be_init_arch_ia32(void);
28 void be_init_arch_ppc32(void);
29 void be_init_arch_mips(void);
30 void be_init_arch_arm(void);
31 void be_init_arch_sta(void);
32 void be_init_ilpsched(void);
33 void be_init_copyilp(void);
34 void be_init_javacoal(void);
35 void be_init_ra(void);
36 void be_init_spillbelady(void);
37 void be_init_spillmorgan(void);
38 void be_init_spillremat(void);
39 void be_init_ssaconstr(void);
40 void be_init_ifg(void);
41 void be_init_irgmod(void);
42 void be_init_loopana(void);
43 void be_init_spillslots(void);
44 void be_init_live(void);
45 void be_init_state(void);
46
47 void be_quit_copystat(void);
48
49 /**
50  * Driver for module intialization.
51  * Call your module initialization function here.
52  */
53 void be_init_modules(void)
54 {
55         static int run_once = 0;
56
57         if (run_once)
58                 return;
59         run_once = 1;
60
61         be_init_irgmod();
62         be_init_loopana();
63         be_init_live();
64         be_init_spillslots();
65         be_init_sched();
66         be_init_blocksched();
67         be_init_spill();
68         be_init_listsched();
69         be_init_schedrss();
70         be_init_chordal_main();
71         be_init_chordal();
72         be_init_copycoal();
73         be_init_copyheur2();
74         be_init_copystat();
75         be_init_ra();
76         be_init_spillbelady();
77         be_init_spillmorgan();
78         be_init_ssaconstr();
79         be_init_state();
80         be_init_ifg();
81
82         be_init_arch_ia32();
83         be_init_arch_ppc32();
84         be_init_arch_mips();
85         be_init_arch_arm();
86
87 #ifdef WITH_ILP
88         be_init_ilpsched();
89         be_init_copyilp();
90         be_init_spillremat();
91 #endif /* WITH_ILP */
92
93 #ifdef WITH_JVM
94         be_init_javacoal();
95 #endif /* WITH_JVM */
96
97 #if PLUGIN_IR_BE_STA
98         be_init_arch_sta();
99 #endif /* PLUGIN_IR_BE_STA */
100 }
101
102 void be_quit_modules(void)
103 {
104         be_quit_copystat();
105 }
106
107 //---------------------------------------------------------------------------
108
109 typedef struct module_opt_data_t {
110         void **var;
111         be_module_list_entry_t * const *list_head;
112 } module_opt_data_t;
113
114 /**
115  * Searches in list for module option. If found, set option to given value and return true.
116  * Beware: return value of 0 means error.
117  */
118 static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
119                           size_t length, ...)
120 {
121         module_opt_data_t            *moddata = data;
122         int                          res      = 0;
123         va_list                      args;
124         const char                   *opt;
125         const be_module_list_entry_t *module;
126
127         va_start(args, length);
128         opt = va_arg(args, const char*);
129
130         for (module = *(moddata->list_head); module != NULL; module = module->next) {
131                 if (strcmp(module->name, opt) == 0) {
132                         *(moddata->var) = module->data;
133                         res = 1;
134                         break;
135                 }
136         }
137         va_end(args);
138
139         return res;
140 }
141
142 /**
143  * Dump the names of all registered module options.
144  */
145 int dump_opt_module(char *buf, size_t buflen, const char *name,
146                     lc_opt_type_t type, void *data, size_t length)
147 {
148         module_opt_data_t            *moddata = data;
149         const be_module_list_entry_t *module;
150
151         for (module = *(moddata->list_head); module != NULL; module = module->next) {
152                 if (module->data == *(moddata->var)) {
153                         snprintf(buf, buflen, "%s", module->name);
154                         return strlen(buf);
155                 }
156         }
157
158         snprintf(buf, buflen, "none");
159         return strlen(buf);
160 }
161
162 /**
163  * Dump the values of all register module options.
164  */
165 int dump_opt_module_vals(char *buf, size_t buflen, const char *name,
166                          lc_opt_type_t type, void *data, size_t len)
167 {
168         module_opt_data_t            *moddata = data;
169         char                         *p       = buf;
170         const be_module_list_entry_t *module;
171
172         for (module = *(moddata->list_head); module != NULL; module = module->next) {
173                 size_t len = strlen(module->name);
174
175                 if (module != *(moddata->list_head)) {
176                         p       = strncat(p, ", ", buflen - 1);
177                         buflen -= 2;
178                 }
179
180                 p = strncat(p, module->name, buflen - 1);
181
182                 if (len >= buflen)
183                         break;
184
185                 buflen -= len;
186         }
187
188         return strlen(buf);
189 }
190
191 /**
192  * Add a new module to list.
193  */
194 void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
195                            void *module)
196 {
197         be_module_list_entry_t *entry;
198
199     entry       = xmalloc(sizeof(entry[0]));
200         entry->name = name;
201         entry->data = module;
202         entry->next = *list_head;
203         *list_head  = entry;
204 }
205
206 /**
207  * Add an option for a module.
208  */
209 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
210                             const char *description,
211                             be_module_list_entry_t * const * list_head,
212                             void **var)
213 {
214         module_opt_data_t *moddata;
215
216         moddata            = xmalloc(sizeof(moddata[0]));
217         moddata->var       = var;
218         moddata->list_head = list_head;
219
220         lc_opt_add_opt(grp, name, description, lc_opt_type_enum,
221                        moddata, sizeof(moddata[0]),
222                        set_opt_module, dump_opt_module, dump_opt_module_vals,
223                                    NULL);
224 }