]>
Commit | Line | Data |
---|---|---|
0974c7d7 | 1 | /* Generate the machine mode enumeration and associated tables. |
99dee823 | 2 | Copyright (C) 2003-2021 Free Software Foundation, Inc. |
0974c7d7 ZW |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 8 | Software Foundation; either version 3, or (at your option) any later |
0974c7d7 ZW |
9 | version. |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
0974c7d7 ZW |
19 | |
20 | #include "bconfig.h" | |
21 | #include "system.h" | |
22 | #include "errors.h" | |
23 | ||
24 | /* enum mode_class is normally defined by machmode.h but we can't | |
25 | include that header here. */ | |
26 | #include "mode-classes.def" | |
27 | ||
28 | #define DEF_MODE_CLASS(M) M | |
29 | enum mode_class { MODE_CLASSES, MAX_MODE_CLASS }; | |
30 | #undef DEF_MODE_CLASS | |
31 | ||
32 | /* Text names of mode classes, for output. */ | |
33 | #define DEF_MODE_CLASS(M) #M | |
34 | static const char *const mode_class_names[MAX_MODE_CLASS] = | |
35 | { | |
36 | MODE_CLASSES | |
37 | }; | |
38 | #undef DEF_MODE_CLASS | |
39 | #undef MODE_CLASSES | |
40 | ||
41 | #ifdef EXTRA_MODES_FILE | |
42 | # define HAVE_EXTRA_MODES 1 | |
43 | #else | |
44 | # define HAVE_EXTRA_MODES 0 | |
45 | # define EXTRA_MODES_FILE "" | |
46 | #endif | |
47 | ||
48 | /* Data structure for building up what we know about a mode. | |
49 | They're clustered by mode class. */ | |
50 | struct mode_data | |
51 | { | |
52 | struct mode_data *next; /* next this class - arbitrary order */ | |
53 | ||
54 | const char *name; /* printable mode name -- SI, not SImode */ | |
e3a64162 | 55 | enum mode_class cl; /* this mode class */ |
550a3380 | 56 | unsigned int order; /* top-level sorting order */ |
37783865 | 57 | unsigned int precision; /* size in bits, equiv to TYPE_PRECISION */ |
0974c7d7 ZW |
58 | unsigned int bytesize; /* storage size in addressable units */ |
59 | unsigned int ncomponents; /* number of subunits */ | |
60 | unsigned int alignment; /* mode alignment */ | |
909e2256 | 61 | const char *format; /* floating point format - float modes only */ |
0974c7d7 ZW |
62 | |
63 | struct mode_data *component; /* mode of components */ | |
64 | struct mode_data *wider; /* next wider mode */ | |
65 | ||
02befdf4 ZW |
66 | struct mode_data *contained; /* Pointer to list of modes that have |
67 | this mode as a component. */ | |
68 | struct mode_data *next_cont; /* Next mode in that list. */ | |
69 | ||
4304ccfd | 70 | struct mode_data *complex; /* complex type with mode as component. */ |
0974c7d7 ZW |
71 | const char *file; /* file and line of definition, */ |
72 | unsigned int line; /* for error reporting */ | |
909e2256 | 73 | unsigned int counter; /* Rank ordering of modes */ |
1699ec0b CF |
74 | unsigned int ibit; /* the number of integral bits */ |
75 | unsigned int fbit; /* the number of fractional bits */ | |
c6561a1a RS |
76 | bool need_nunits_adj; /* true if this mode needs dynamic nunits |
77 | adjustment */ | |
78 | bool need_bytesize_adj; /* true if this mode needs dynamic size | |
92f0f3ec | 79 | adjustment */ |
78a7c317 | 80 | unsigned int int_n; /* If nonzero, then __int<INT_N> will be defined */ |
0974c7d7 ZW |
81 | }; |
82 | ||
b8eaca23 | 83 | static struct mode_data *modes[MAX_MODE_CLASS]; |
0974c7d7 ZW |
84 | static unsigned int n_modes[MAX_MODE_CLASS]; |
85 | static struct mode_data *void_mode; | |
86 | ||
87 | static const struct mode_data blank_mode = { | |
88 | 0, "<unknown>", MAX_MODE_CLASS, | |
550a3380 | 89 | 0, -1U, -1U, -1U, -1U, |
4304ccfd | 90 | 0, 0, 0, 0, 0, 0, |
c6561a1a | 91 | "<unknown>", 0, 0, 0, 0, false, false, 0 |
0974c7d7 ZW |
92 | }; |
93 | ||
b8eaca23 ZW |
94 | static htab_t modes_by_name; |
95 | ||
96 | /* Data structure for recording target-specified runtime adjustments | |
97 | to a particular mode. We support varying the byte size, the | |
98 | alignment, and the floating point format. */ | |
99 | struct mode_adjust | |
100 | { | |
101 | struct mode_adjust *next; | |
102 | struct mode_data *mode; | |
103 | const char *adjustment; | |
104 | ||
105 | const char *file; | |
106 | unsigned int line; | |
107 | }; | |
108 | ||
c6561a1a | 109 | static struct mode_adjust *adj_nunits; |
b8eaca23 ZW |
110 | static struct mode_adjust *adj_bytesize; |
111 | static struct mode_adjust *adj_alignment; | |
112 | static struct mode_adjust *adj_format; | |
1699ec0b CF |
113 | static struct mode_adjust *adj_ibit; |
114 | static struct mode_adjust *adj_fbit; | |
b8eaca23 | 115 | |
0974c7d7 ZW |
116 | /* Mode class operations. */ |
117 | static enum mode_class | |
e3a64162 | 118 | complex_class (enum mode_class c) |
0974c7d7 | 119 | { |
e3a64162 | 120 | switch (c) |
0974c7d7 ZW |
121 | { |
122 | case MODE_INT: return MODE_COMPLEX_INT; | |
a005570e | 123 | case MODE_PARTIAL_INT: return MODE_COMPLEX_INT; |
0974c7d7 ZW |
124 | case MODE_FLOAT: return MODE_COMPLEX_FLOAT; |
125 | default: | |
e3a64162 | 126 | error ("no complex class for class %s", mode_class_names[c]); |
0974c7d7 ZW |
127 | return MODE_RANDOM; |
128 | } | |
129 | } | |
130 | ||
131 | static enum mode_class | |
e3a64162 | 132 | vector_class (enum mode_class cl) |
0974c7d7 | 133 | { |
e3a64162 | 134 | switch (cl) |
0974c7d7 ZW |
135 | { |
136 | case MODE_INT: return MODE_VECTOR_INT; | |
137 | case MODE_FLOAT: return MODE_VECTOR_FLOAT; | |
1699ec0b CF |
138 | case MODE_FRACT: return MODE_VECTOR_FRACT; |
139 | case MODE_UFRACT: return MODE_VECTOR_UFRACT; | |
140 | case MODE_ACCUM: return MODE_VECTOR_ACCUM; | |
141 | case MODE_UACCUM: return MODE_VECTOR_UACCUM; | |
0974c7d7 | 142 | default: |
e3a64162 | 143 | error ("no vector class for class %s", mode_class_names[cl]); |
0974c7d7 ZW |
144 | return MODE_RANDOM; |
145 | } | |
146 | } | |
147 | ||
b8eaca23 ZW |
148 | /* Utility routines. */ |
149 | static inline struct mode_data * | |
150 | find_mode (const char *name) | |
0974c7d7 | 151 | { |
b8eaca23 | 152 | struct mode_data key; |
0974c7d7 | 153 | |
b8eaca23 | 154 | key.name = name; |
e3a64162 | 155 | return (struct mode_data *) htab_find (modes_by_name, &key); |
0974c7d7 ZW |
156 | } |
157 | ||
158 | static struct mode_data * | |
e3a64162 | 159 | new_mode (enum mode_class cl, const char *name, |
0974c7d7 ZW |
160 | const char *file, unsigned int line) |
161 | { | |
162 | struct mode_data *m; | |
909e2256 | 163 | static unsigned int count = 0; |
0974c7d7 | 164 | |
b8eaca23 | 165 | m = find_mode (name); |
0974c7d7 ZW |
166 | if (m) |
167 | { | |
168 | error ("%s:%d: duplicate definition of mode \"%s\"", | |
169 | trim_filename (file), line, name); | |
170 | error ("%s:%d: previous definition here", m->file, m->line); | |
171 | return m; | |
172 | } | |
173 | ||
e3a64162 | 174 | m = XNEW (struct mode_data); |
0974c7d7 | 175 | memcpy (m, &blank_mode, sizeof (struct mode_data)); |
e3a64162 | 176 | m->cl = cl; |
0974c7d7 ZW |
177 | m->name = name; |
178 | if (file) | |
179 | m->file = trim_filename (file); | |
180 | m->line = line; | |
909e2256 | 181 | m->counter = count++; |
0974c7d7 | 182 | |
e3a64162 BI |
183 | m->next = modes[cl]; |
184 | modes[cl] = m; | |
185 | n_modes[cl]++; | |
b8eaca23 ZW |
186 | |
187 | *htab_find_slot (modes_by_name, m, INSERT) = m; | |
b8698a0f | 188 | |
0974c7d7 ZW |
189 | return m; |
190 | } | |
191 | ||
b8eaca23 ZW |
192 | static hashval_t |
193 | hash_mode (const void *p) | |
194 | { | |
195 | const struct mode_data *m = (const struct mode_data *)p; | |
196 | return htab_hash_string (m->name); | |
197 | } | |
198 | ||
199 | static int | |
200 | eq_mode (const void *p, const void *q) | |
201 | { | |
202 | const struct mode_data *a = (const struct mode_data *)p; | |
203 | const struct mode_data *b = (const struct mode_data *)q; | |
204 | ||
205 | return !strcmp (a->name, b->name); | |
206 | } | |
207 | ||
0974c7d7 ZW |
208 | #define for_all_modes(C, M) \ |
209 | for (C = 0; C < MAX_MODE_CLASS; C++) \ | |
b8eaca23 ZW |
210 | for (M = modes[C]; M; M = M->next) |
211 | ||
212 | static void ATTRIBUTE_UNUSED | |
213 | new_adjust (const char *name, | |
214 | struct mode_adjust **category, const char *catname, | |
215 | const char *adjustment, | |
1699ec0b CF |
216 | enum mode_class required_class_from, |
217 | enum mode_class required_class_to, | |
b8eaca23 ZW |
218 | const char *file, unsigned int line) |
219 | { | |
220 | struct mode_data *mode = find_mode (name); | |
221 | struct mode_adjust *a; | |
222 | ||
223 | file = trim_filename (file); | |
224 | ||
225 | if (!mode) | |
226 | { | |
227 | error ("%s:%d: no mode \"%s\"", file, line, name); | |
228 | return; | |
229 | } | |
230 | ||
1699ec0b CF |
231 | if (required_class_from != MODE_RANDOM |
232 | && (mode->cl < required_class_from || mode->cl > required_class_to)) | |
b8eaca23 | 233 | { |
1699ec0b CF |
234 | error ("%s:%d: mode \"%s\" is not among class {%s, %s}", |
235 | file, line, name, mode_class_names[required_class_from] + 5, | |
236 | mode_class_names[required_class_to] + 5); | |
b8eaca23 ZW |
237 | return; |
238 | } | |
b8698a0f | 239 | |
b8eaca23 ZW |
240 | for (a = *category; a; a = a->next) |
241 | if (a->mode == mode) | |
242 | { | |
243 | error ("%s:%d: mode \"%s\" already has a %s adjustment", | |
244 | file, line, name, catname); | |
245 | error ("%s:%d: previous adjustment here", a->file, a->line); | |
246 | return; | |
247 | } | |
248 | ||
5d038c4c | 249 | a = XNEW (struct mode_adjust); |
b8eaca23 ZW |
250 | a->mode = mode; |
251 | a->adjustment = adjustment; | |
252 | a->file = file; | |
253 | a->line = line; | |
254 | ||
255 | a->next = *category; | |
256 | *category = a; | |
257 | } | |
0974c7d7 ZW |
258 | |
259 | /* Diagnose failure to meet expectations in a partially filled out | |
260 | mode structure. */ | |
261 | enum requirement { SET, UNSET, OPTIONAL }; | |
262 | ||
263 | #define validate_field_(mname, fname, req, val, unset, file, line) do { \ | |
264 | switch (req) \ | |
265 | { \ | |
266 | case SET: \ | |
267 | if (val == unset) \ | |
268 | error ("%s:%d: (%s) field %s must be set", \ | |
269 | file, line, mname, fname); \ | |
270 | break; \ | |
271 | case UNSET: \ | |
272 | if (val != unset) \ | |
273 | error ("%s:%d: (%s) field %s must not be set", \ | |
274 | file, line, mname, fname); \ | |
275 | case OPTIONAL: \ | |
276 | break; \ | |
277 | } \ | |
278 | } while (0) | |
279 | ||
280 | #define validate_field(M, F) \ | |
281 | validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line) | |
282 | ||
283 | static void | |
284 | validate_mode (struct mode_data *m, | |
37783865 | 285 | enum requirement r_precision, |
0974c7d7 ZW |
286 | enum requirement r_bytesize, |
287 | enum requirement r_component, | |
94134f42 ZW |
288 | enum requirement r_ncomponents, |
289 | enum requirement r_format) | |
0974c7d7 | 290 | { |
37783865 | 291 | validate_field (m, precision); |
0974c7d7 ZW |
292 | validate_field (m, bytesize); |
293 | validate_field (m, component); | |
294 | validate_field (m, ncomponents); | |
94134f42 | 295 | validate_field (m, format); |
0974c7d7 ZW |
296 | } |
297 | #undef validate_field | |
298 | #undef validate_field_ | |
299 | ||
300 | /* Given a partially-filled-out mode structure, figure out what we can | |
301 | and fill the rest of it in; die if it isn't enough. */ | |
302 | static void | |
303 | complete_mode (struct mode_data *m) | |
304 | { | |
305 | unsigned int alignment; | |
306 | ||
307 | if (!m->name) | |
308 | { | |
309 | error ("%s:%d: mode with no name", m->file, m->line); | |
310 | return; | |
311 | } | |
e3a64162 | 312 | if (m->cl == MAX_MODE_CLASS) |
0974c7d7 ZW |
313 | { |
314 | error ("%s:%d: %smode has no mode class", m->file, m->line, m->name); | |
315 | return; | |
316 | } | |
317 | ||
e3a64162 | 318 | switch (m->cl) |
0974c7d7 ZW |
319 | { |
320 | case MODE_RANDOM: | |
321 | /* Nothing more need be said. */ | |
322 | if (!strcmp (m->name, "VOID")) | |
323 | void_mode = m; | |
324 | ||
94134f42 | 325 | validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET); |
0974c7d7 | 326 | |
37783865 | 327 | m->precision = 0; |
0974c7d7 ZW |
328 | m->bytesize = 0; |
329 | m->ncomponents = 0; | |
330 | m->component = 0; | |
331 | break; | |
332 | ||
333 | case MODE_CC: | |
334 | /* Again, nothing more need be said. For historical reasons, | |
335 | the size of a CC mode is four units. */ | |
94134f42 | 336 | validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET); |
0974c7d7 ZW |
337 | |
338 | m->bytesize = 4; | |
9fcc6bf6 | 339 | m->ncomponents = 1; |
0974c7d7 ZW |
340 | m->component = 0; |
341 | break; | |
342 | ||
343 | case MODE_INT: | |
344 | case MODE_FLOAT: | |
909e2256 | 345 | case MODE_DECIMAL_FLOAT: |
1699ec0b CF |
346 | case MODE_FRACT: |
347 | case MODE_UFRACT: | |
348 | case MODE_ACCUM: | |
349 | case MODE_UACCUM: | |
0974c7d7 | 350 | /* A scalar mode must have a byte size, may have a bit size, |
94134f42 ZW |
351 | and must not have components. A float mode must have a |
352 | format. */ | |
353 | validate_mode (m, OPTIONAL, SET, UNSET, UNSET, | |
1699ec0b CF |
354 | (m->cl == MODE_FLOAT || m->cl == MODE_DECIMAL_FLOAT) |
355 | ? SET : UNSET); | |
0974c7d7 | 356 | |
9fcc6bf6 | 357 | m->ncomponents = 1; |
0974c7d7 ZW |
358 | m->component = 0; |
359 | break; | |
360 | ||
6b91b3e9 AS |
361 | case MODE_OPAQUE: |
362 | /* Opaque modes have size and precision. */ | |
363 | validate_mode (m, OPTIONAL, SET, UNSET, UNSET, UNSET); | |
364 | ||
365 | m->ncomponents = 1; | |
366 | m->component = 0; | |
367 | break; | |
368 | ||
0974c7d7 ZW |
369 | case MODE_PARTIAL_INT: |
370 | /* A partial integer mode uses ->component to say what the | |
371 | corresponding full-size integer mode is, and may also | |
372 | specify a bit size. */ | |
94134f42 | 373 | validate_mode (m, OPTIONAL, UNSET, SET, UNSET, UNSET); |
0974c7d7 ZW |
374 | |
375 | m->bytesize = m->component->bytesize; | |
376 | ||
9fcc6bf6 | 377 | m->ncomponents = 1; |
0974c7d7 ZW |
378 | break; |
379 | ||
380 | case MODE_COMPLEX_INT: | |
381 | case MODE_COMPLEX_FLOAT: | |
382 | /* Complex modes should have a component indicated, but no more. */ | |
94134f42 | 383 | validate_mode (m, UNSET, UNSET, SET, UNSET, UNSET); |
0974c7d7 | 384 | m->ncomponents = 2; |
37783865 ZW |
385 | if (m->component->precision != (unsigned int)-1) |
386 | m->precision = 2 * m->component->precision; | |
0974c7d7 ZW |
387 | m->bytesize = 2 * m->component->bytesize; |
388 | break; | |
389 | ||
5c0caeb3 RS |
390 | case MODE_VECTOR_BOOL: |
391 | validate_mode (m, UNSET, SET, SET, SET, UNSET); | |
392 | break; | |
393 | ||
0974c7d7 ZW |
394 | case MODE_VECTOR_INT: |
395 | case MODE_VECTOR_FLOAT: | |
1699ec0b CF |
396 | case MODE_VECTOR_FRACT: |
397 | case MODE_VECTOR_UFRACT: | |
398 | case MODE_VECTOR_ACCUM: | |
399 | case MODE_VECTOR_UACCUM: | |
0974c7d7 | 400 | /* Vector modes should have a component and a number of components. */ |
94134f42 | 401 | validate_mode (m, UNSET, UNSET, SET, SET, UNSET); |
37783865 ZW |
402 | if (m->component->precision != (unsigned int)-1) |
403 | m->precision = m->ncomponents * m->component->precision; | |
0974c7d7 ZW |
404 | m->bytesize = m->ncomponents * m->component->bytesize; |
405 | break; | |
406 | ||
407 | default: | |
b2d59f6f | 408 | gcc_unreachable (); |
0974c7d7 ZW |
409 | } |
410 | ||
411 | /* If not already specified, the mode alignment defaults to the largest | |
412 | power of two that divides the size of the object. Complex types are | |
413 | not more aligned than their contents. */ | |
e3a64162 | 414 | if (m->cl == MODE_COMPLEX_INT || m->cl == MODE_COMPLEX_FLOAT) |
0974c7d7 ZW |
415 | alignment = m->component->bytesize; |
416 | else | |
417 | alignment = m->bytesize; | |
418 | ||
419 | m->alignment = alignment & (~alignment + 1); | |
02befdf4 ZW |
420 | |
421 | /* If this mode has components, make the component mode point back | |
422 | to this mode, for the sake of adjustments. */ | |
423 | if (m->component) | |
424 | { | |
425 | m->next_cont = m->component->contained; | |
426 | m->component->contained = m; | |
427 | } | |
0974c7d7 ZW |
428 | } |
429 | ||
430 | static void | |
431 | complete_all_modes (void) | |
432 | { | |
433 | struct mode_data *m; | |
e3a64162 BI |
434 | int cl; |
435 | ||
436 | for_all_modes (cl, m) | |
0974c7d7 ZW |
437 | complete_mode (m); |
438 | } | |
439 | ||
440 | /* For each mode in class CLASS, construct a corresponding complex mode. */ | |
c3284718 | 441 | #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__) |
0974c7d7 | 442 | static void |
e3a64162 | 443 | make_complex_modes (enum mode_class cl, |
0974c7d7 ZW |
444 | const char *file, unsigned int line) |
445 | { | |
446 | struct mode_data *m; | |
447 | struct mode_data *c; | |
e3a64162 | 448 | enum mode_class cclass = complex_class (cl); |
0974c7d7 ZW |
449 | |
450 | if (cclass == MODE_RANDOM) | |
451 | return; | |
e3a64162 BI |
452 | |
453 | for (m = modes[cl]; m; m = m->next) | |
0974c7d7 | 454 | { |
1f36f7b3 | 455 | char *p, *buf; |
75be0217 JM |
456 | size_t m_len; |
457 | ||
0974c7d7 | 458 | /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */ |
37783865 | 459 | if (m->precision == 1) |
0974c7d7 ZW |
460 | continue; |
461 | ||
75be0217 | 462 | m_len = strlen (m->name); |
1f36f7b3 JM |
463 | /* The leading "1 +" is in case we prepend a "C" below. */ |
464 | buf = (char *) xmalloc (1 + m_len + 1); | |
0974c7d7 ZW |
465 | |
466 | /* Float complex modes are named SCmode, etc. | |
467 | Int complex modes are named CSImode, etc. | |
468 | This inconsistency should be eliminated. */ | |
1f36f7b3 | 469 | p = 0; |
e3a64162 | 470 | if (cl == MODE_FLOAT) |
0974c7d7 | 471 | { |
75be0217 | 472 | memcpy (buf, m->name, m_len + 1); |
0974c7d7 | 473 | p = strchr (buf, 'F'); |
1f36f7b3 | 474 | if (p == 0 && strchr (buf, 'D') == 0) |
0974c7d7 | 475 | { |
909e2256 | 476 | error ("%s:%d: float mode \"%s\" has no 'F' or 'D'", |
0974c7d7 | 477 | m->file, m->line, m->name); |
1f36f7b3 | 478 | free (buf); |
0974c7d7 ZW |
479 | continue; |
480 | } | |
0974c7d7 | 481 | } |
1f36f7b3 JM |
482 | if (p != 0) |
483 | *p = 'C'; | |
0974c7d7 | 484 | else |
1f36f7b3 JM |
485 | { |
486 | buf[0] = 'C'; | |
487 | memcpy (buf + 1, m->name, m_len + 1); | |
488 | } | |
0974c7d7 | 489 | |
1f36f7b3 | 490 | c = new_mode (cclass, buf, file, line); |
0974c7d7 | 491 | c->component = m; |
4304ccfd | 492 | m->complex = c; |
0974c7d7 ZW |
493 | } |
494 | } | |
495 | ||
550a3380 RS |
496 | /* For all modes in class CL, construct vector modes of width WIDTH, |
497 | having as many components as necessary. ORDER is the sorting order | |
498 | of the mode, with smaller numbers indicating a higher priority. */ | |
499 | #define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W, ORDER) \ | |
500 | make_vector_modes (MODE_##C, #PREFIX, W, ORDER, __FILE__, __LINE__) | |
501 | #define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W, 0) | |
4c61a9fd | 502 | static void ATTRIBUTE_UNUSED |
6ce12f6a | 503 | make_vector_modes (enum mode_class cl, const char *prefix, unsigned int width, |
550a3380 | 504 | unsigned int order, const char *file, unsigned int line) |
0974c7d7 ZW |
505 | { |
506 | struct mode_data *m; | |
507 | struct mode_data *v; | |
3d7b83b6 MS |
508 | /* Big enough for a 32-bit UINT_MAX plus the text. */ |
509 | char buf[12]; | |
0974c7d7 | 510 | unsigned int ncomponents; |
e3a64162 | 511 | enum mode_class vclass = vector_class (cl); |
0974c7d7 ZW |
512 | |
513 | if (vclass == MODE_RANDOM) | |
514 | return; | |
515 | ||
e3a64162 | 516 | for (m = modes[cl]; m; m = m->next) |
0974c7d7 ZW |
517 | { |
518 | /* Do not construct vector modes with only one element, or | |
519 | vector modes where the element size doesn't divide the full | |
520 | size evenly. */ | |
521 | ncomponents = width / m->bytesize; | |
522 | if (ncomponents < 2) | |
523 | continue; | |
524 | if (width % m->bytesize) | |
525 | continue; | |
526 | ||
527 | /* Skip QFmode and BImode. FIXME: this special case should | |
528 | not be necessary. */ | |
e3a64162 | 529 | if (cl == MODE_FLOAT && m->bytesize == 1) |
0974c7d7 | 530 | continue; |
e3a64162 | 531 | if (cl == MODE_INT && m->precision == 1) |
0974c7d7 ZW |
532 | continue; |
533 | ||
6ce12f6a RS |
534 | if ((size_t) snprintf (buf, sizeof buf, "%s%u%s", prefix, |
535 | ncomponents, m->name) >= sizeof buf) | |
0974c7d7 ZW |
536 | { |
537 | error ("%s:%d: mode name \"%s\" is too long", | |
538 | m->file, m->line, m->name); | |
539 | continue; | |
540 | } | |
541 | ||
542 | v = new_mode (vclass, xstrdup (buf), file, line); | |
550a3380 | 543 | v->order = order; |
0974c7d7 ZW |
544 | v->component = m; |
545 | v->ncomponents = ncomponents; | |
546 | } | |
547 | } | |
548 | ||
5c0caeb3 RS |
549 | /* Create a vector of booleans called NAME with COUNT elements and |
550 | BYTESIZE bytes in total. */ | |
551 | #define VECTOR_BOOL_MODE(NAME, COUNT, BYTESIZE) \ | |
552 | make_vector_bool_mode (#NAME, COUNT, BYTESIZE, __FILE__, __LINE__) | |
553 | static void ATTRIBUTE_UNUSED | |
554 | make_vector_bool_mode (const char *name, unsigned int count, | |
555 | unsigned int bytesize, const char *file, | |
556 | unsigned int line) | |
557 | { | |
558 | struct mode_data *m = find_mode ("BI"); | |
559 | if (!m) | |
560 | { | |
561 | error ("%s:%d: no mode \"BI\"", file, line); | |
562 | return; | |
563 | } | |
564 | ||
565 | struct mode_data *v = new_mode (MODE_VECTOR_BOOL, name, file, line); | |
566 | v->component = m; | |
567 | v->ncomponents = count; | |
568 | v->bytesize = bytesize; | |
569 | } | |
570 | ||
0974c7d7 ZW |
571 | /* Input. */ |
572 | ||
c3284718 RS |
573 | #define _SPECIAL_MODE(C, N) \ |
574 | make_special_mode (MODE_##C, #N, __FILE__, __LINE__) | |
0974c7d7 ZW |
575 | #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N) |
576 | #define CC_MODE(N) _SPECIAL_MODE (CC, N) | |
577 | ||
578 | static void | |
e3a64162 | 579 | make_special_mode (enum mode_class cl, const char *name, |
0974c7d7 ZW |
580 | const char *file, unsigned int line) |
581 | { | |
e3a64162 | 582 | new_mode (cl, name, file, line); |
0974c7d7 ZW |
583 | } |
584 | ||
e3a64162 | 585 | #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y) |
94134f42 ZW |
586 | #define FRACTIONAL_INT_MODE(N, B, Y) \ |
587 | make_int_mode (#N, B, Y, __FILE__, __LINE__) | |
0974c7d7 | 588 | |
94134f42 ZW |
589 | static void |
590 | make_int_mode (const char *name, | |
37783865 | 591 | unsigned int precision, unsigned int bytesize, |
94134f42 ZW |
592 | const char *file, unsigned int line) |
593 | { | |
594 | struct mode_data *m = new_mode (MODE_INT, name, file, line); | |
595 | m->bytesize = bytesize; | |
37783865 | 596 | m->precision = precision; |
94134f42 ZW |
597 | } |
598 | ||
6b91b3e9 AS |
599 | #define OPAQUE_MODE(N, B) \ |
600 | make_opaque_mode (#N, -1U, B, __FILE__, __LINE__) | |
601 | ||
602 | static void ATTRIBUTE_UNUSED | |
603 | make_opaque_mode (const char *name, | |
604 | unsigned int precision, | |
605 | unsigned int bytesize, | |
606 | const char *file, unsigned int line) | |
607 | { | |
608 | struct mode_data *m = new_mode (MODE_OPAQUE, name, file, line); | |
609 | m->bytesize = bytesize; | |
610 | m->precision = precision; | |
611 | } | |
612 | ||
1699ec0b CF |
613 | #define FRACT_MODE(N, Y, F) \ |
614 | make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__) | |
615 | ||
616 | #define UFRACT_MODE(N, Y, F) \ | |
617 | make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__) | |
618 | ||
619 | #define ACCUM_MODE(N, Y, I, F) \ | |
620 | make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__) | |
621 | ||
622 | #define UACCUM_MODE(N, Y, I, F) \ | |
623 | make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__) | |
624 | ||
625 | /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT, | |
626 | FILE, and LINE. */ | |
627 | ||
628 | static void | |
629 | make_fixed_point_mode (enum mode_class cl, | |
630 | const char *name, | |
631 | unsigned int bytesize, | |
632 | unsigned int ibit, | |
633 | unsigned int fbit, | |
634 | const char *file, unsigned int line) | |
635 | { | |
636 | struct mode_data *m = new_mode (cl, name, file, line); | |
637 | m->bytesize = bytesize; | |
638 | m->ibit = ibit; | |
639 | m->fbit = fbit; | |
640 | } | |
641 | ||
e3a64162 | 642 | #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F) |
94134f42 ZW |
643 | #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \ |
644 | make_float_mode (#N, B, Y, #F, __FILE__, __LINE__) | |
0974c7d7 ZW |
645 | |
646 | static void | |
94134f42 | 647 | make_float_mode (const char *name, |
37783865 | 648 | unsigned int precision, unsigned int bytesize, |
94134f42 ZW |
649 | const char *format, |
650 | const char *file, unsigned int line) | |
0974c7d7 | 651 | { |
94134f42 | 652 | struct mode_data *m = new_mode (MODE_FLOAT, name, file, line); |
0974c7d7 | 653 | m->bytesize = bytesize; |
37783865 | 654 | m->precision = precision; |
94134f42 ZW |
655 | m->format = format; |
656 | } | |
657 | ||
909e2256 JG |
658 | #define DECIMAL_FLOAT_MODE(N, Y, F) \ |
659 | FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F) | |
660 | #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \ | |
661 | make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__) | |
662 | ||
663 | static void | |
664 | make_decimal_float_mode (const char *name, | |
665 | unsigned int precision, unsigned int bytesize, | |
666 | const char *format, | |
667 | const char *file, unsigned int line) | |
668 | { | |
669 | struct mode_data *m = new_mode (MODE_DECIMAL_FLOAT, name, file, line); | |
670 | m->bytesize = bytesize; | |
671 | m->precision = precision; | |
672 | m->format = format; | |
673 | } | |
674 | ||
94134f42 ZW |
675 | #define RESET_FLOAT_FORMAT(N, F) \ |
676 | reset_float_format (#N, #F, __FILE__, __LINE__) | |
677 | static void ATTRIBUTE_UNUSED | |
678 | reset_float_format (const char *name, const char *format, | |
b8eaca23 | 679 | const char *file, unsigned int line) |
94134f42 | 680 | { |
b8eaca23 | 681 | struct mode_data *m = find_mode (name); |
94134f42 ZW |
682 | if (!m) |
683 | { | |
b8eaca23 ZW |
684 | error ("%s:%d: no mode \"%s\"", file, line, name); |
685 | return; | |
686 | } | |
909e2256 | 687 | if (m->cl != MODE_FLOAT && m->cl != MODE_DECIMAL_FLOAT) |
b8eaca23 | 688 | { |
909e2256 | 689 | error ("%s:%d: mode \"%s\" is not a FLOAT class", file, line, name); |
94134f42 ZW |
690 | return; |
691 | } | |
692 | m->format = format; | |
0974c7d7 ZW |
693 | } |
694 | ||
78a7c317 DD |
695 | /* __intN support. */ |
696 | #define INT_N(M,PREC) \ | |
697 | make_int_n (#M, PREC, __FILE__, __LINE__) | |
698 | static void ATTRIBUTE_UNUSED | |
699 | make_int_n (const char *m, int bitsize, | |
700 | const char *file, unsigned int line) | |
701 | { | |
702 | struct mode_data *component = find_mode (m); | |
703 | if (!component) | |
704 | { | |
705 | error ("%s:%d: no mode \"%s\"", file, line, m); | |
706 | return; | |
707 | } | |
708 | if (component->cl != MODE_INT | |
709 | && component->cl != MODE_PARTIAL_INT) | |
710 | { | |
711 | error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file, line, m); | |
712 | return; | |
713 | } | |
714 | if (component->int_n != 0) | |
715 | { | |
716 | error ("%s:%d: mode \"%s\" already has an intN", file, line, m); | |
717 | return; | |
718 | } | |
719 | ||
720 | component->int_n = bitsize; | |
721 | } | |
722 | ||
d8487c94 MS |
723 | /* Partial integer modes are specified by relation to a full integer |
724 | mode. */ | |
725 | #define PARTIAL_INT_MODE(M,PREC,NAME) \ | |
726 | make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__) | |
0974c7d7 ZW |
727 | static void ATTRIBUTE_UNUSED |
728 | make_partial_integer_mode (const char *base, const char *name, | |
37783865 | 729 | unsigned int precision, |
0974c7d7 ZW |
730 | const char *file, unsigned int line) |
731 | { | |
732 | struct mode_data *m; | |
b8eaca23 | 733 | struct mode_data *component = find_mode (base); |
0974c7d7 ZW |
734 | if (!component) |
735 | { | |
b8eaca23 ZW |
736 | error ("%s:%d: no mode \"%s\"", file, line, name); |
737 | return; | |
738 | } | |
e3a64162 | 739 | if (component->cl != MODE_INT) |
b8eaca23 ZW |
740 | { |
741 | error ("%s:%d: mode \"%s\" is not class INT", file, line, name); | |
0974c7d7 ZW |
742 | return; |
743 | } | |
e3a64162 | 744 | |
0974c7d7 | 745 | m = new_mode (MODE_PARTIAL_INT, name, file, line); |
37783865 | 746 | m->precision = precision; |
0974c7d7 ZW |
747 | m->component = component; |
748 | } | |
749 | ||
750 | /* A single vector mode can be specified by naming its component | |
751 | mode and the number of components. */ | |
66f206b8 JW |
752 | #define VECTOR_MODE_WITH_PREFIX(PREFIX, C, M, N, ORDER) \ |
753 | make_vector_mode (MODE_##C, #PREFIX, #M, N, ORDER, __FILE__, __LINE__); | |
754 | #define VECTOR_MODE(C, M, N) VECTOR_MODE_WITH_PREFIX(V, C, M, N, 0); | |
0974c7d7 ZW |
755 | static void ATTRIBUTE_UNUSED |
756 | make_vector_mode (enum mode_class bclass, | |
66f206b8 | 757 | const char *prefix, |
0974c7d7 ZW |
758 | const char *base, |
759 | unsigned int ncomponents, | |
66f206b8 | 760 | unsigned int order, |
0974c7d7 ZW |
761 | const char *file, unsigned int line) |
762 | { | |
763 | struct mode_data *v; | |
764 | enum mode_class vclass = vector_class (bclass); | |
b8eaca23 | 765 | struct mode_data *component = find_mode (base); |
d8487c94 | 766 | char namebuf[16]; |
0974c7d7 ZW |
767 | |
768 | if (vclass == MODE_RANDOM) | |
769 | return; | |
770 | if (component == 0) | |
771 | { | |
b8eaca23 ZW |
772 | error ("%s:%d: no mode \"%s\"", file, line, base); |
773 | return; | |
774 | } | |
75d8b2d0 BS |
775 | if (component->cl != bclass |
776 | && (component->cl != MODE_PARTIAL_INT | |
777 | || bclass != MODE_INT)) | |
b8eaca23 ZW |
778 | { |
779 | error ("%s:%d: mode \"%s\" is not class %s", | |
0974c7d7 ZW |
780 | file, line, base, mode_class_names[bclass] + 5); |
781 | return; | |
782 | } | |
783 | ||
66f206b8 | 784 | if ((size_t)snprintf (namebuf, sizeof namebuf, "%s%u%s", prefix, |
0974c7d7 ZW |
785 | ncomponents, base) >= sizeof namebuf) |
786 | { | |
787 | error ("%s:%d: mode name \"%s\" is too long", | |
474b650e | 788 | file, line, base); |
0974c7d7 ZW |
789 | return; |
790 | } | |
791 | ||
792 | v = new_mode (vclass, xstrdup (namebuf), file, line); | |
66f206b8 | 793 | v->order = order; |
0974c7d7 ZW |
794 | v->ncomponents = ncomponents; |
795 | v->component = component; | |
796 | } | |
b8eaca23 ZW |
797 | |
798 | /* Adjustability. */ | |
1699ec0b CF |
799 | #define _ADD_ADJUST(A, M, X, C1, C2) \ |
800 | new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__) | |
b8eaca23 | 801 | |
c6561a1a | 802 | #define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM) |
c3284718 RS |
803 | #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM) |
804 | #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM) | |
805 | #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT) | |
806 | #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM) | |
807 | #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM) | |
0974c7d7 | 808 | |
8fd05f4d KZ |
809 | static int bits_per_unit; |
810 | static int max_bitsize_mode_any_int; | |
98ac7913 | 811 | static int max_bitsize_mode_any_mode; |
8fd05f4d | 812 | |
0974c7d7 ZW |
813 | static void |
814 | create_modes (void) | |
815 | { | |
816 | #include "machmode.def" | |
8fd05f4d KZ |
817 | |
818 | /* So put the default value unless the target needs a non standard | |
819 | value. */ | |
820 | #ifdef BITS_PER_UNIT | |
821 | bits_per_unit = BITS_PER_UNIT; | |
822 | #else | |
823 | bits_per_unit = 8; | |
824 | #endif | |
825 | ||
826 | #ifdef MAX_BITSIZE_MODE_ANY_INT | |
827 | max_bitsize_mode_any_int = MAX_BITSIZE_MODE_ANY_INT; | |
828 | #else | |
829 | max_bitsize_mode_any_int = 0; | |
830 | #endif | |
98ac7913 RS |
831 | |
832 | #ifdef MAX_BITSIZE_MODE_ANY_MODE | |
833 | max_bitsize_mode_any_mode = MAX_BITSIZE_MODE_ANY_MODE; | |
834 | #else | |
835 | max_bitsize_mode_any_mode = 0; | |
836 | #endif | |
0974c7d7 ZW |
837 | } |
838 | ||
e535b963 RS |
839 | #ifndef NUM_POLY_INT_COEFFS |
840 | #define NUM_POLY_INT_COEFFS 1 | |
841 | #endif | |
842 | ||
0974c7d7 ZW |
843 | /* Processing. */ |
844 | ||
845 | /* Sort a list of modes into the order needed for the WIDER field: | |
37783865 | 846 | major sort by precision, minor sort by component precision. |
0974c7d7 ZW |
847 | |
848 | For instance: | |
849 | QI < HI < SI < DI < TI | |
850 | V4QI < V2HI < V8QI < V4HI < V2SI. | |
851 | ||
37783865 ZW |
852 | If the precision is not set, sort by the bytesize. A mode with |
853 | precision set gets sorted before a mode without precision set, if | |
0974c7d7 | 854 | they have the same bytesize; this is the right thing because |
37783865 | 855 | the precision must always be smaller than the bytesize * BITS_PER_UNIT. |
0974c7d7 | 856 | We don't have to do anything special to get this done -- an unset |
37783865 | 857 | precision shows up as (unsigned int)-1, i.e. UINT_MAX. */ |
0974c7d7 ZW |
858 | static int |
859 | cmp_modes (const void *a, const void *b) | |
860 | { | |
741ac903 KG |
861 | const struct mode_data *const m = *(const struct mode_data *const*)a; |
862 | const struct mode_data *const n = *(const struct mode_data *const*)b; | |
0974c7d7 | 863 | |
550a3380 RS |
864 | if (m->order > n->order) |
865 | return 1; | |
866 | else if (m->order < n->order) | |
867 | return -1; | |
868 | ||
0974c7d7 ZW |
869 | if (m->bytesize > n->bytesize) |
870 | return 1; | |
871 | else if (m->bytesize < n->bytesize) | |
872 | return -1; | |
873 | ||
37783865 | 874 | if (m->precision > n->precision) |
0974c7d7 | 875 | return 1; |
37783865 | 876 | else if (m->precision < n->precision) |
0974c7d7 ZW |
877 | return -1; |
878 | ||
879 | if (!m->component && !n->component) | |
909e2256 JG |
880 | { |
881 | if (m->counter < n->counter) | |
882 | return -1; | |
883 | else | |
884 | return 1; | |
885 | } | |
0974c7d7 ZW |
886 | |
887 | if (m->component->bytesize > n->component->bytesize) | |
888 | return 1; | |
889 | else if (m->component->bytesize < n->component->bytesize) | |
890 | return -1; | |
891 | ||
37783865 | 892 | if (m->component->precision > n->component->precision) |
0974c7d7 | 893 | return 1; |
37783865 | 894 | else if (m->component->precision < n->component->precision) |
0974c7d7 ZW |
895 | return -1; |
896 | ||
909e2256 JG |
897 | if (m->counter < n->counter) |
898 | return -1; | |
899 | else | |
900 | return 1; | |
0974c7d7 ZW |
901 | } |
902 | ||
903 | static void | |
904 | calc_wider_mode (void) | |
905 | { | |
e3a64162 | 906 | int c; |
0974c7d7 ZW |
907 | struct mode_data *m; |
908 | struct mode_data **sortbuf; | |
909 | unsigned int max_n_modes = 0; | |
910 | unsigned int i, j; | |
911 | ||
912 | for (c = 0; c < MAX_MODE_CLASS; c++) | |
913 | max_n_modes = MAX (max_n_modes, n_modes[c]); | |
914 | ||
0f229b22 OH |
915 | /* Allocate max_n_modes + 1 entries to leave room for the extra null |
916 | pointer assigned after the qsort call below. */ | |
a7de2c2a | 917 | sortbuf = XALLOCAVEC (struct mode_data *, max_n_modes + 1); |
0974c7d7 ZW |
918 | |
919 | for (c = 0; c < MAX_MODE_CLASS; c++) | |
920 | { | |
921 | /* "wider" is not meaningful for MODE_RANDOM and MODE_CC. | |
922 | However, we want these in textual order, and we have | |
923 | precisely the reverse. */ | |
924 | if (c == MODE_RANDOM || c == MODE_CC) | |
925 | { | |
926 | struct mode_data *prev, *next; | |
927 | ||
b8eaca23 | 928 | for (prev = 0, m = modes[c]; m; m = next) |
0974c7d7 ZW |
929 | { |
930 | m->wider = void_mode; | |
931 | ||
932 | /* this is nreverse */ | |
933 | next = m->next; | |
934 | m->next = prev; | |
935 | prev = m; | |
936 | } | |
b8eaca23 | 937 | modes[c] = prev; |
0974c7d7 ZW |
938 | } |
939 | else | |
940 | { | |
b8eaca23 | 941 | if (!modes[c]) |
0974c7d7 ZW |
942 | continue; |
943 | ||
b8eaca23 | 944 | for (i = 0, m = modes[c]; m; i++, m = m->next) |
0974c7d7 ZW |
945 | sortbuf[i] = m; |
946 | ||
9e686ea1 | 947 | (qsort) (sortbuf, i, sizeof (struct mode_data *), cmp_modes); |
0974c7d7 ZW |
948 | |
949 | sortbuf[i] = 0; | |
950 | for (j = 0; j < i; j++) | |
e90247f8 BS |
951 | { |
952 | sortbuf[j]->next = sortbuf[j + 1]; | |
953 | if (c == MODE_PARTIAL_INT) | |
954 | sortbuf[j]->wider = sortbuf[j]->component; | |
955 | else | |
956 | sortbuf[j]->wider = sortbuf[j]->next; | |
957 | } | |
0974c7d7 | 958 | |
b8eaca23 | 959 | modes[c] = sortbuf[0]; |
0974c7d7 ZW |
960 | } |
961 | } | |
962 | } | |
963 | ||
7b777afa RS |
964 | /* Text to add to the constant part of a poly_int_pod initializer in |
965 | order to fill out te whole structure. */ | |
966 | #if NUM_POLY_INT_COEFFS == 1 | |
967 | #define ZERO_COEFFS "" | |
968 | #elif NUM_POLY_INT_COEFFS == 2 | |
969 | #define ZERO_COEFFS ", 0" | |
970 | #else | |
971 | #error "Unknown value of NUM_POLY_INT_COEFFS" | |
972 | #endif | |
973 | ||
0974c7d7 ZW |
974 | /* Output routines. */ |
975 | ||
976 | #define tagged_printf(FMT, ARG, TAG) do { \ | |
7258e976 | 977 | int count_ = printf (" " FMT ",", ARG); \ |
0974c7d7 ZW |
978 | printf ("%*s/* %s */\n", 27 - count_, "", TAG); \ |
979 | } while (0) | |
980 | ||
981 | #define print_decl(TYPE, NAME, ASIZE) \ | |
b8eaca23 ZW |
982 | puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{"); |
983 | ||
c6561a1a | 984 | #define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \ |
b8eaca23 | 985 | printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \ |
c6561a1a | 986 | NEEDS_ADJ ? "" : "const ") |
0974c7d7 ZW |
987 | |
988 | #define print_closer() puts ("};") | |
989 | ||
8697be17 KZ |
990 | /* Compute the max bitsize of some of the classes of integers. It may |
991 | be that there are needs for the other integer classes, and this | |
992 | code is easy to extend. */ | |
993 | static void | |
994 | emit_max_int (void) | |
995 | { | |
996 | unsigned int max, mmax; | |
997 | struct mode_data *i; | |
998 | int j; | |
999 | ||
1000 | puts (""); | |
8fd05f4d KZ |
1001 | |
1002 | printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit); | |
1003 | ||
1004 | if (max_bitsize_mode_any_int == 0) | |
1005 | { | |
1006 | for (max = 1, i = modes[MODE_INT]; i; i = i->next) | |
1007 | if (max < i->bytesize) | |
1008 | max = i->bytesize; | |
1009 | mmax = max; | |
1010 | for (max = 1, i = modes[MODE_PARTIAL_INT]; i; i = i->next) | |
1011 | if (max < i->bytesize) | |
1012 | max = i->bytesize; | |
1013 | if (max > mmax) | |
1014 | mmax = max; | |
74241479 | 1015 | printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax); |
8fd05f4d KZ |
1016 | } |
1017 | else | |
1018 | printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int); | |
8697be17 | 1019 | |
98ac7913 RS |
1020 | if (max_bitsize_mode_any_mode == 0) |
1021 | { | |
1022 | mmax = 0; | |
1023 | for (j = 0; j < MAX_MODE_CLASS; j++) | |
1024 | for (i = modes[j]; i; i = i->next) | |
1025 | if (mmax < i->bytesize) | |
1026 | mmax = i->bytesize; | |
1027 | printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax); | |
1028 | } | |
1029 | else | |
1030 | printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n", | |
1031 | max_bitsize_mode_any_mode); | |
8697be17 KZ |
1032 | } |
1033 | ||
92f0f3ec JJ |
1034 | /* Emit mode_size_inline routine into insn-modes.h header. */ |
1035 | static void | |
1036 | emit_mode_size_inline (void) | |
1037 | { | |
1038 | int c; | |
1039 | struct mode_adjust *a; | |
1040 | struct mode_data *m; | |
1041 | ||
1042 | /* Size adjustments must be propagated to all containing modes. */ | |
1043 | for (a = adj_bytesize; a; a = a->next) | |
1044 | { | |
1045 | a->mode->need_bytesize_adj = true; | |
1046 | for (m = a->mode->contained; m; m = m->next_cont) | |
1047 | m->need_bytesize_adj = true; | |
1048 | } | |
1049 | ||
c6561a1a RS |
1050 | /* Changing the number of units by a factor of X also changes the size |
1051 | by a factor of X. */ | |
1052 | for (mode_adjust *a = adj_nunits; a; a = a->next) | |
1053 | a->mode->need_bytesize_adj = true; | |
1054 | ||
92f0f3ec JJ |
1055 | printf ("\ |
1056 | #ifdef __cplusplus\n\ | |
1057 | inline __attribute__((__always_inline__))\n\ | |
1058 | #else\n\ | |
1059 | extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1060 | #endif\n\ | |
cf098191 | 1061 | poly_uint16\n\ |
ef4bddc2 | 1062 | mode_size_inline (machine_mode mode)\n\ |
92f0f3ec | 1063 | {\n\ |
cf098191 | 1064 | extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\ |
524cf1e4 | 1065 | gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ |
92f0f3ec | 1066 | switch (mode)\n\ |
c6561a1a | 1067 | {\n", adj_nunits || adj_bytesize ? "" : "const "); |
92f0f3ec JJ |
1068 | |
1069 | for_all_modes (c, m) | |
1070 | if (!m->need_bytesize_adj) | |
0d4a1197 | 1071 | printf (" case E_%smode: return %u;\n", m->name, m->bytesize); |
92f0f3ec JJ |
1072 | |
1073 | puts ("\ | |
1074 | default: return mode_size[mode];\n\ | |
1075 | }\n\ | |
1076 | }\n"); | |
1077 | } | |
1078 | ||
1079 | /* Emit mode_nunits_inline routine into insn-modes.h header. */ | |
1080 | static void | |
1081 | emit_mode_nunits_inline (void) | |
1082 | { | |
1083 | int c; | |
1084 | struct mode_data *m; | |
1085 | ||
c6561a1a RS |
1086 | for (mode_adjust *a = adj_nunits; a; a = a->next) |
1087 | a->mode->need_nunits_adj = true; | |
1088 | ||
1089 | printf ("\ | |
92f0f3ec JJ |
1090 | #ifdef __cplusplus\n\ |
1091 | inline __attribute__((__always_inline__))\n\ | |
1092 | #else\n\ | |
1093 | extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1094 | #endif\n\ | |
7b777afa | 1095 | poly_uint16\n\ |
ef4bddc2 | 1096 | mode_nunits_inline (machine_mode mode)\n\ |
92f0f3ec | 1097 | {\n\ |
c6561a1a | 1098 | extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\ |
92f0f3ec | 1099 | switch (mode)\n\ |
c6561a1a | 1100 | {\n", adj_nunits ? "" : "const "); |
92f0f3ec JJ |
1101 | |
1102 | for_all_modes (c, m) | |
c6561a1a RS |
1103 | if (!m->need_nunits_adj) |
1104 | printf (" case E_%smode: return %u;\n", m->name, m->ncomponents); | |
92f0f3ec JJ |
1105 | |
1106 | puts ("\ | |
1107 | default: return mode_nunits[mode];\n\ | |
1108 | }\n\ | |
1109 | }\n"); | |
1110 | } | |
1111 | ||
1112 | /* Emit mode_inner_inline routine into insn-modes.h header. */ | |
1113 | static void | |
1114 | emit_mode_inner_inline (void) | |
1115 | { | |
1116 | int c; | |
1117 | struct mode_data *m; | |
1118 | ||
1119 | puts ("\ | |
1120 | #ifdef __cplusplus\n\ | |
1121 | inline __attribute__((__always_inline__))\n\ | |
1122 | #else\n\ | |
1123 | extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1124 | #endif\n\ | |
1125 | unsigned char\n\ | |
ef4bddc2 | 1126 | mode_inner_inline (machine_mode mode)\n\ |
92f0f3ec JJ |
1127 | {\n\ |
1128 | extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\ | |
524cf1e4 | 1129 | gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ |
92f0f3ec JJ |
1130 | switch (mode)\n\ |
1131 | {"); | |
1132 | ||
1133 | for_all_modes (c, m) | |
0d4a1197 | 1134 | printf (" case E_%smode: return E_%smode;\n", m->name, |
92f0f3ec | 1135 | c != MODE_PARTIAL_INT && m->component |
1c0e448f | 1136 | ? m->component->name : m->name); |
92f0f3ec JJ |
1137 | |
1138 | puts ("\ | |
1139 | default: return mode_inner[mode];\n\ | |
1140 | }\n\ | |
1141 | }\n"); | |
1142 | } | |
1143 | ||
8dc89e4d DS |
1144 | /* Emit mode_unit_size_inline routine into insn-modes.h header. */ |
1145 | static void | |
1146 | emit_mode_unit_size_inline (void) | |
1147 | { | |
1148 | int c; | |
1149 | struct mode_data *m; | |
1150 | ||
1151 | puts ("\ | |
1152 | #ifdef __cplusplus\n\ | |
1153 | inline __attribute__((__always_inline__))\n\ | |
1154 | #else\n\ | |
1155 | extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1156 | #endif\n\ | |
1157 | unsigned char\n\ | |
1158 | mode_unit_size_inline (machine_mode mode)\n\ | |
1159 | {\n\ | |
f22b0575 DS |
1160 | extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\ |
1161 | \n\ | |
524cf1e4 | 1162 | gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ |
8dc89e4d DS |
1163 | switch (mode)\n\ |
1164 | {"); | |
1165 | ||
1166 | for_all_modes (c, m) | |
1167 | { | |
1168 | const char *name = m->name; | |
1169 | struct mode_data *m2 = m; | |
1170 | if (c != MODE_PARTIAL_INT && m2->component) | |
1171 | m2 = m2->component; | |
1172 | if (!m2->need_bytesize_adj) | |
0d4a1197 | 1173 | printf (" case E_%smode: return %u;\n", name, m2->bytesize); |
8dc89e4d DS |
1174 | } |
1175 | ||
1176 | puts ("\ | |
1177 | default: return mode_unit_size[mode];\n\ | |
1178 | }\n\ | |
1179 | }\n"); | |
1180 | } | |
1181 | ||
1182 | /* Emit mode_unit_precision_inline routine into insn-modes.h header. */ | |
1183 | static void | |
1184 | emit_mode_unit_precision_inline (void) | |
1185 | { | |
1186 | int c; | |
1187 | struct mode_data *m; | |
1188 | ||
1189 | puts ("\ | |
1190 | #ifdef __cplusplus\n\ | |
1191 | inline __attribute__((__always_inline__))\n\ | |
1192 | #else\n\ | |
1193 | extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1194 | #endif\n\ | |
1195 | unsigned short\n\ | |
1196 | mode_unit_precision_inline (machine_mode mode)\n\ | |
1197 | {\n\ | |
1198 | extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\ | |
524cf1e4 | 1199 | gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ |
8dc89e4d DS |
1200 | switch (mode)\n\ |
1201 | {"); | |
1202 | ||
1203 | for_all_modes (c, m) | |
1204 | { | |
1205 | struct mode_data *m2 | |
1206 | = (c != MODE_PARTIAL_INT && m->component) ? m->component : m; | |
1207 | if (m2->precision != (unsigned int)-1) | |
0d4a1197 | 1208 | printf (" case E_%smode: return %u;\n", m->name, m2->precision); |
8dc89e4d | 1209 | else |
0d4a1197 | 1210 | printf (" case E_%smode: return %u*BITS_PER_UNIT;\n", |
8dc89e4d DS |
1211 | m->name, m2->bytesize); |
1212 | } | |
1213 | ||
1214 | puts ("\ | |
1215 | default: return mode_unit_precision[mode];\n\ | |
1216 | }\n\ | |
1217 | }\n"); | |
1218 | } | |
1219 | ||
e386a52f RS |
1220 | /* Return the best machine mode class for MODE, or null if machine_mode |
1221 | should be used. */ | |
1222 | ||
1223 | static const char * | |
1224 | get_mode_class (struct mode_data *mode) | |
1225 | { | |
1226 | switch (mode->cl) | |
1227 | { | |
501623d4 RS |
1228 | case MODE_INT: |
1229 | case MODE_PARTIAL_INT: | |
1230 | return "scalar_int_mode"; | |
1231 | ||
d21cefc2 RS |
1232 | case MODE_FRACT: |
1233 | case MODE_UFRACT: | |
1234 | case MODE_ACCUM: | |
1235 | case MODE_UACCUM: | |
d21cefc2 RS |
1236 | return "scalar_mode"; |
1237 | ||
e386a52f RS |
1238 | case MODE_FLOAT: |
1239 | case MODE_DECIMAL_FLOAT: | |
1240 | return "scalar_float_mode"; | |
1241 | ||
a97390bf RS |
1242 | case MODE_COMPLEX_INT: |
1243 | case MODE_COMPLEX_FLOAT: | |
1244 | return "complex_mode"; | |
1245 | ||
e386a52f RS |
1246 | default: |
1247 | return NULL; | |
1248 | } | |
1249 | } | |
1250 | ||
0974c7d7 ZW |
1251 | static void |
1252 | emit_insn_modes_h (void) | |
1253 | { | |
e3a64162 | 1254 | int c; |
0974c7d7 | 1255 | struct mode_data *m, *first, *last; |
78a7c317 | 1256 | int n_int_n_ents = 0; |
0974c7d7 ZW |
1257 | |
1258 | printf ("/* Generated automatically from machmode.def%s%s\n", | |
1259 | HAVE_EXTRA_MODES ? " and " : "", | |
1260 | EXTRA_MODES_FILE); | |
1261 | ||
1262 | puts ("\ | |
1263 | by genmodes. */\n\ | |
1264 | \n\ | |
1265 | #ifndef GCC_INSN_MODES_H\n\ | |
1266 | #define GCC_INSN_MODES_H\n\ | |
1267 | \n\ | |
1268 | enum machine_mode\n{"); | |
1269 | ||
1270 | for (c = 0; c < MAX_MODE_CLASS; c++) | |
b8eaca23 | 1271 | for (m = modes[c]; m; m = m->next) |
0974c7d7 | 1272 | { |
0d4a1197 | 1273 | int count_ = printf (" E_%smode,", m->name); |
0974c7d7 ZW |
1274 | printf ("%*s/* %s:%d */\n", 27 - count_, "", |
1275 | trim_filename (m->file), m->line); | |
8cc4b7a2 | 1276 | printf ("#define HAVE_%smode\n", m->name); |
b77d1a17 RS |
1277 | printf ("#ifdef USE_ENUM_MODES\n"); |
1278 | printf ("#define %smode E_%smode\n", m->name, m->name); | |
1279 | printf ("#else\n"); | |
e386a52f RS |
1280 | if (const char *mode_class = get_mode_class (m)) |
1281 | printf ("#define %smode (%s ((%s::from_int) E_%smode))\n", | |
1282 | m->name, mode_class, mode_class, m->name); | |
1283 | else | |
1284 | printf ("#define %smode ((void) 0, E_%smode)\n", | |
1285 | m->name, m->name); | |
b77d1a17 | 1286 | printf ("#endif\n"); |
0974c7d7 ZW |
1287 | } |
1288 | ||
1289 | puts (" MAX_MACHINE_MODE,\n"); | |
1290 | ||
1291 | for (c = 0; c < MAX_MODE_CLASS; c++) | |
1292 | { | |
b8eaca23 | 1293 | first = modes[c]; |
0974c7d7 ZW |
1294 | last = 0; |
1295 | for (m = first; m; last = m, m = m->next) | |
1296 | ; | |
1297 | ||
1298 | /* Don't use BImode for MIN_MODE_INT, since otherwise the middle | |
1299 | end will try to use it for bitfields in structures and the | |
1300 | like, which we do not want. Only the target md file should | |
1301 | generate BImode widgets. */ | |
d8487c94 | 1302 | if (first && first->precision == 1 && c == MODE_INT) |
0974c7d7 ZW |
1303 | first = first->next; |
1304 | ||
1305 | if (first && last) | |
0d4a1197 | 1306 | printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n", |
0974c7d7 ZW |
1307 | mode_class_names[c], first->name, |
1308 | mode_class_names[c], last->name); | |
1309 | else | |
0d4a1197 | 1310 | printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n", |
0974c7d7 ZW |
1311 | mode_class_names[c], void_mode->name, |
1312 | mode_class_names[c], void_mode->name); | |
1313 | } | |
1314 | ||
1315 | puts ("\ | |
1316 | NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\ | |
b8eaca23 ZW |
1317 | };\n"); |
1318 | ||
8fd2477d RS |
1319 | /* Define a NUM_* macro for each mode class, giving the number of modes |
1320 | in the class. */ | |
1321 | for (c = 0; c < MAX_MODE_CLASS; c++) | |
1322 | { | |
1323 | printf ("#define NUM_%s ", mode_class_names[c]); | |
1324 | if (modes[c]) | |
1325 | printf ("(MAX_%s - MIN_%s + 1)\n", mode_class_names[c], | |
1326 | mode_class_names[c]); | |
1327 | else | |
1328 | printf ("0\n"); | |
1329 | } | |
1330 | printf ("\n"); | |
1331 | ||
b8eaca23 | 1332 | /* I can't think of a better idea, can you? */ |
c6561a1a RS |
1333 | printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits ? "" : " const"); |
1334 | printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits ? "" : " const"); | |
1335 | printf ("#define CONST_MODE_SIZE%s\n", | |
1336 | adj_bytesize || adj_nunits ? "" : " const"); | |
8dc89e4d | 1337 | printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize ? "" : " const"); |
b8eaca23 ZW |
1338 | printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment ? "" : " const"); |
1339 | #if 0 /* disabled for backward compatibility, temporary */ | |
1340 | printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format ? "" :" const"); | |
1341 | #endif | |
1699ec0b CF |
1342 | printf ("#define CONST_MODE_IBIT%s\n", adj_ibit ? "" : " const"); |
1343 | printf ("#define CONST_MODE_FBIT%s\n", adj_fbit ? "" : " const"); | |
0411210f | 1344 | printf ("#define CONST_MODE_MASK%s\n", adj_nunits ? "" : " const"); |
8697be17 | 1345 | emit_max_int (); |
78a7c317 DD |
1346 | |
1347 | for_all_modes (c, m) | |
1348 | if (m->int_n) | |
1349 | n_int_n_ents ++; | |
1350 | ||
1351 | printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents); | |
1352 | ||
e535b963 RS |
1353 | printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS); |
1354 | ||
b0e84cf7 RS |
1355 | puts ("\ |
1356 | \n\ | |
1357 | #endif /* insn-modes.h */"); | |
1358 | } | |
1359 | ||
1360 | static void | |
1361 | emit_insn_modes_inline_h (void) | |
1362 | { | |
1363 | printf ("/* Generated automatically from machmode.def%s%s\n", | |
1364 | HAVE_EXTRA_MODES ? " and " : "", | |
1365 | EXTRA_MODES_FILE); | |
1366 | ||
1367 | puts ("\ | |
1368 | by genmodes. */\n\ | |
1369 | \n\ | |
1370 | #ifndef GCC_INSN_MODES_INLINE_H\n\ | |
1371 | #define GCC_INSN_MODES_INLINE_H"); | |
1372 | ||
ef4bddc2 | 1373 | puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n"); |
92f0f3ec JJ |
1374 | emit_mode_size_inline (); |
1375 | emit_mode_nunits_inline (); | |
1376 | emit_mode_inner_inline (); | |
8dc89e4d DS |
1377 | emit_mode_unit_size_inline (); |
1378 | emit_mode_unit_precision_inline (); | |
92f0f3ec JJ |
1379 | puts ("#endif /* GCC_VERSION >= 4001 */"); |
1380 | ||
b8eaca23 | 1381 | puts ("\ |
0974c7d7 | 1382 | \n\ |
b0e84cf7 | 1383 | #endif /* insn-modes-inline.h */"); |
0974c7d7 ZW |
1384 | } |
1385 | ||
1386 | static void | |
1387 | emit_insn_modes_c_header (void) | |
1388 | { | |
1389 | printf ("/* Generated automatically from machmode.def%s%s\n", | |
1390 | HAVE_EXTRA_MODES ? " and " : "", | |
1391 | EXTRA_MODES_FILE); | |
1392 | ||
1393 | puts ("\ | |
1394 | by genmodes. */\n\ | |
1395 | \n\ | |
0974c7d7 ZW |
1396 | #include \"config.h\"\n\ |
1397 | #include \"system.h\"\n\ | |
1398 | #include \"coretypes.h\"\n\ | |
1399 | #include \"tm.h\"\n\ | |
94134f42 ZW |
1400 | #include \"real.h\""); |
1401 | } | |
1402 | ||
1403 | static void | |
1404 | emit_min_insn_modes_c_header (void) | |
1405 | { | |
1406 | printf ("/* Generated automatically from machmode.def%s%s\n", | |
1407 | HAVE_EXTRA_MODES ? " and " : "", | |
1408 | EXTRA_MODES_FILE); | |
1409 | ||
1410 | puts ("\ | |
1411 | by genmodes. */\n\ | |
1412 | \n\ | |
1413 | #include \"bconfig.h\"\n\ | |
1414 | #include \"system.h\"\n\ | |
b0e84cf7 | 1415 | #include \"coretypes.h\""); |
0974c7d7 ZW |
1416 | } |
1417 | ||
1418 | static void | |
1419 | emit_mode_name (void) | |
1420 | { | |
e3a64162 | 1421 | int c; |
0974c7d7 ZW |
1422 | struct mode_data *m; |
1423 | ||
1424 | print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES"); | |
1425 | ||
1426 | for_all_modes (c, m) | |
1427 | printf (" \"%s\",\n", m->name); | |
1428 | ||
1429 | print_closer (); | |
1430 | } | |
1431 | ||
1432 | static void | |
1433 | emit_mode_class (void) | |
1434 | { | |
e3a64162 | 1435 | int c; |
0974c7d7 ZW |
1436 | struct mode_data *m; |
1437 | ||
1438 | print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES"); | |
1439 | ||
1440 | for_all_modes (c, m) | |
e3a64162 | 1441 | tagged_printf ("%s", mode_class_names[m->cl], m->name); |
0974c7d7 ZW |
1442 | |
1443 | print_closer (); | |
1444 | } | |
1445 | ||
1446 | static void | |
37783865 | 1447 | emit_mode_precision (void) |
0974c7d7 | 1448 | { |
e3a64162 | 1449 | int c; |
0974c7d7 ZW |
1450 | struct mode_data *m; |
1451 | ||
c6561a1a RS |
1452 | print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision", |
1453 | "NUM_MACHINE_MODES", adj_nunits); | |
0974c7d7 ZW |
1454 | |
1455 | for_all_modes (c, m) | |
37783865 | 1456 | if (m->precision != (unsigned int)-1) |
bb94ec76 | 1457 | tagged_printf ("{ %u" ZERO_COEFFS " }", m->precision, m->name); |
0974c7d7 | 1458 | else |
bb94ec76 RS |
1459 | tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS " }", |
1460 | m->bytesize, m->name); | |
0974c7d7 ZW |
1461 | |
1462 | print_closer (); | |
1463 | } | |
1464 | ||
1465 | static void | |
1466 | emit_mode_size (void) | |
1467 | { | |
e3a64162 | 1468 | int c; |
0974c7d7 ZW |
1469 | struct mode_data *m; |
1470 | ||
cf098191 | 1471 | print_maybe_const_decl ("%spoly_uint16_pod", "mode_size", |
c6561a1a | 1472 | "NUM_MACHINE_MODES", adj_nunits || adj_bytesize); |
0974c7d7 ZW |
1473 | |
1474 | for_all_modes (c, m) | |
cf098191 | 1475 | tagged_printf ("{ %u" ZERO_COEFFS " }", m->bytesize, m->name); |
0974c7d7 ZW |
1476 | |
1477 | print_closer (); | |
1478 | } | |
1479 | ||
1480 | static void | |
02befdf4 | 1481 | emit_mode_nunits (void) |
0974c7d7 | 1482 | { |
e3a64162 | 1483 | int c; |
0974c7d7 ZW |
1484 | struct mode_data *m; |
1485 | ||
c6561a1a RS |
1486 | print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits", |
1487 | "NUM_MACHINE_MODES", adj_nunits); | |
0974c7d7 ZW |
1488 | |
1489 | for_all_modes (c, m) | |
7b777afa | 1490 | tagged_printf ("{ %u" ZERO_COEFFS " }", m->ncomponents, m->name); |
0974c7d7 ZW |
1491 | |
1492 | print_closer (); | |
1493 | } | |
1494 | ||
1495 | static void | |
1496 | emit_mode_wider (void) | |
1497 | { | |
e3a64162 | 1498 | int c; |
0974c7d7 ZW |
1499 | struct mode_data *m; |
1500 | ||
1501 | print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES"); | |
1502 | ||
1503 | for_all_modes (c, m) | |
0d4a1197 | 1504 | tagged_printf ("E_%smode", |
0974c7d7 ZW |
1505 | m->wider ? m->wider->name : void_mode->name, |
1506 | m->name); | |
1507 | ||
1508 | print_closer (); | |
d2348bd5 DD |
1509 | print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES"); |
1510 | ||
1511 | for_all_modes (c, m) | |
1512 | { | |
1513 | struct mode_data * m2; | |
1514 | ||
1515 | for (m2 = m; | |
1516 | m2 && m2 != void_mode; | |
1517 | m2 = m2->wider) | |
1518 | { | |
1519 | if (m2->bytesize < 2 * m->bytesize) | |
1520 | continue; | |
1521 | if (m->precision != (unsigned int) -1) | |
1522 | { | |
1523 | if (m2->precision != 2 * m->precision) | |
1524 | continue; | |
1525 | } | |
1526 | else | |
1527 | { | |
1528 | if (m2->precision != (unsigned int) -1) | |
1529 | continue; | |
1530 | } | |
1531 | ||
a7de2c2a RH |
1532 | /* For vectors we want twice the number of components, |
1533 | with the same element type. */ | |
5c0caeb3 RS |
1534 | if (m->cl == MODE_VECTOR_BOOL |
1535 | || m->cl == MODE_VECTOR_INT | |
a7de2c2a RH |
1536 | || m->cl == MODE_VECTOR_FLOAT |
1537 | || m->cl == MODE_VECTOR_FRACT | |
1538 | || m->cl == MODE_VECTOR_UFRACT | |
1539 | || m->cl == MODE_VECTOR_ACCUM | |
1540 | || m->cl == MODE_VECTOR_UACCUM) | |
1541 | { | |
1542 | if (m2->ncomponents != 2 * m->ncomponents) | |
1543 | continue; | |
1544 | if (m->component != m2->component) | |
1545 | continue; | |
1546 | } | |
1547 | ||
d2348bd5 DD |
1548 | break; |
1549 | } | |
1550 | if (m2 == void_mode) | |
1551 | m2 = 0; | |
0d4a1197 | 1552 | tagged_printf ("E_%smode", |
d2348bd5 DD |
1553 | m2 ? m2->name : void_mode->name, |
1554 | m->name); | |
1555 | } | |
1556 | ||
1557 | print_closer (); | |
0974c7d7 ZW |
1558 | } |
1559 | ||
4304ccfd MM |
1560 | static void |
1561 | emit_mode_complex (void) | |
1562 | { | |
1563 | int c; | |
1564 | struct mode_data *m; | |
1565 | ||
1566 | print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES"); | |
1567 | ||
1568 | for_all_modes (c, m) | |
0d4a1197 | 1569 | tagged_printf ("E_%smode", |
4304ccfd MM |
1570 | m->complex ? m->complex->name : void_mode->name, |
1571 | m->name); | |
1572 | ||
1573 | print_closer (); | |
1574 | } | |
1575 | ||
0974c7d7 ZW |
1576 | static void |
1577 | emit_mode_mask (void) | |
1578 | { | |
e3a64162 | 1579 | int c; |
0974c7d7 ZW |
1580 | struct mode_data *m; |
1581 | ||
0411210f RS |
1582 | print_maybe_const_decl ("%sunsigned HOST_WIDE_INT", "mode_mask_array", |
1583 | "NUM_MACHINE_MODES", adj_nunits); | |
0974c7d7 | 1584 | puts ("\ |
379f1861 | 1585 | #define MODE_MASK(m) \\\n\ |
0974c7d7 | 1586 | ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\ |
dd4786fe | 1587 | ? HOST_WIDE_INT_M1U \\\n\ |
fecfbfa4 | 1588 | : (HOST_WIDE_INT_1U << (m)) - 1\n"); |
0974c7d7 ZW |
1589 | |
1590 | for_all_modes (c, m) | |
37783865 ZW |
1591 | if (m->precision != (unsigned int)-1) |
1592 | tagged_printf ("MODE_MASK (%u)", m->precision, m->name); | |
0974c7d7 | 1593 | else |
379f1861 | 1594 | tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m->bytesize, m->name); |
0974c7d7 | 1595 | |
379f1861 | 1596 | puts ("#undef MODE_MASK"); |
0974c7d7 ZW |
1597 | print_closer (); |
1598 | } | |
1599 | ||
1600 | static void | |
1601 | emit_mode_inner (void) | |
1602 | { | |
e3a64162 | 1603 | int c; |
0974c7d7 ZW |
1604 | struct mode_data *m; |
1605 | ||
1606 | print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES"); | |
1607 | ||
1608 | for_all_modes (c, m) | |
0d4a1197 | 1609 | tagged_printf ("E_%smode", |
e90247f8 | 1610 | c != MODE_PARTIAL_INT && m->component |
1c0e448f | 1611 | ? m->component->name : m->name, |
0974c7d7 ZW |
1612 | m->name); |
1613 | ||
1614 | print_closer (); | |
1615 | } | |
1616 | ||
8dc89e4d DS |
1617 | /* Emit mode_unit_size array into insn-modes.c file. */ |
1618 | static void | |
1619 | emit_mode_unit_size (void) | |
1620 | { | |
1621 | int c; | |
1622 | struct mode_data *m; | |
1623 | ||
1624 | print_maybe_const_decl ("%sunsigned char", "mode_unit_size", | |
c6561a1a | 1625 | "NUM_MACHINE_MODES", adj_bytesize); |
8dc89e4d DS |
1626 | |
1627 | for_all_modes (c, m) | |
1628 | tagged_printf ("%u", | |
1629 | c != MODE_PARTIAL_INT && m->component | |
1630 | ? m->component->bytesize : m->bytesize, m->name); | |
1631 | ||
1632 | print_closer (); | |
1633 | } | |
1634 | ||
1635 | /* Emit mode_unit_precision array into insn-modes.c file. */ | |
1636 | static void | |
1637 | emit_mode_unit_precision (void) | |
1638 | { | |
1639 | int c; | |
1640 | struct mode_data *m; | |
1641 | ||
1642 | print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES"); | |
1643 | ||
1644 | for_all_modes (c, m) | |
1645 | { | |
1646 | struct mode_data *m2 = (c != MODE_PARTIAL_INT && m->component) ? | |
1647 | m->component : m; | |
1648 | if (m2->precision != (unsigned int)-1) | |
1649 | tagged_printf ("%u", m2->precision, m->name); | |
1650 | else | |
1651 | tagged_printf ("%u*BITS_PER_UNIT", m2->bytesize, m->name); | |
1652 | } | |
1653 | ||
1654 | print_closer (); | |
1655 | } | |
1656 | ||
1657 | ||
0974c7d7 ZW |
1658 | static void |
1659 | emit_mode_base_align (void) | |
1660 | { | |
e3a64162 | 1661 | int c; |
0974c7d7 ZW |
1662 | struct mode_data *m; |
1663 | ||
5fbb13a7 | 1664 | print_maybe_const_decl ("%sunsigned short", |
b8eaca23 | 1665 | "mode_base_align", "NUM_MACHINE_MODES", |
c6561a1a | 1666 | adj_alignment); |
0974c7d7 ZW |
1667 | |
1668 | for_all_modes (c, m) | |
1669 | tagged_printf ("%u", m->alignment, m->name); | |
1670 | ||
1671 | print_closer (); | |
1672 | } | |
1673 | ||
1674 | static void | |
1675 | emit_class_narrowest_mode (void) | |
1676 | { | |
e3a64162 | 1677 | int c; |
0974c7d7 ZW |
1678 | |
1679 | print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS"); | |
1680 | ||
1681 | for (c = 0; c < MAX_MODE_CLASS; c++) | |
1682 | /* Bleah, all this to get the comment right for MIN_MODE_INT. */ | |
1683 | tagged_printf ("MIN_%s", mode_class_names[c], | |
b8eaca23 | 1684 | modes[c] |
d8487c94 | 1685 | ? ((c != MODE_INT || modes[c]->precision != 1) |
b8eaca23 ZW |
1686 | ? modes[c]->name |
1687 | : (modes[c]->next | |
1688 | ? modes[c]->next->name | |
0974c7d7 ZW |
1689 | : void_mode->name)) |
1690 | : void_mode->name); | |
b8698a0f | 1691 | |
0974c7d7 ZW |
1692 | print_closer (); |
1693 | } | |
1694 | ||
94134f42 ZW |
1695 | static void |
1696 | emit_real_format_for_mode (void) | |
1697 | { | |
1698 | struct mode_data *m; | |
1699 | ||
b8eaca23 ZW |
1700 | /* The entities pointed to by this table are constant, whether |
1701 | or not the table itself is constant. | |
1702 | ||
1703 | For backward compatibility this table is always writable | |
c5387660 | 1704 | (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME: |
b8eaca23 ZW |
1705 | convert all said targets to use ADJUST_FORMAT instead. */ |
1706 | #if 0 | |
1707 | print_maybe_const_decl ("const struct real_format *%s", | |
1708 | "real_format_for_mode", | |
1709 | "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1", | |
1710 | format); | |
1711 | #else | |
1712 | print_decl ("struct real_format *\n", "real_format_for_mode", | |
909e2256 JG |
1713 | "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 " |
1714 | "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1"); | |
b8eaca23 | 1715 | #endif |
94134f42 | 1716 | |
909e2256 | 1717 | /* The beginning of the table is entries for float modes. */ |
b8eaca23 | 1718 | for (m = modes[MODE_FLOAT]; m; m = m->next) |
94134f42 ZW |
1719 | if (!strcmp (m->format, "0")) |
1720 | tagged_printf ("%s", m->format, m->name); | |
1721 | else | |
1722 | tagged_printf ("&%s", m->format, m->name); | |
1723 | ||
909e2256 JG |
1724 | /* The end of the table is entries for decimal float modes. */ |
1725 | for (m = modes[MODE_DECIMAL_FLOAT]; m; m = m->next) | |
1726 | if (!strcmp (m->format, "0")) | |
1727 | tagged_printf ("%s", m->format, m->name); | |
1728 | else | |
1729 | tagged_printf ("&%s", m->format, m->name); | |
1730 | ||
94134f42 ZW |
1731 | print_closer (); |
1732 | } | |
1733 | ||
b8eaca23 ZW |
1734 | static void |
1735 | emit_mode_adjustments (void) | |
1736 | { | |
1737 | struct mode_adjust *a; | |
02befdf4 | 1738 | struct mode_data *m; |
b8eaca23 | 1739 | |
0411210f RS |
1740 | if (adj_nunits) |
1741 | printf ("\n" | |
1742 | "void\n" | |
1743 | "adjust_mode_mask (machine_mode mode)\n" | |
1744 | "{\n" | |
1745 | " unsigned int precision;\n" | |
1746 | " if (GET_MODE_PRECISION (mode).is_constant (&precision)\n" | |
1747 | " && precision < HOST_BITS_PER_WIDE_INT)\n" | |
1748 | " mode_mask_array[mode] = (HOST_WIDE_INT_1U << precision) - 1;" | |
1749 | "\n" | |
1750 | " else\n" | |
1751 | " mode_mask_array[mode] = HOST_WIDE_INT_M1U;\n" | |
1752 | "}\n"); | |
1753 | ||
02befdf4 ZW |
1754 | puts ("\ |
1755 | \nvoid\ | |
1756 | \ninit_adjust_machine_modes (void)\ | |
1757 | \n{\ | |
cf098191 RS |
1758 | \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\ |
1759 | size_t s ATTRIBUTE_UNUSED;"); | |
b8eaca23 | 1760 | |
c6561a1a RS |
1761 | for (a = adj_nunits; a; a = a->next) |
1762 | { | |
1763 | m = a->mode; | |
1764 | printf ("\n" | |
1765 | " {\n" | |
1766 | " /* %s:%d */\n ps = %s;\n", | |
1767 | a->file, a->line, a->adjustment); | |
1768 | printf (" int old_factor = vector_element_size" | |
1769 | " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n", | |
1770 | m->name, m->name); | |
0411210f | 1771 | printf (" mode_precision[E_%smode] = ps * old_factor;\n", m->name); |
c6561a1a RS |
1772 | printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode]," |
1773 | " BITS_PER_UNIT);\n", m->name, m->name); | |
1774 | printf (" mode_nunits[E_%smode] = ps;\n", m->name); | |
0411210f | 1775 | printf (" adjust_mode_mask (E_%smode);\n", m->name); |
c6561a1a RS |
1776 | printf (" }\n"); |
1777 | } | |
1778 | ||
02befdf4 ZW |
1779 | /* Size adjustments must be propagated to all containing modes. |
1780 | A size adjustment forces us to recalculate the alignment too. */ | |
b8eaca23 | 1781 | for (a = adj_bytesize; a; a = a->next) |
02befdf4 | 1782 | { |
cf098191 RS |
1783 | printf ("\n /* %s:%d */\n", a->file, a->line); |
1784 | switch (a->mode->cl) | |
1785 | { | |
5c0caeb3 | 1786 | case MODE_VECTOR_BOOL: |
cf098191 RS |
1787 | case MODE_VECTOR_INT: |
1788 | case MODE_VECTOR_FLOAT: | |
1789 | case MODE_VECTOR_FRACT: | |
1790 | case MODE_VECTOR_UFRACT: | |
1791 | case MODE_VECTOR_ACCUM: | |
1792 | case MODE_VECTOR_UACCUM: | |
1793 | printf (" ps = %s;\n", a->adjustment); | |
1794 | printf (" s = mode_unit_size[E_%smode];\n", a->mode->name); | |
1795 | break; | |
1796 | ||
1797 | default: | |
1798 | printf (" ps = s = %s;\n", a->adjustment); | |
1799 | printf (" mode_unit_size[E_%smode] = s;\n", a->mode->name); | |
1800 | break; | |
1801 | } | |
1802 | printf (" mode_size[E_%smode] = ps;\n", a->mode->name); | |
1803 | printf (" mode_base_align[E_%smode] = known_alignment (ps);\n", | |
02befdf4 ZW |
1804 | a->mode->name); |
1805 | ||
1806 | for (m = a->mode->contained; m; m = m->next_cont) | |
1807 | { | |
e3a64162 | 1808 | switch (m->cl) |
02befdf4 ZW |
1809 | { |
1810 | case MODE_COMPLEX_INT: | |
1811 | case MODE_COMPLEX_FLOAT: | |
0d4a1197 RS |
1812 | printf (" mode_size[E_%smode] = 2*s;\n", m->name); |
1813 | printf (" mode_unit_size[E_%smode] = s;\n", m->name); | |
1814 | printf (" mode_base_align[E_%smode] = s & (~s + 1);\n", | |
02befdf4 ZW |
1815 | m->name); |
1816 | break; | |
1817 | ||
5c0caeb3 RS |
1818 | case MODE_VECTOR_BOOL: |
1819 | /* Changes to BImode should not affect vector booleans. */ | |
1820 | break; | |
1821 | ||
02befdf4 ZW |
1822 | case MODE_VECTOR_INT: |
1823 | case MODE_VECTOR_FLOAT: | |
1699ec0b CF |
1824 | case MODE_VECTOR_FRACT: |
1825 | case MODE_VECTOR_UFRACT: | |
1826 | case MODE_VECTOR_ACCUM: | |
1827 | case MODE_VECTOR_UACCUM: | |
cf098191 | 1828 | printf (" mode_size[E_%smode] = %d * ps;\n", |
02befdf4 | 1829 | m->name, m->ncomponents); |
0d4a1197 | 1830 | printf (" mode_unit_size[E_%smode] = s;\n", m->name); |
cf098191 RS |
1831 | printf (" mode_base_align[E_%smode]" |
1832 | " = known_alignment (%d * ps);\n", | |
1833 | m->name, m->ncomponents); | |
02befdf4 ZW |
1834 | break; |
1835 | ||
1836 | default: | |
1837 | internal_error ( | |
1838 | "mode %s is neither vector nor complex but contains %s", | |
1839 | m->name, a->mode->name); | |
1840 | /* NOTREACHED */ | |
1841 | } | |
1842 | } | |
1843 | } | |
b8eaca23 | 1844 | |
02befdf4 ZW |
1845 | /* Alignment adjustments propagate too. |
1846 | ??? This may not be the right thing for vector modes. */ | |
b8eaca23 | 1847 | for (a = adj_alignment; a; a = a->next) |
02befdf4 ZW |
1848 | { |
1849 | printf ("\n /* %s:%d */\n s = %s;\n", | |
1850 | a->file, a->line, a->adjustment); | |
0d4a1197 | 1851 | printf (" mode_base_align[E_%smode] = s;\n", a->mode->name); |
b8eaca23 | 1852 | |
02befdf4 ZW |
1853 | for (m = a->mode->contained; m; m = m->next_cont) |
1854 | { | |
e3a64162 | 1855 | switch (m->cl) |
02befdf4 ZW |
1856 | { |
1857 | case MODE_COMPLEX_INT: | |
1858 | case MODE_COMPLEX_FLOAT: | |
0d4a1197 | 1859 | printf (" mode_base_align[E_%smode] = s;\n", m->name); |
02befdf4 ZW |
1860 | break; |
1861 | ||
5c0caeb3 RS |
1862 | case MODE_VECTOR_BOOL: |
1863 | /* Changes to BImode should not affect vector booleans. */ | |
1864 | break; | |
1865 | ||
02befdf4 ZW |
1866 | case MODE_VECTOR_INT: |
1867 | case MODE_VECTOR_FLOAT: | |
1699ec0b CF |
1868 | case MODE_VECTOR_FRACT: |
1869 | case MODE_VECTOR_UFRACT: | |
1870 | case MODE_VECTOR_ACCUM: | |
1871 | case MODE_VECTOR_UACCUM: | |
0d4a1197 | 1872 | printf (" mode_base_align[E_%smode] = %d*s;\n", |
02befdf4 ZW |
1873 | m->name, m->ncomponents); |
1874 | break; | |
1875 | ||
1876 | default: | |
1877 | internal_error ( | |
1878 | "mode %s is neither vector nor complex but contains %s", | |
1879 | m->name, a->mode->name); | |
1880 | /* NOTREACHED */ | |
1881 | } | |
1882 | } | |
1883 | } | |
1699ec0b CF |
1884 | |
1885 | /* Ibit adjustments don't have to propagate. */ | |
1886 | for (a = adj_ibit; a; a = a->next) | |
1887 | { | |
1888 | printf ("\n /* %s:%d */\n s = %s;\n", | |
1889 | a->file, a->line, a->adjustment); | |
0d4a1197 | 1890 | printf (" mode_ibit[E_%smode] = s;\n", a->mode->name); |
1699ec0b CF |
1891 | } |
1892 | ||
1893 | /* Fbit adjustments don't have to propagate. */ | |
1894 | for (a = adj_fbit; a; a = a->next) | |
1895 | { | |
1896 | printf ("\n /* %s:%d */\n s = %s;\n", | |
1897 | a->file, a->line, a->adjustment); | |
0d4a1197 | 1898 | printf (" mode_fbit[E_%smode] = s;\n", a->mode->name); |
1699ec0b | 1899 | } |
b8698a0f | 1900 | |
02befdf4 | 1901 | /* Real mode formats don't have to propagate anywhere. */ |
b8eaca23 | 1902 | for (a = adj_format; a; a = a->next) |
0d4a1197 | 1903 | printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n", |
b8eaca23 ZW |
1904 | a->file, a->line, a->mode->name, a->adjustment); |
1905 | ||
1906 | puts ("}"); | |
1907 | } | |
1908 | ||
1699ec0b CF |
1909 | /* Emit ibit for all modes. */ |
1910 | ||
1911 | static void | |
1912 | emit_mode_ibit (void) | |
1913 | { | |
1914 | int c; | |
1915 | struct mode_data *m; | |
1916 | ||
1917 | print_maybe_const_decl ("%sunsigned char", | |
1918 | "mode_ibit", "NUM_MACHINE_MODES", | |
c6561a1a | 1919 | adj_ibit); |
1699ec0b CF |
1920 | |
1921 | for_all_modes (c, m) | |
1922 | tagged_printf ("%u", m->ibit, m->name); | |
1923 | ||
1924 | print_closer (); | |
1925 | } | |
1926 | ||
1927 | /* Emit fbit for all modes. */ | |
1928 | ||
1929 | static void | |
1930 | emit_mode_fbit (void) | |
1931 | { | |
1932 | int c; | |
1933 | struct mode_data *m; | |
1934 | ||
1935 | print_maybe_const_decl ("%sunsigned char", | |
1936 | "mode_fbit", "NUM_MACHINE_MODES", | |
c6561a1a | 1937 | adj_fbit); |
1699ec0b CF |
1938 | |
1939 | for_all_modes (c, m) | |
1940 | tagged_printf ("%u", m->fbit, m->name); | |
1941 | ||
1942 | print_closer (); | |
1943 | } | |
1944 | ||
78a7c317 DD |
1945 | /* Emit __intN for all modes. */ |
1946 | ||
1947 | static void | |
1948 | emit_mode_int_n (void) | |
1949 | { | |
1950 | int c; | |
1951 | struct mode_data *m; | |
1952 | struct mode_data **mode_sort; | |
1953 | int n_modes = 0; | |
1954 | int i, j; | |
1955 | ||
1956 | print_decl ("int_n_data_t", "int_n_data", ""); | |
1957 | ||
1958 | n_modes = 0; | |
1959 | for_all_modes (c, m) | |
1960 | if (m->int_n) | |
1961 | n_modes ++; | |
1962 | mode_sort = XALLOCAVEC (struct mode_data *, n_modes); | |
1963 | ||
1964 | n_modes = 0; | |
1965 | for_all_modes (c, m) | |
1966 | if (m->int_n) | |
1967 | mode_sort[n_modes++] = m; | |
1968 | ||
1969 | /* Yes, this is a bubblesort, but there are at most four (and | |
1970 | usually only 1-2) entries to sort. */ | |
1971 | for (i = 0; i<n_modes - 1; i++) | |
1972 | for (j = i + 1; j < n_modes; j++) | |
1973 | if (mode_sort[i]->int_n > mode_sort[j]->int_n) | |
fab27f52 | 1974 | std::swap (mode_sort[i], mode_sort[j]); |
78a7c317 DD |
1975 | |
1976 | for (i = 0; i < n_modes; i ++) | |
1977 | { | |
1978 | m = mode_sort[i]; | |
1979 | printf(" {\n"); | |
1980 | tagged_printf ("%u", m->int_n, m->name); | |
bf862c53 | 1981 | printf ("{ E_%smode },", m->name); |
78a7c317 DD |
1982 | printf(" },\n"); |
1983 | } | |
1984 | ||
1985 | print_closer (); | |
1986 | } | |
1987 | ||
1699ec0b | 1988 | |
0974c7d7 ZW |
1989 | static void |
1990 | emit_insn_modes_c (void) | |
1991 | { | |
1992 | emit_insn_modes_c_header (); | |
1993 | emit_mode_name (); | |
1994 | emit_mode_class (); | |
37783865 | 1995 | emit_mode_precision (); |
0974c7d7 | 1996 | emit_mode_size (); |
02befdf4 | 1997 | emit_mode_nunits (); |
0974c7d7 | 1998 | emit_mode_wider (); |
4304ccfd | 1999 | emit_mode_complex (); |
0974c7d7 ZW |
2000 | emit_mode_mask (); |
2001 | emit_mode_inner (); | |
8dc89e4d DS |
2002 | emit_mode_unit_size (); |
2003 | emit_mode_unit_precision (); | |
0974c7d7 ZW |
2004 | emit_mode_base_align (); |
2005 | emit_class_narrowest_mode (); | |
94134f42 | 2006 | emit_real_format_for_mode (); |
b8eaca23 | 2007 | emit_mode_adjustments (); |
1699ec0b CF |
2008 | emit_mode_ibit (); |
2009 | emit_mode_fbit (); | |
78a7c317 | 2010 | emit_mode_int_n (); |
94134f42 ZW |
2011 | } |
2012 | ||
2013 | static void | |
2014 | emit_min_insn_modes_c (void) | |
2015 | { | |
2016 | emit_min_insn_modes_c_header (); | |
2017 | emit_mode_name (); | |
2018 | emit_mode_class (); | |
c4d5ab5d | 2019 | emit_mode_nunits (); |
94134f42 | 2020 | emit_mode_wider (); |
c4d5ab5d | 2021 | emit_mode_inner (); |
94134f42 | 2022 | emit_class_narrowest_mode (); |
0974c7d7 ZW |
2023 | } |
2024 | ||
2025 | /* Master control. */ | |
2026 | int | |
62e5bf5d | 2027 | main (int argc, char **argv) |
0974c7d7 | 2028 | { |
b0e84cf7 | 2029 | bool gen_header = false, gen_inlines = false, gen_min = false; |
0974c7d7 ZW |
2030 | progname = argv[0]; |
2031 | ||
2032 | if (argc == 1) | |
94134f42 | 2033 | ; |
0974c7d7 ZW |
2034 | else if (argc == 2 && !strcmp (argv[1], "-h")) |
2035 | gen_header = true; | |
b0e84cf7 RS |
2036 | else if (argc == 2 && !strcmp (argv[1], "-i")) |
2037 | gen_inlines = true; | |
94134f42 ZW |
2038 | else if (argc == 2 && !strcmp (argv[1], "-m")) |
2039 | gen_min = true; | |
0974c7d7 ZW |
2040 | else |
2041 | { | |
b0e84cf7 | 2042 | error ("usage: %s [-h|-i|-m] > file", progname); |
0974c7d7 ZW |
2043 | return FATAL_EXIT_CODE; |
2044 | } | |
2045 | ||
b8eaca23 ZW |
2046 | modes_by_name = htab_create_alloc (64, hash_mode, eq_mode, 0, xcalloc, free); |
2047 | ||
0974c7d7 ZW |
2048 | create_modes (); |
2049 | complete_all_modes (); | |
2050 | ||
2051 | if (have_error) | |
2052 | return FATAL_EXIT_CODE; | |
b8698a0f | 2053 | |
0974c7d7 ZW |
2054 | calc_wider_mode (); |
2055 | ||
2056 | if (gen_header) | |
2057 | emit_insn_modes_h (); | |
b0e84cf7 RS |
2058 | else if (gen_inlines) |
2059 | emit_insn_modes_inline_h (); | |
94134f42 ZW |
2060 | else if (gen_min) |
2061 | emit_min_insn_modes_c (); | |
0974c7d7 ZW |
2062 | else |
2063 | emit_insn_modes_c (); | |
2064 | ||
2065 | if (fflush (stdout) || fclose (stdout)) | |
2066 | return FATAL_EXIT_CODE; | |
2067 | return SUCCESS_EXIT_CODE; | |
2068 | } |