Rebase.
[official-gcc.git] / gcc / genmodes.c
blob4a4fa3321a0f00c113feea7f8e1cf42db29db1a5
1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
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
8 Software Foundation; either version 3, or (at your option) any later
9 version.
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.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "bconfig.h"
21 #include "system.h"
22 #include "errors.h"
23 #include "hashtab.h"
25 /* enum mode_class is normally defined by machmode.h but we can't
26 include that header here. */
27 #include "mode-classes.def"
29 #define DEF_MODE_CLASS(M) M
30 enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
31 #undef DEF_MODE_CLASS
33 /* Text names of mode classes, for output. */
34 #define DEF_MODE_CLASS(M) #M
35 static const char *const mode_class_names[MAX_MODE_CLASS] =
37 MODE_CLASSES
39 #undef DEF_MODE_CLASS
40 #undef MODE_CLASSES
42 #ifdef EXTRA_MODES_FILE
43 # define HAVE_EXTRA_MODES 1
44 #else
45 # define HAVE_EXTRA_MODES 0
46 # define EXTRA_MODES_FILE ""
47 #endif
49 /* Data structure for building up what we know about a mode.
50 They're clustered by mode class. */
51 struct mode_data
53 struct mode_data *next; /* next this class - arbitrary order */
55 const char *name; /* printable mode name -- SI, not SImode */
56 enum mode_class cl; /* this mode class */
57 unsigned int precision; /* size in bits, equiv to TYPE_PRECISION */
58 unsigned int bytesize; /* storage size in addressable units */
59 unsigned int ncomponents; /* number of subunits */
60 unsigned int alignment; /* mode alignment */
61 const char *format; /* floating point format - float modes only */
63 struct mode_data *component; /* mode of components */
64 struct mode_data *wider; /* next wider mode */
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. */
70 const char *file; /* file and line of definition, */
71 unsigned int line; /* for error reporting */
72 unsigned int counter; /* Rank ordering of modes */
73 unsigned int ibit; /* the number of integral bits */
74 unsigned int fbit; /* the number of fractional bits */
75 bool need_bytesize_adj; /* true if this mode need dynamic size
76 adjustment */
79 static struct mode_data *modes[MAX_MODE_CLASS];
80 static unsigned int n_modes[MAX_MODE_CLASS];
81 static struct mode_data *void_mode;
83 static const struct mode_data blank_mode = {
84 0, "<unknown>", MAX_MODE_CLASS,
85 -1U, -1U, -1U, -1U,
86 0, 0, 0, 0, 0,
87 "<unknown>", 0, 0, 0, 0, false
90 static htab_t modes_by_name;
92 /* Data structure for recording target-specified runtime adjustments
93 to a particular mode. We support varying the byte size, the
94 alignment, and the floating point format. */
95 struct mode_adjust
97 struct mode_adjust *next;
98 struct mode_data *mode;
99 const char *adjustment;
101 const char *file;
102 unsigned int line;
105 static struct mode_adjust *adj_bytesize;
106 static struct mode_adjust *adj_alignment;
107 static struct mode_adjust *adj_format;
108 static struct mode_adjust *adj_ibit;
109 static struct mode_adjust *adj_fbit;
111 /* Mode class operations. */
112 static enum mode_class
113 complex_class (enum mode_class c)
115 switch (c)
117 case MODE_INT: return MODE_COMPLEX_INT;
118 case MODE_FLOAT: return MODE_COMPLEX_FLOAT;
119 default:
120 error ("no complex class for class %s", mode_class_names[c]);
121 return MODE_RANDOM;
125 static enum mode_class
126 vector_class (enum mode_class cl)
128 switch (cl)
130 case MODE_INT: return MODE_VECTOR_INT;
131 case MODE_FLOAT: return MODE_VECTOR_FLOAT;
132 case MODE_FRACT: return MODE_VECTOR_FRACT;
133 case MODE_UFRACT: return MODE_VECTOR_UFRACT;
134 case MODE_ACCUM: return MODE_VECTOR_ACCUM;
135 case MODE_UACCUM: return MODE_VECTOR_UACCUM;
136 default:
137 error ("no vector class for class %s", mode_class_names[cl]);
138 return MODE_RANDOM;
142 /* Utility routines. */
143 static inline struct mode_data *
144 find_mode (const char *name)
146 struct mode_data key;
148 key.name = name;
149 return (struct mode_data *) htab_find (modes_by_name, &key);
152 static struct mode_data *
153 new_mode (enum mode_class cl, const char *name,
154 const char *file, unsigned int line)
156 struct mode_data *m;
157 static unsigned int count = 0;
159 m = find_mode (name);
160 if (m)
162 error ("%s:%d: duplicate definition of mode \"%s\"",
163 trim_filename (file), line, name);
164 error ("%s:%d: previous definition here", m->file, m->line);
165 return m;
168 m = XNEW (struct mode_data);
169 memcpy (m, &blank_mode, sizeof (struct mode_data));
170 m->cl = cl;
171 m->name = name;
172 if (file)
173 m->file = trim_filename (file);
174 m->line = line;
175 m->counter = count++;
177 m->next = modes[cl];
178 modes[cl] = m;
179 n_modes[cl]++;
181 *htab_find_slot (modes_by_name, m, INSERT) = m;
183 return m;
186 static hashval_t
187 hash_mode (const void *p)
189 const struct mode_data *m = (const struct mode_data *)p;
190 return htab_hash_string (m->name);
193 static int
194 eq_mode (const void *p, const void *q)
196 const struct mode_data *a = (const struct mode_data *)p;
197 const struct mode_data *b = (const struct mode_data *)q;
199 return !strcmp (a->name, b->name);
202 #define for_all_modes(C, M) \
203 for (C = 0; C < MAX_MODE_CLASS; C++) \
204 for (M = modes[C]; M; M = M->next)
206 static void ATTRIBUTE_UNUSED
207 new_adjust (const char *name,
208 struct mode_adjust **category, const char *catname,
209 const char *adjustment,
210 enum mode_class required_class_from,
211 enum mode_class required_class_to,
212 const char *file, unsigned int line)
214 struct mode_data *mode = find_mode (name);
215 struct mode_adjust *a;
217 file = trim_filename (file);
219 if (!mode)
221 error ("%s:%d: no mode \"%s\"", file, line, name);
222 return;
225 if (required_class_from != MODE_RANDOM
226 && (mode->cl < required_class_from || mode->cl > required_class_to))
228 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
229 file, line, name, mode_class_names[required_class_from] + 5,
230 mode_class_names[required_class_to] + 5);
231 return;
234 for (a = *category; a; a = a->next)
235 if (a->mode == mode)
237 error ("%s:%d: mode \"%s\" already has a %s adjustment",
238 file, line, name, catname);
239 error ("%s:%d: previous adjustment here", a->file, a->line);
240 return;
243 a = XNEW (struct mode_adjust);
244 a->mode = mode;
245 a->adjustment = adjustment;
246 a->file = file;
247 a->line = line;
249 a->next = *category;
250 *category = a;
253 /* Diagnose failure to meet expectations in a partially filled out
254 mode structure. */
255 enum requirement { SET, UNSET, OPTIONAL };
257 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
258 switch (req) \
260 case SET: \
261 if (val == unset) \
262 error ("%s:%d: (%s) field %s must be set", \
263 file, line, mname, fname); \
264 break; \
265 case UNSET: \
266 if (val != unset) \
267 error ("%s:%d: (%s) field %s must not be set", \
268 file, line, mname, fname); \
269 case OPTIONAL: \
270 break; \
272 } while (0)
274 #define validate_field(M, F) \
275 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
277 static void
278 validate_mode (struct mode_data *m,
279 enum requirement r_precision,
280 enum requirement r_bytesize,
281 enum requirement r_component,
282 enum requirement r_ncomponents,
283 enum requirement r_format)
285 validate_field (m, precision);
286 validate_field (m, bytesize);
287 validate_field (m, component);
288 validate_field (m, ncomponents);
289 validate_field (m, format);
291 #undef validate_field
292 #undef validate_field_
294 /* Given a partially-filled-out mode structure, figure out what we can
295 and fill the rest of it in; die if it isn't enough. */
296 static void
297 complete_mode (struct mode_data *m)
299 unsigned int alignment;
301 if (!m->name)
303 error ("%s:%d: mode with no name", m->file, m->line);
304 return;
306 if (m->cl == MAX_MODE_CLASS)
308 error ("%s:%d: %smode has no mode class", m->file, m->line, m->name);
309 return;
312 switch (m->cl)
314 case MODE_RANDOM:
315 /* Nothing more need be said. */
316 if (!strcmp (m->name, "VOID"))
317 void_mode = m;
319 validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET);
321 m->precision = 0;
322 m->bytesize = 0;
323 m->ncomponents = 0;
324 m->component = 0;
325 break;
327 case MODE_CC:
328 /* Again, nothing more need be said. For historical reasons,
329 the size of a CC mode is four units. */
330 validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET);
332 m->bytesize = 4;
333 m->ncomponents = 1;
334 m->component = 0;
335 break;
337 case MODE_INT:
338 case MODE_POINTER_BOUNDS:
339 case MODE_FLOAT:
340 case MODE_DECIMAL_FLOAT:
341 case MODE_FRACT:
342 case MODE_UFRACT:
343 case MODE_ACCUM:
344 case MODE_UACCUM:
345 /* A scalar mode must have a byte size, may have a bit size,
346 and must not have components. A float mode must have a
347 format. */
348 validate_mode (m, OPTIONAL, SET, UNSET, UNSET,
349 (m->cl == MODE_FLOAT || m->cl == MODE_DECIMAL_FLOAT)
350 ? SET : UNSET);
352 m->ncomponents = 1;
353 m->component = 0;
354 break;
356 case MODE_PARTIAL_INT:
357 /* A partial integer mode uses ->component to say what the
358 corresponding full-size integer mode is, and may also
359 specify a bit size. */
360 validate_mode (m, OPTIONAL, UNSET, SET, UNSET, UNSET);
362 m->bytesize = m->component->bytesize;
364 m->ncomponents = 1;
365 break;
367 case MODE_COMPLEX_INT:
368 case MODE_COMPLEX_FLOAT:
369 /* Complex modes should have a component indicated, but no more. */
370 validate_mode (m, UNSET, UNSET, SET, UNSET, UNSET);
371 m->ncomponents = 2;
372 if (m->component->precision != (unsigned int)-1)
373 m->precision = 2 * m->component->precision;
374 m->bytesize = 2 * m->component->bytesize;
375 break;
377 case MODE_VECTOR_INT:
378 case MODE_VECTOR_FLOAT:
379 case MODE_VECTOR_FRACT:
380 case MODE_VECTOR_UFRACT:
381 case MODE_VECTOR_ACCUM:
382 case MODE_VECTOR_UACCUM:
383 /* Vector modes should have a component and a number of components. */
384 validate_mode (m, UNSET, UNSET, SET, SET, UNSET);
385 if (m->component->precision != (unsigned int)-1)
386 m->precision = m->ncomponents * m->component->precision;
387 m->bytesize = m->ncomponents * m->component->bytesize;
388 break;
390 default:
391 gcc_unreachable ();
394 /* If not already specified, the mode alignment defaults to the largest
395 power of two that divides the size of the object. Complex types are
396 not more aligned than their contents. */
397 if (m->cl == MODE_COMPLEX_INT || m->cl == MODE_COMPLEX_FLOAT)
398 alignment = m->component->bytesize;
399 else
400 alignment = m->bytesize;
402 m->alignment = alignment & (~alignment + 1);
404 /* If this mode has components, make the component mode point back
405 to this mode, for the sake of adjustments. */
406 if (m->component)
408 m->next_cont = m->component->contained;
409 m->component->contained = m;
413 static void
414 complete_all_modes (void)
416 struct mode_data *m;
417 int cl;
419 for_all_modes (cl, m)
420 complete_mode (m);
423 /* For each mode in class CLASS, construct a corresponding complex mode. */
424 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
425 static void
426 make_complex_modes (enum mode_class cl,
427 const char *file, unsigned int line)
429 struct mode_data *m;
430 struct mode_data *c;
431 enum mode_class cclass = complex_class (cl);
433 if (cclass == MODE_RANDOM)
434 return;
436 for (m = modes[cl]; m; m = m->next)
438 char *p, *buf;
439 size_t m_len;
441 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
442 if (m->precision == 1)
443 continue;
445 m_len = strlen (m->name);
446 /* The leading "1 +" is in case we prepend a "C" below. */
447 buf = (char *) xmalloc (1 + m_len + 1);
449 /* Float complex modes are named SCmode, etc.
450 Int complex modes are named CSImode, etc.
451 This inconsistency should be eliminated. */
452 p = 0;
453 if (cl == MODE_FLOAT)
455 memcpy (buf, m->name, m_len + 1);
456 p = strchr (buf, 'F');
457 if (p == 0 && strchr (buf, 'D') == 0)
459 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
460 m->file, m->line, m->name);
461 free (buf);
462 continue;
465 if (p != 0)
466 *p = 'C';
467 else
469 buf[0] = 'C';
470 memcpy (buf + 1, m->name, m_len + 1);
473 c = new_mode (cclass, buf, file, line);
474 c->component = m;
478 /* For all modes in class CL, construct vector modes of width
479 WIDTH, having as many components as necessary. */
480 #define VECTOR_MODES(C, W) make_vector_modes (MODE_##C, W, __FILE__, __LINE__)
481 static void ATTRIBUTE_UNUSED
482 make_vector_modes (enum mode_class cl, unsigned int width,
483 const char *file, unsigned int line)
485 struct mode_data *m;
486 struct mode_data *v;
487 char buf[8];
488 unsigned int ncomponents;
489 enum mode_class vclass = vector_class (cl);
491 if (vclass == MODE_RANDOM)
492 return;
494 for (m = modes[cl]; m; m = m->next)
496 /* Do not construct vector modes with only one element, or
497 vector modes where the element size doesn't divide the full
498 size evenly. */
499 ncomponents = width / m->bytesize;
500 if (ncomponents < 2)
501 continue;
502 if (width % m->bytesize)
503 continue;
505 /* Skip QFmode and BImode. FIXME: this special case should
506 not be necessary. */
507 if (cl == MODE_FLOAT && m->bytesize == 1)
508 continue;
509 if (cl == MODE_INT && m->precision == 1)
510 continue;
512 if ((size_t)snprintf (buf, sizeof buf, "V%u%s", ncomponents, m->name)
513 >= sizeof buf)
515 error ("%s:%d: mode name \"%s\" is too long",
516 m->file, m->line, m->name);
517 continue;
520 v = new_mode (vclass, xstrdup (buf), file, line);
521 v->component = m;
522 v->ncomponents = ncomponents;
526 /* Input. */
528 #define _SPECIAL_MODE(C, N) \
529 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
530 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
531 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
533 static void
534 make_special_mode (enum mode_class cl, const char *name,
535 const char *file, unsigned int line)
537 new_mode (cl, name, file, line);
540 #define POINTER_BOUNDS_MODE(N, Y) \
541 make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
543 static void ATTRIBUTE_UNUSED
544 make_pointer_bounds_mode (const char *name,
545 unsigned int bytesize,
546 const char *file, unsigned int line)
548 struct mode_data *m = new_mode (MODE_POINTER_BOUNDS, name, file, line);
549 m->bytesize = bytesize;
553 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
554 #define FRACTIONAL_INT_MODE(N, B, Y) \
555 make_int_mode (#N, B, Y, __FILE__, __LINE__)
557 static void
558 make_int_mode (const char *name,
559 unsigned int precision, unsigned int bytesize,
560 const char *file, unsigned int line)
562 struct mode_data *m = new_mode (MODE_INT, name, file, line);
563 m->bytesize = bytesize;
564 m->precision = precision;
567 #define FRACT_MODE(N, Y, F) \
568 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
570 #define UFRACT_MODE(N, Y, F) \
571 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
573 #define ACCUM_MODE(N, Y, I, F) \
574 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
576 #define UACCUM_MODE(N, Y, I, F) \
577 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
579 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
580 FILE, and LINE. */
582 static void
583 make_fixed_point_mode (enum mode_class cl,
584 const char *name,
585 unsigned int bytesize,
586 unsigned int ibit,
587 unsigned int fbit,
588 const char *file, unsigned int line)
590 struct mode_data *m = new_mode (cl, name, file, line);
591 m->bytesize = bytesize;
592 m->ibit = ibit;
593 m->fbit = fbit;
596 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
597 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
598 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
600 static void
601 make_float_mode (const char *name,
602 unsigned int precision, unsigned int bytesize,
603 const char *format,
604 const char *file, unsigned int line)
606 struct mode_data *m = new_mode (MODE_FLOAT, name, file, line);
607 m->bytesize = bytesize;
608 m->precision = precision;
609 m->format = format;
612 #define DECIMAL_FLOAT_MODE(N, Y, F) \
613 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
614 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
615 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
617 static void
618 make_decimal_float_mode (const char *name,
619 unsigned int precision, unsigned int bytesize,
620 const char *format,
621 const char *file, unsigned int line)
623 struct mode_data *m = new_mode (MODE_DECIMAL_FLOAT, name, file, line);
624 m->bytesize = bytesize;
625 m->precision = precision;
626 m->format = format;
629 #define RESET_FLOAT_FORMAT(N, F) \
630 reset_float_format (#N, #F, __FILE__, __LINE__)
631 static void ATTRIBUTE_UNUSED
632 reset_float_format (const char *name, const char *format,
633 const char *file, unsigned int line)
635 struct mode_data *m = find_mode (name);
636 if (!m)
638 error ("%s:%d: no mode \"%s\"", file, line, name);
639 return;
641 if (m->cl != MODE_FLOAT && m->cl != MODE_DECIMAL_FLOAT)
643 error ("%s:%d: mode \"%s\" is not a FLOAT class", file, line, name);
644 return;
646 m->format = format;
649 /* Partial integer modes are specified by relation to a full integer
650 mode. */
651 #define PARTIAL_INT_MODE(M,PREC,NAME) \
652 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
653 static void ATTRIBUTE_UNUSED
654 make_partial_integer_mode (const char *base, const char *name,
655 unsigned int precision,
656 const char *file, unsigned int line)
658 struct mode_data *m;
659 struct mode_data *component = find_mode (base);
660 if (!component)
662 error ("%s:%d: no mode \"%s\"", file, line, name);
663 return;
665 if (component->cl != MODE_INT)
667 error ("%s:%d: mode \"%s\" is not class INT", file, line, name);
668 return;
671 m = new_mode (MODE_PARTIAL_INT, name, file, line);
672 m->precision = precision;
673 m->component = component;
676 /* A single vector mode can be specified by naming its component
677 mode and the number of components. */
678 #define VECTOR_MODE(C, M, N) \
679 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
680 static void ATTRIBUTE_UNUSED
681 make_vector_mode (enum mode_class bclass,
682 const char *base,
683 unsigned int ncomponents,
684 const char *file, unsigned int line)
686 struct mode_data *v;
687 enum mode_class vclass = vector_class (bclass);
688 struct mode_data *component = find_mode (base);
689 char namebuf[16];
691 if (vclass == MODE_RANDOM)
692 return;
693 if (component == 0)
695 error ("%s:%d: no mode \"%s\"", file, line, base);
696 return;
698 if (component->cl != bclass
699 && (component->cl != MODE_PARTIAL_INT
700 || bclass != MODE_INT))
702 error ("%s:%d: mode \"%s\" is not class %s",
703 file, line, base, mode_class_names[bclass] + 5);
704 return;
707 if ((size_t)snprintf (namebuf, sizeof namebuf, "V%u%s",
708 ncomponents, base) >= sizeof namebuf)
710 error ("%s:%d: mode name \"%s\" is too long",
711 file, line, base);
712 return;
715 v = new_mode (vclass, xstrdup (namebuf), file, line);
716 v->ncomponents = ncomponents;
717 v->component = component;
720 /* Adjustability. */
721 #define _ADD_ADJUST(A, M, X, C1, C2) \
722 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
724 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
725 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
726 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
727 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
728 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
730 static int bits_per_unit;
731 static int max_bitsize_mode_any_int;
733 static void
734 create_modes (void)
736 #include "machmode.def"
738 /* So put the default value unless the target needs a non standard
739 value. */
740 #ifdef BITS_PER_UNIT
741 bits_per_unit = BITS_PER_UNIT;
742 #else
743 bits_per_unit = 8;
744 #endif
746 #ifdef MAX_BITSIZE_MODE_ANY_INT
747 max_bitsize_mode_any_int = MAX_BITSIZE_MODE_ANY_INT;
748 #else
749 max_bitsize_mode_any_int = 0;
750 #endif
753 /* Processing. */
755 /* Sort a list of modes into the order needed for the WIDER field:
756 major sort by precision, minor sort by component precision.
758 For instance:
759 QI < HI < SI < DI < TI
760 V4QI < V2HI < V8QI < V4HI < V2SI.
762 If the precision is not set, sort by the bytesize. A mode with
763 precision set gets sorted before a mode without precision set, if
764 they have the same bytesize; this is the right thing because
765 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
766 We don't have to do anything special to get this done -- an unset
767 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
768 static int
769 cmp_modes (const void *a, const void *b)
771 const struct mode_data *const m = *(const struct mode_data *const*)a;
772 const struct mode_data *const n = *(const struct mode_data *const*)b;
774 if (m->bytesize > n->bytesize)
775 return 1;
776 else if (m->bytesize < n->bytesize)
777 return -1;
779 if (m->precision > n->precision)
780 return 1;
781 else if (m->precision < n->precision)
782 return -1;
784 if (!m->component && !n->component)
786 if (m->counter < n->counter)
787 return -1;
788 else
789 return 1;
792 if (m->component->bytesize > n->component->bytesize)
793 return 1;
794 else if (m->component->bytesize < n->component->bytesize)
795 return -1;
797 if (m->component->precision > n->component->precision)
798 return 1;
799 else if (m->component->precision < n->component->precision)
800 return -1;
802 if (m->counter < n->counter)
803 return -1;
804 else
805 return 1;
808 static void
809 calc_wider_mode (void)
811 int c;
812 struct mode_data *m;
813 struct mode_data **sortbuf;
814 unsigned int max_n_modes = 0;
815 unsigned int i, j;
817 for (c = 0; c < MAX_MODE_CLASS; c++)
818 max_n_modes = MAX (max_n_modes, n_modes[c]);
820 /* Allocate max_n_modes + 1 entries to leave room for the extra null
821 pointer assigned after the qsort call below. */
822 sortbuf = XALLOCAVEC (struct mode_data *, max_n_modes + 1);
824 for (c = 0; c < MAX_MODE_CLASS; c++)
826 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
827 However, we want these in textual order, and we have
828 precisely the reverse. */
829 if (c == MODE_RANDOM || c == MODE_CC)
831 struct mode_data *prev, *next;
833 for (prev = 0, m = modes[c]; m; m = next)
835 m->wider = void_mode;
837 /* this is nreverse */
838 next = m->next;
839 m->next = prev;
840 prev = m;
842 modes[c] = prev;
844 else
846 if (!modes[c])
847 continue;
849 for (i = 0, m = modes[c]; m; i++, m = m->next)
850 sortbuf[i] = m;
852 qsort (sortbuf, i, sizeof (struct mode_data *), cmp_modes);
854 sortbuf[i] = 0;
855 for (j = 0; j < i; j++)
857 sortbuf[j]->next = sortbuf[j + 1];
858 if (c == MODE_PARTIAL_INT)
859 sortbuf[j]->wider = sortbuf[j]->component;
860 else
861 sortbuf[j]->wider = sortbuf[j]->next;
864 modes[c] = sortbuf[0];
869 /* Output routines. */
871 #define tagged_printf(FMT, ARG, TAG) do { \
872 int count_ = printf (" " FMT ",", ARG); \
873 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
874 } while (0)
876 #define print_decl(TYPE, NAME, ASIZE) \
877 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
879 #define print_maybe_const_decl(TYPE, NAME, ASIZE, CATEGORY) \
880 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
881 adj_##CATEGORY ? "" : "const ")
883 #define print_closer() puts ("};")
885 /* Compute the max bitsize of some of the classes of integers. It may
886 be that there are needs for the other integer classes, and this
887 code is easy to extend. */
888 static void
889 emit_max_int (void)
891 unsigned int max, mmax;
892 struct mode_data *i;
893 int j;
895 puts ("");
897 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit);
899 if (max_bitsize_mode_any_int == 0)
901 for (max = 1, i = modes[MODE_INT]; i; i = i->next)
902 if (max < i->bytesize)
903 max = i->bytesize;
904 mmax = max;
905 for (max = 1, i = modes[MODE_PARTIAL_INT]; i; i = i->next)
906 if (max < i->bytesize)
907 max = i->bytesize;
908 if (max > mmax)
909 mmax = max;
910 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax);
912 else
913 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int);
915 mmax = 0;
916 for (j = 0; j < MAX_MODE_CLASS; j++)
917 for (i = modes[j]; i; i = i->next)
918 if (mmax < i->bytesize)
919 mmax = i->bytesize;
920 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax);
923 /* Emit mode_size_inline routine into insn-modes.h header. */
924 static void
925 emit_mode_size_inline (void)
927 int c;
928 struct mode_adjust *a;
929 struct mode_data *m;
931 /* Size adjustments must be propagated to all containing modes. */
932 for (a = adj_bytesize; a; a = a->next)
934 a->mode->need_bytesize_adj = true;
935 for (m = a->mode->contained; m; m = m->next_cont)
936 m->need_bytesize_adj = true;
939 printf ("\
940 #ifdef __cplusplus\n\
941 inline __attribute__((__always_inline__))\n\
942 #else\n\
943 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
944 #endif\n\
945 unsigned char\n\
946 mode_size_inline (enum machine_mode mode)\n\
947 {\n\
948 extern %sunsigned char mode_size[NUM_MACHINE_MODES];\n\
949 switch (mode)\n\
950 {\n", adj_bytesize ? "" : "const ");
952 for_all_modes (c, m)
953 if (!m->need_bytesize_adj)
954 printf (" case %smode: return %u;\n", m->name, m->bytesize);
956 puts ("\
957 default: return mode_size[mode];\n\
958 }\n\
959 }\n");
962 /* Emit mode_nunits_inline routine into insn-modes.h header. */
963 static void
964 emit_mode_nunits_inline (void)
966 int c;
967 struct mode_data *m;
969 puts ("\
970 #ifdef __cplusplus\n\
971 inline __attribute__((__always_inline__))\n\
972 #else\n\
973 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
974 #endif\n\
975 unsigned char\n\
976 mode_nunits_inline (enum machine_mode mode)\n\
977 {\n\
978 extern const unsigned char mode_nunits[NUM_MACHINE_MODES];\n\
979 switch (mode)\n\
980 {");
982 for_all_modes (c, m)
983 printf (" case %smode: return %u;\n", m->name, m->ncomponents);
985 puts ("\
986 default: return mode_nunits[mode];\n\
987 }\n\
988 }\n");
991 /* Emit mode_inner_inline routine into insn-modes.h header. */
992 static void
993 emit_mode_inner_inline (void)
995 int c;
996 struct mode_data *m;
998 puts ("\
999 #ifdef __cplusplus\n\
1000 inline __attribute__((__always_inline__))\n\
1001 #else\n\
1002 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1003 #endif\n\
1004 unsigned char\n\
1005 mode_inner_inline (enum machine_mode mode)\n\
1006 {\n\
1007 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1008 switch (mode)\n\
1009 {");
1011 for_all_modes (c, m)
1012 printf (" case %smode: return %smode;\n", m->name,
1013 c != MODE_PARTIAL_INT && m->component
1014 ? m->component->name : void_mode->name);
1016 puts ("\
1017 default: return mode_inner[mode];\n\
1018 }\n\
1019 }\n");
1022 static void
1023 emit_insn_modes_h (void)
1025 int c;
1026 struct mode_data *m, *first, *last;
1028 printf ("/* Generated automatically from machmode.def%s%s\n",
1029 HAVE_EXTRA_MODES ? " and " : "",
1030 EXTRA_MODES_FILE);
1032 puts ("\
1033 by genmodes. */\n\
1035 #ifndef GCC_INSN_MODES_H\n\
1036 #define GCC_INSN_MODES_H\n\
1038 enum machine_mode\n{");
1040 for (c = 0; c < MAX_MODE_CLASS; c++)
1041 for (m = modes[c]; m; m = m->next)
1043 int count_ = printf (" %smode,", m->name);
1044 printf ("%*s/* %s:%d */\n", 27 - count_, "",
1045 trim_filename (m->file), m->line);
1048 puts (" MAX_MACHINE_MODE,\n");
1050 for (c = 0; c < MAX_MODE_CLASS; c++)
1052 first = modes[c];
1053 last = 0;
1054 for (m = first; m; last = m, m = m->next)
1057 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1058 end will try to use it for bitfields in structures and the
1059 like, which we do not want. Only the target md file should
1060 generate BImode widgets. */
1061 if (first && first->precision == 1 && c == MODE_INT)
1062 first = first->next;
1064 if (first && last)
1065 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
1066 mode_class_names[c], first->name,
1067 mode_class_names[c], last->name);
1068 else
1069 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
1070 mode_class_names[c], void_mode->name,
1071 mode_class_names[c], void_mode->name);
1074 puts ("\
1075 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1076 };\n");
1078 /* I can't think of a better idea, can you? */
1079 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize ? "" : " const");
1080 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment ? "" : " const");
1081 #if 0 /* disabled for backward compatibility, temporary */
1082 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format ? "" :" const");
1083 #endif
1084 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit ? "" : " const");
1085 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit ? "" : " const");
1086 emit_max_int ();
1087 puts ("\n#if GCC_VERSION >= 4001\n");
1088 emit_mode_size_inline ();
1089 emit_mode_nunits_inline ();
1090 emit_mode_inner_inline ();
1091 puts ("#endif /* GCC_VERSION >= 4001 */");
1093 puts ("\
1095 #endif /* insn-modes.h */");
1098 static void
1099 emit_insn_modes_c_header (void)
1101 printf ("/* Generated automatically from machmode.def%s%s\n",
1102 HAVE_EXTRA_MODES ? " and " : "",
1103 EXTRA_MODES_FILE);
1105 puts ("\
1106 by genmodes. */\n\
1108 #include \"config.h\"\n\
1109 #include \"system.h\"\n\
1110 #include \"coretypes.h\"\n\
1111 #include \"tm.h\"\n\
1112 #include \"machmode.h\"\n\
1113 #include \"real.h\"");
1116 static void
1117 emit_min_insn_modes_c_header (void)
1119 printf ("/* Generated automatically from machmode.def%s%s\n",
1120 HAVE_EXTRA_MODES ? " and " : "",
1121 EXTRA_MODES_FILE);
1123 puts ("\
1124 by genmodes. */\n\
1126 #include \"bconfig.h\"\n\
1127 #include \"system.h\"\n\
1128 #include \"machmode.h\"");
1131 static void
1132 emit_mode_name (void)
1134 int c;
1135 struct mode_data *m;
1137 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1139 for_all_modes (c, m)
1140 printf (" \"%s\",\n", m->name);
1142 print_closer ();
1145 static void
1146 emit_mode_class (void)
1148 int c;
1149 struct mode_data *m;
1151 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1153 for_all_modes (c, m)
1154 tagged_printf ("%s", mode_class_names[m->cl], m->name);
1156 print_closer ();
1159 static void
1160 emit_mode_precision (void)
1162 int c;
1163 struct mode_data *m;
1165 print_decl ("unsigned short", "mode_precision", "NUM_MACHINE_MODES");
1167 for_all_modes (c, m)
1168 if (m->precision != (unsigned int)-1)
1169 tagged_printf ("%u", m->precision, m->name);
1170 else
1171 tagged_printf ("%u*BITS_PER_UNIT", m->bytesize, m->name);
1173 print_closer ();
1176 static void
1177 emit_mode_size (void)
1179 int c;
1180 struct mode_data *m;
1182 print_maybe_const_decl ("%sunsigned char", "mode_size",
1183 "NUM_MACHINE_MODES", bytesize);
1185 for_all_modes (c, m)
1186 tagged_printf ("%u", m->bytesize, m->name);
1188 print_closer ();
1191 static void
1192 emit_mode_nunits (void)
1194 int c;
1195 struct mode_data *m;
1197 print_decl ("unsigned char", "mode_nunits", "NUM_MACHINE_MODES");
1199 for_all_modes (c, m)
1200 tagged_printf ("%u", m->ncomponents, m->name);
1202 print_closer ();
1205 static void
1206 emit_mode_wider (void)
1208 int c;
1209 struct mode_data *m;
1211 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1213 for_all_modes (c, m)
1214 tagged_printf ("%smode",
1215 m->wider ? m->wider->name : void_mode->name,
1216 m->name);
1218 print_closer ();
1219 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1221 for_all_modes (c, m)
1223 struct mode_data * m2;
1225 for (m2 = m;
1226 m2 && m2 != void_mode;
1227 m2 = m2->wider)
1229 if (m2->bytesize < 2 * m->bytesize)
1230 continue;
1231 if (m->precision != (unsigned int) -1)
1233 if (m2->precision != 2 * m->precision)
1234 continue;
1236 else
1238 if (m2->precision != (unsigned int) -1)
1239 continue;
1242 /* For vectors we want twice the number of components,
1243 with the same element type. */
1244 if (m->cl == MODE_VECTOR_INT
1245 || m->cl == MODE_VECTOR_FLOAT
1246 || m->cl == MODE_VECTOR_FRACT
1247 || m->cl == MODE_VECTOR_UFRACT
1248 || m->cl == MODE_VECTOR_ACCUM
1249 || m->cl == MODE_VECTOR_UACCUM)
1251 if (m2->ncomponents != 2 * m->ncomponents)
1252 continue;
1253 if (m->component != m2->component)
1254 continue;
1257 break;
1259 if (m2 == void_mode)
1260 m2 = 0;
1261 tagged_printf ("%smode",
1262 m2 ? m2->name : void_mode->name,
1263 m->name);
1266 print_closer ();
1269 static void
1270 emit_mode_mask (void)
1272 int c;
1273 struct mode_data *m;
1275 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1276 "NUM_MACHINE_MODES");
1277 puts ("\
1278 #define MODE_MASK(m) \\\n\
1279 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1280 ? ~(unsigned HOST_WIDE_INT) 0 \\\n\
1281 : ((unsigned HOST_WIDE_INT) 1 << (m)) - 1\n");
1283 for_all_modes (c, m)
1284 if (m->precision != (unsigned int)-1)
1285 tagged_printf ("MODE_MASK (%u)", m->precision, m->name);
1286 else
1287 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m->bytesize, m->name);
1289 puts ("#undef MODE_MASK");
1290 print_closer ();
1293 static void
1294 emit_mode_inner (void)
1296 int c;
1297 struct mode_data *m;
1299 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1301 for_all_modes (c, m)
1302 tagged_printf ("%smode",
1303 c != MODE_PARTIAL_INT && m->component
1304 ? m->component->name : void_mode->name,
1305 m->name);
1307 print_closer ();
1310 static void
1311 emit_mode_base_align (void)
1313 int c;
1314 struct mode_data *m;
1316 print_maybe_const_decl ("%sunsigned char",
1317 "mode_base_align", "NUM_MACHINE_MODES",
1318 alignment);
1320 for_all_modes (c, m)
1321 tagged_printf ("%u", m->alignment, m->name);
1323 print_closer ();
1326 static void
1327 emit_class_narrowest_mode (void)
1329 int c;
1331 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1333 for (c = 0; c < MAX_MODE_CLASS; c++)
1334 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1335 tagged_printf ("MIN_%s", mode_class_names[c],
1336 modes[c]
1337 ? ((c != MODE_INT || modes[c]->precision != 1)
1338 ? modes[c]->name
1339 : (modes[c]->next
1340 ? modes[c]->next->name
1341 : void_mode->name))
1342 : void_mode->name);
1344 print_closer ();
1347 static void
1348 emit_real_format_for_mode (void)
1350 struct mode_data *m;
1352 /* The entities pointed to by this table are constant, whether
1353 or not the table itself is constant.
1355 For backward compatibility this table is always writable
1356 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1357 convert all said targets to use ADJUST_FORMAT instead. */
1358 #if 0
1359 print_maybe_const_decl ("const struct real_format *%s",
1360 "real_format_for_mode",
1361 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1362 format);
1363 #else
1364 print_decl ("struct real_format *\n", "real_format_for_mode",
1365 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1366 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1367 #endif
1369 /* The beginning of the table is entries for float modes. */
1370 for (m = modes[MODE_FLOAT]; m; m = m->next)
1371 if (!strcmp (m->format, "0"))
1372 tagged_printf ("%s", m->format, m->name);
1373 else
1374 tagged_printf ("&%s", m->format, m->name);
1376 /* The end of the table is entries for decimal float modes. */
1377 for (m = modes[MODE_DECIMAL_FLOAT]; m; m = m->next)
1378 if (!strcmp (m->format, "0"))
1379 tagged_printf ("%s", m->format, m->name);
1380 else
1381 tagged_printf ("&%s", m->format, m->name);
1383 print_closer ();
1386 static void
1387 emit_mode_adjustments (void)
1389 struct mode_adjust *a;
1390 struct mode_data *m;
1392 puts ("\
1393 \nvoid\
1394 \ninit_adjust_machine_modes (void)\
1395 \n{\
1396 \n size_t s ATTRIBUTE_UNUSED;");
1398 /* Size adjustments must be propagated to all containing modes.
1399 A size adjustment forces us to recalculate the alignment too. */
1400 for (a = adj_bytesize; a; a = a->next)
1402 printf ("\n /* %s:%d */\n s = %s;\n",
1403 a->file, a->line, a->adjustment);
1404 printf (" mode_size[%smode] = s;\n", a->mode->name);
1405 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1406 a->mode->name);
1408 for (m = a->mode->contained; m; m = m->next_cont)
1410 switch (m->cl)
1412 case MODE_COMPLEX_INT:
1413 case MODE_COMPLEX_FLOAT:
1414 printf (" mode_size[%smode] = 2*s;\n", m->name);
1415 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1416 m->name);
1417 break;
1419 case MODE_VECTOR_INT:
1420 case MODE_VECTOR_FLOAT:
1421 case MODE_VECTOR_FRACT:
1422 case MODE_VECTOR_UFRACT:
1423 case MODE_VECTOR_ACCUM:
1424 case MODE_VECTOR_UACCUM:
1425 printf (" mode_size[%smode] = %d*s;\n",
1426 m->name, m->ncomponents);
1427 printf (" mode_base_align[%smode] = (%d*s) & (~(%d*s)+1);\n",
1428 m->name, m->ncomponents, m->ncomponents);
1429 break;
1431 default:
1432 internal_error (
1433 "mode %s is neither vector nor complex but contains %s",
1434 m->name, a->mode->name);
1435 /* NOTREACHED */
1440 /* Alignment adjustments propagate too.
1441 ??? This may not be the right thing for vector modes. */
1442 for (a = adj_alignment; a; a = a->next)
1444 printf ("\n /* %s:%d */\n s = %s;\n",
1445 a->file, a->line, a->adjustment);
1446 printf (" mode_base_align[%smode] = s;\n", a->mode->name);
1448 for (m = a->mode->contained; m; m = m->next_cont)
1450 switch (m->cl)
1452 case MODE_COMPLEX_INT:
1453 case MODE_COMPLEX_FLOAT:
1454 printf (" mode_base_align[%smode] = s;\n", m->name);
1455 break;
1457 case MODE_VECTOR_INT:
1458 case MODE_VECTOR_FLOAT:
1459 case MODE_VECTOR_FRACT:
1460 case MODE_VECTOR_UFRACT:
1461 case MODE_VECTOR_ACCUM:
1462 case MODE_VECTOR_UACCUM:
1463 printf (" mode_base_align[%smode] = %d*s;\n",
1464 m->name, m->ncomponents);
1465 break;
1467 default:
1468 internal_error (
1469 "mode %s is neither vector nor complex but contains %s",
1470 m->name, a->mode->name);
1471 /* NOTREACHED */
1476 /* Ibit adjustments don't have to propagate. */
1477 for (a = adj_ibit; a; a = a->next)
1479 printf ("\n /* %s:%d */\n s = %s;\n",
1480 a->file, a->line, a->adjustment);
1481 printf (" mode_ibit[%smode] = s;\n", a->mode->name);
1484 /* Fbit adjustments don't have to propagate. */
1485 for (a = adj_fbit; a; a = a->next)
1487 printf ("\n /* %s:%d */\n s = %s;\n",
1488 a->file, a->line, a->adjustment);
1489 printf (" mode_fbit[%smode] = s;\n", a->mode->name);
1492 /* Real mode formats don't have to propagate anywhere. */
1493 for (a = adj_format; a; a = a->next)
1494 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (%smode) = %s;\n",
1495 a->file, a->line, a->mode->name, a->adjustment);
1497 puts ("}");
1500 /* Emit ibit for all modes. */
1502 static void
1503 emit_mode_ibit (void)
1505 int c;
1506 struct mode_data *m;
1508 print_maybe_const_decl ("%sunsigned char",
1509 "mode_ibit", "NUM_MACHINE_MODES",
1510 ibit);
1512 for_all_modes (c, m)
1513 tagged_printf ("%u", m->ibit, m->name);
1515 print_closer ();
1518 /* Emit fbit for all modes. */
1520 static void
1521 emit_mode_fbit (void)
1523 int c;
1524 struct mode_data *m;
1526 print_maybe_const_decl ("%sunsigned char",
1527 "mode_fbit", "NUM_MACHINE_MODES",
1528 fbit);
1530 for_all_modes (c, m)
1531 tagged_printf ("%u", m->fbit, m->name);
1533 print_closer ();
1537 static void
1538 emit_insn_modes_c (void)
1540 emit_insn_modes_c_header ();
1541 emit_mode_name ();
1542 emit_mode_class ();
1543 emit_mode_precision ();
1544 emit_mode_size ();
1545 emit_mode_nunits ();
1546 emit_mode_wider ();
1547 emit_mode_mask ();
1548 emit_mode_inner ();
1549 emit_mode_base_align ();
1550 emit_class_narrowest_mode ();
1551 emit_real_format_for_mode ();
1552 emit_mode_adjustments ();
1553 emit_mode_ibit ();
1554 emit_mode_fbit ();
1557 static void
1558 emit_min_insn_modes_c (void)
1560 emit_min_insn_modes_c_header ();
1561 emit_mode_name ();
1562 emit_mode_class ();
1563 emit_mode_wider ();
1564 emit_class_narrowest_mode ();
1567 /* Master control. */
1569 main (int argc, char **argv)
1571 bool gen_header = false, gen_min = false;
1572 progname = argv[0];
1574 if (argc == 1)
1576 else if (argc == 2 && !strcmp (argv[1], "-h"))
1577 gen_header = true;
1578 else if (argc == 2 && !strcmp (argv[1], "-m"))
1579 gen_min = true;
1580 else
1582 error ("usage: %s [-h|-m] > file", progname);
1583 return FATAL_EXIT_CODE;
1586 modes_by_name = htab_create_alloc (64, hash_mode, eq_mode, 0, xcalloc, free);
1588 create_modes ();
1589 complete_all_modes ();
1591 if (have_error)
1592 return FATAL_EXIT_CODE;
1594 calc_wider_mode ();
1596 if (gen_header)
1597 emit_insn_modes_h ();
1598 else if (gen_min)
1599 emit_min_insn_modes_c ();
1600 else
1601 emit_insn_modes_c ();
1603 if (fflush (stdout) || fclose (stdout))
1604 return FATAL_EXIT_CODE;
1605 return SUCCESS_EXIT_CODE;