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