sta is not there by default
[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         be_init_arch_sta();
70
71 #ifdef WITH_ILP
72         be_init_ilpsched();
73         be_init_copyilp();
74         be_init_spillremat();
75 #endif
76
77 #ifdef WITH_JVM
78         be_init_javacoal();
79 #endif
80
81 #ifdef WITH_STA
82         be_init_arch_sta();
83 #endif
84 }
85
86 void be_quit_modules(void)
87 {
88         be_quit_copystat();
89 }
90
91 //---------------------------------------------------------------------------
92
93 #ifdef WITH_LIBCORE
94 typedef struct module_opt_data_t {
95         void **var;
96         be_module_list_entry_t * const *list_head;
97 } module_opt_data_t;
98
99 /**
100  * Beware: return value of 0 means error.
101  */
102 static int set_opt_module(const char *name, lc_opt_type_t type, void *data,
103                           size_t length, ...)
104 {
105         module_opt_data_t *moddata = data;
106         va_list args;
107         const char* opt;
108         const be_module_list_entry_t *module;
109         int res = 0;
110
111         va_start(args, length);
112         opt = va_arg(args, const char*);
113
114         for(module = *(moddata->list_head); module != NULL; module = module->next) {
115                 if(strcmp(module->name, opt) == 0) {
116                         *(moddata->var) = module->data;
117                         res = 1;
118                         break;
119                 }
120         }
121         va_end(args);
122
123         return res;
124 }
125
126 int dump_opt_module(char *buf, size_t buflen, const char *name,
127                     lc_opt_type_t type, void *data, size_t length)
128 {
129         module_opt_data_t *moddata = data;
130         const be_module_list_entry_t *module;
131
132         for(module = *(moddata->list_head); module != NULL; module = module->next) {
133                 if(module->data == *(moddata->var)) {
134                         snprintf(buf, buflen, "%s", module->name);
135                         return strlen(buf);
136                 }
137         }
138
139         snprintf(buf, buflen, "none");
140         return strlen(buf);
141 }
142
143 int dump_opt_module_vals(char *buf, size_t buflen, const char *name,
144                          lc_opt_type_t type, void *data, size_t len)
145 {
146         module_opt_data_t *moddata = data;
147         const be_module_list_entry_t *module;
148         char *p = buf;
149
150         for(module = *(moddata->list_head); module != NULL; module = module->next) {
151                 size_t len = strlen(module->name);
152
153                 if(module != *(moddata->list_head)) {
154                         p = strncat(p, ", ", buflen - 1);
155                         buflen -= 2;
156                 }
157
158                 p = strncat(p, module->name, buflen - 1);
159                 if(len >= buflen) {
160                         break;
161                 }
162                 buflen -= len;
163         }
164
165         return strlen(buf);
166 }
167
168
169 void be_add_module_to_list(be_module_list_entry_t **list_head, const char *name,
170                            void *module)
171 {
172         be_module_list_entry_t *entry = xmalloc(sizeof(entry[0]));
173         entry->name = name;
174         entry->data = module;
175         entry->next = *list_head;
176         *list_head = entry;
177 }
178
179 void be_add_module_list_opt(lc_opt_entry_t *grp, const char *name,
180                             const char *description,
181                             be_module_list_entry_t * const * list_head,
182                             void **var)
183 {
184         module_opt_data_t *moddata = xmalloc(sizeof(moddata[0]));
185         moddata->var = var;
186         moddata->list_head = list_head;
187
188         lc_opt_add_opt(grp, name, description, lc_opt_type_enum,
189                        moddata, sizeof(moddata[0]),
190                        set_opt_module, dump_opt_module, dump_opt_module_vals,
191                                    NULL);
192 }
193
194 #endif