there is no be_chordal_open anymore, don't call init_arch_sta if WITH_STA is not...
[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  */
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10
11 #include <stdlib.h>
12
13 #include "bemodule_t.h"
14 #include "xmalloc.h"
15
16 void be_init_sched(void);
17 void be_init_blocksched(void);
18 void be_init_spill(void);
19 void be_init_listsched(void);
20 void be_init_schedrss(void);
21 void be_init_chordal(void);
22 void be_init_copycoal(void);
23 void be_init_copyheur2(void);
24 void be_init_raextern(void);
25 void be_init_copystat(void);
26 void be_init_arch_ia32(void);
27 void be_init_arch_ppc32(void);
28 void be_init_arch_mips(void);
29 void be_init_arch_arm(void);
30 void be_init_arch_sta(void);
31 void be_init_ilpsched(void);
32 void be_init_copyilp(void);
33 void be_init_javacoal(void);
34 void be_init_ra(void);
35 void be_init_spillbelady(void);
36 void be_init_spillmorgan(void);
37 void be_init_spillremat(void);
38 void be_init_ifg(void);
39
40 void be_quit_copystat(void);
41
42 void be_init_modules(void)
43 {
44         static int run_once = 0;
45
46         if(run_once)
47                 return;
48         run_once = 1;
49
50         be_init_sched();
51         be_init_blocksched();
52         be_init_spill();
53         be_init_listsched();
54         be_init_schedrss();
55         be_init_chordal();
56         be_init_copycoal();
57         be_init_copyheur2();
58         be_init_raextern();
59         be_init_copystat();
60         be_init_ra();
61         be_init_spillbelady();
62         be_init_spillmorgan();
63         be_init_ifg();
64
65         be_init_arch_ia32();
66         be_init_arch_ppc32();
67         be_init_arch_mips();
68         be_init_arch_arm();
69
70 #ifdef WITH_ILP
71         be_init_ilpsched();
72         be_init_copyilp();
73         be_init_spillremat();
74 #endif
75
76 #ifdef WITH_JVM
77         be_init_javacoal();
78 #endif
79
80 #ifdef WITH_STA
81         be_init_arch_sta();
82 #endif
83 }
84
85 void be_quit_modules(void)
86 {
87         be_quit_copystat();
88 }
89
90 //---------------------------------------------------------------------------
91
92 #ifdef WITH_LIBCORE
93 typedef struct module_opt_data_t {
94         void **var;
95         be_module_list_entry_t * const *list_head;
96 } module_opt_data_t;
97
98 /**
99  * Beware: return value of 0 means error.
100  */
101 static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
102                           size_t length, ...)
103 {
104         module_opt_data_t *moddata = data;
105         va_list args;
106         const char* opt;
107         const be_module_list_entry_t *module;
108         int res = 0;
109
110         va_start(args, length);
111         opt = va_arg(args, const char*);
112
113         for(module = *(moddata->list_head); module != NULL; module = module->next) {
114                 if(strcmp(module->name, opt) == 0) {
115                         *(moddata->var) = module->data;
116                         res = 1;
117                         break;
118                 }
119         }
120         va_end(args);
121
122         return res;
123 }
124
125 int dump_opt_module(char *buf, size_t buflen, const char *name,
126                     lc_opt_type_t type, void *data, size_t length)
127 {
128         module_opt_data_t *moddata = data;
129         const be_module_list_entry_t *module;
130
131         for(module = *(moddata->list_head); module != NULL; module = module->next) {
132                 if(module->data == *(moddata->var)) {
133                         snprintf(buf, buflen, "%s", module->name);
134                         return strlen(buf);
135                 }
136         }
137
138         snprintf(buf, buflen, "none");
139         return strlen(buf);
140 }
141
142 int dump_opt_module_vals(char *buf, size_t buflen, const char *name,
143                          lc_opt_type_t type, void *data, size_t len)
144 {
145         module_opt_data_t *moddata = data;
146         const be_module_list_entry_t *module;
147         char *p = buf;
148
149         for(module = *(moddata->list_head); module != NULL; module = module->next) {
150                 size_t len = strlen(module->name);
151
152                 if(module != *(moddata->list_head)) {
153                         p = strncat(p, ", ", buflen - 1);
154                         buflen -= 2;
155                 }
156
157                 p = strncat(p, module->name, buflen - 1);
158                 if(len >= buflen) {
159                         break;
160                 }
161                 buflen -= len;
162         }
163
164         return strlen(buf);
165 }
166
167
168 void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
169                            void *module)
170 {
171         be_module_list_entry_t *entry = xmalloc(sizeof(entry[0]));
172         entry->name = name;
173         entry->data = module;
174         entry->next = *list_head;
175         *list_head = entry;
176 }
177
178 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
179                             const char *description,
180                             be_module_list_entry_t * const * list_head,
181                             void **var)
182 {
183         module_opt_data_t *moddata = xmalloc(sizeof(moddata[0]));
184         moddata->var = var;
185         moddata->list_head = list_head;
186
187         lc_opt_add_opt(grp, name, description, lc_opt_type_enum,
188                        moddata, sizeof(moddata[0]),
189                        set_opt_module, dump_opt_module, dump_opt_module_vals,
190                                    NULL);
191 }
192
193 #endif