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