* doc/xml/manual/status_cxx2011.xml: Update status.
[official-gcc.git] / gcc / genmodes.c
blob1a32cdefeab9095bf5a639a8215d1cd30f55a40e
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 */
77 unsigned int int_n; /* If nonzero, then __int<INT_N> will be defined */
80 static struct mode_data *modes[MAX_MODE_CLASS];
81 static unsigned int n_modes[MAX_MODE_CLASS];
82 static struct mode_data *void_mode;
84 static const struct mode_data blank_mode = {
85 0, "<unknown>", MAX_MODE_CLASS,
86 -1U, -1U, -1U, -1U,
87 0, 0, 0, 0, 0,
88 "<unknown>", 0, 0, 0, 0, false, 0
91 static htab_t modes_by_name;
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. */
96 struct mode_adjust
98 struct mode_adjust *next;
99 struct mode_data *mode;
100 const char *adjustment;
102 const char *file;
103 unsigned int line;
106 static struct mode_adjust *adj_bytesize;
107 static struct mode_adjust *adj_alignment;
108 static struct mode_adjust *adj_format;
109 static struct mode_adjust *adj_ibit;
110 static struct mode_adjust *adj_fbit;
112 /* Mode class operations. */
113 static enum mode_class
114 complex_class (enum mode_class c)
116 switch (c)
118 case MODE_INT: return MODE_COMPLEX_INT;
119 case MODE_FLOAT: return MODE_COMPLEX_FLOAT;
120 default:
121 error ("no complex class for class %s", mode_class_names[c]);
122 return MODE_RANDOM;
126 static enum mode_class
127 vector_class (enum mode_class cl)
129 switch (cl)
131 case MODE_INT: return MODE_VECTOR_INT;
132 case MODE_FLOAT: return MODE_VECTOR_FLOAT;
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;
137 default:
138 error ("no vector class for class %s", mode_class_names[cl]);
139 return MODE_RANDOM;
143 /* Utility routines. */
144 static inline struct mode_data *
145 find_mode (const char *name)
147 struct mode_data key;
149 key.name = name;
150 return (struct mode_data *) htab_find (modes_by_name, &key);
153 static struct mode_data *
154 new_mode (enum mode_class cl, const char *name,
155 const char *file, unsigned int line)
157 struct mode_data *m;
158 static unsigned int count = 0;
160 m = find_mode (name);
161 if (m)
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;
169 m = XNEW (struct mode_data);
170 memcpy (m, &blank_mode, sizeof (struct mode_data));
171 m->cl = cl;
172 m->name = name;
173 if (file)
174 m->file = trim_filename (file);
175 m->line = line;
176 m->counter = count++;
178 m->next = modes[cl];
179 modes[cl] = m;
180 n_modes[cl]++;
182 *htab_find_slot (modes_by_name, m, INSERT) = m;
184 return m;
187 static hashval_t
188 hash_mode (const void *p)
190 const struct mode_data *m = (const struct mode_data *)p;
191 return htab_hash_string (m->name);
194 static int
195 eq_mode (const void *p, const void *q)
197 const struct mode_data *a = (const struct mode_data *)p;
198 const struct mode_data *b = (const struct mode_data *)q;
200 return !strcmp (a->name, b->name);
203 #define for_all_modes(C, M) \
204 for (C = 0; C < MAX_MODE_CLASS; C++) \
205 for (M = modes[C]; M; M = M->next)
207 static void ATTRIBUTE_UNUSED
208 new_adjust (const char *name,
209 struct mode_adjust **category, const char *catname,
210 const char *adjustment,
211 enum mode_class required_class_from,
212 enum mode_class required_class_to,
213 const char *file, unsigned int line)
215 struct mode_data *mode = find_mode (name);
216 struct mode_adjust *a;
218 file = trim_filename (file);
220 if (!mode)
222 error ("%s:%d: no mode \"%s\"", file, line, name);
223 return;
226 if (required_class_from != MODE_RANDOM
227 && (mode->cl < required_class_from || mode->cl > required_class_to))
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);
232 return;
235 for (a = *category; a; a = a->next)
236 if (a->mode == mode)
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;
244 a = XNEW (struct mode_adjust);
245 a->mode = mode;
246 a->adjustment = adjustment;
247 a->file = file;
248 a->line = line;
250 a->next = *category;
251 *category = a;
254 /* Diagnose failure to meet expectations in a partially filled out
255 mode structure. */
256 enum requirement { SET, UNSET, OPTIONAL };
258 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
259 switch (req) \
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; \
273 } while (0)
275 #define validate_field(M, F) \
276 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
278 static void
279 validate_mode (struct mode_data *m,
280 enum requirement r_precision,
281 enum requirement r_bytesize,
282 enum requirement r_component,
283 enum requirement r_ncomponents,
284 enum requirement r_format)
286 validate_field (m, precision);
287 validate_field (m, bytesize);
288 validate_field (m, component);
289 validate_field (m, ncomponents);
290 validate_field (m, format);
292 #undef validate_field
293 #undef validate_field_
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. */
297 static void
298 complete_mode (struct mode_data *m)
300 unsigned int alignment;
302 if (!m->name)
304 error ("%s:%d: mode with no name", m->file, m->line);
305 return;
307 if (m->cl == MAX_MODE_CLASS)
309 error ("%s:%d: %smode has no mode class", m->file, m->line, m->name);
310 return;
313 switch (m->cl)
315 case MODE_RANDOM:
316 /* Nothing more need be said. */
317 if (!strcmp (m->name, "VOID"))
318 void_mode = m;
320 validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET);
322 m->precision = 0;
323 m->bytesize = 0;
324 m->ncomponents = 0;
325 m->component = 0;
326 break;
328 case MODE_CC:
329 /* Again, nothing more need be said. For historical reasons,
330 the size of a CC mode is four units. */
331 validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET);
333 m->bytesize = 4;
334 m->ncomponents = 1;
335 m->component = 0;
336 break;
338 case MODE_INT:
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 INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
541 #define FRACTIONAL_INT_MODE(N, B, Y) \
542 make_int_mode (#N, B, Y, __FILE__, __LINE__)
544 static void
545 make_int_mode (const char *name,
546 unsigned int precision, unsigned int bytesize,
547 const char *file, unsigned int line)
549 struct mode_data *m = new_mode (MODE_INT, name, file, line);
550 m->bytesize = bytesize;
551 m->precision = precision;
554 #define FRACT_MODE(N, Y, F) \
555 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
557 #define UFRACT_MODE(N, Y, F) \
558 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
560 #define ACCUM_MODE(N, Y, I, F) \
561 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
563 #define UACCUM_MODE(N, Y, I, F) \
564 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
566 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
567 FILE, and LINE. */
569 static void
570 make_fixed_point_mode (enum mode_class cl,
571 const char *name,
572 unsigned int bytesize,
573 unsigned int ibit,
574 unsigned int fbit,
575 const char *file, unsigned int line)
577 struct mode_data *m = new_mode (cl, name, file, line);
578 m->bytesize = bytesize;
579 m->ibit = ibit;
580 m->fbit = fbit;
583 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
584 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
585 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
587 static void
588 make_float_mode (const char *name,
589 unsigned int precision, unsigned int bytesize,
590 const char *format,
591 const char *file, unsigned int line)
593 struct mode_data *m = new_mode (MODE_FLOAT, name, file, line);
594 m->bytesize = bytesize;
595 m->precision = precision;
596 m->format = format;
599 #define DECIMAL_FLOAT_MODE(N, Y, F) \
600 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
601 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
602 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
604 static void
605 make_decimal_float_mode (const char *name,
606 unsigned int precision, unsigned int bytesize,
607 const char *format,
608 const char *file, unsigned int line)
610 struct mode_data *m = new_mode (MODE_DECIMAL_FLOAT, name, file, line);
611 m->bytesize = bytesize;
612 m->precision = precision;
613 m->format = format;
616 #define RESET_FLOAT_FORMAT(N, F) \
617 reset_float_format (#N, #F, __FILE__, __LINE__)
618 static void ATTRIBUTE_UNUSED
619 reset_float_format (const char *name, const char *format,
620 const char *file, unsigned int line)
622 struct mode_data *m = find_mode (name);
623 if (!m)
625 error ("%s:%d: no mode \"%s\"", file, line, name);
626 return;
628 if (m->cl != MODE_FLOAT && m->cl != MODE_DECIMAL_FLOAT)
630 error ("%s:%d: mode \"%s\" is not a FLOAT class", file, line, name);
631 return;
633 m->format = format;
636 /* __intN support. */
637 #define INT_N(M,PREC) \
638 make_int_n (#M, PREC, __FILE__, __LINE__)
639 static void ATTRIBUTE_UNUSED
640 make_int_n (const char *m, int bitsize,
641 const char *file, unsigned int line)
643 struct mode_data *component = find_mode (m);
644 if (!component)
646 error ("%s:%d: no mode \"%s\"", file, line, m);
647 return;
649 if (component->cl != MODE_INT
650 && component->cl != MODE_PARTIAL_INT)
652 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file, line, m);
653 return;
655 if (component->int_n != 0)
657 error ("%s:%d: mode \"%s\" already has an intN", file, line, m);
658 return;
661 component->int_n = bitsize;
664 /* Partial integer modes are specified by relation to a full integer
665 mode. */
666 #define PARTIAL_INT_MODE(M,PREC,NAME) \
667 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
668 static void ATTRIBUTE_UNUSED
669 make_partial_integer_mode (const char *base, const char *name,
670 unsigned int precision,
671 const char *file, unsigned int line)
673 struct mode_data *m;
674 struct mode_data *component = find_mode (base);
675 if (!component)
677 error ("%s:%d: no mode \"%s\"", file, line, name);
678 return;
680 if (component->cl != MODE_INT)
682 error ("%s:%d: mode \"%s\" is not class INT", file, line, name);
683 return;
686 m = new_mode (MODE_PARTIAL_INT, name, file, line);
687 m->precision = precision;
688 m->component = component;
691 /* A single vector mode can be specified by naming its component
692 mode and the number of components. */
693 #define VECTOR_MODE(C, M, N) \
694 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
695 static void ATTRIBUTE_UNUSED
696 make_vector_mode (enum mode_class bclass,
697 const char *base,
698 unsigned int ncomponents,
699 const char *file, unsigned int line)
701 struct mode_data *v;
702 enum mode_class vclass = vector_class (bclass);
703 struct mode_data *component = find_mode (base);
704 char namebuf[16];
706 if (vclass == MODE_RANDOM)
707 return;
708 if (component == 0)
710 error ("%s:%d: no mode \"%s\"", file, line, base);
711 return;
713 if (component->cl != bclass
714 && (component->cl != MODE_PARTIAL_INT
715 || bclass != MODE_INT))
717 error ("%s:%d: mode \"%s\" is not class %s",
718 file, line, base, mode_class_names[bclass] + 5);
719 return;
722 if ((size_t)snprintf (namebuf, sizeof namebuf, "V%u%s",
723 ncomponents, base) >= sizeof namebuf)
725 error ("%s:%d: mode name \"%s\" is too long",
726 file, line, base);
727 return;
730 v = new_mode (vclass, xstrdup (namebuf), file, line);
731 v->ncomponents = ncomponents;
732 v->component = component;
735 /* Adjustability. */
736 #define _ADD_ADJUST(A, M, X, C1, C2) \
737 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
739 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
740 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
741 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
742 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
743 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
745 static int bits_per_unit;
746 static int max_bitsize_mode_any_int;
748 static void
749 create_modes (void)
751 #include "machmode.def"
753 /* So put the default value unless the target needs a non standard
754 value. */
755 #ifdef BITS_PER_UNIT
756 bits_per_unit = BITS_PER_UNIT;
757 #else
758 bits_per_unit = 8;
759 #endif
761 #ifdef MAX_BITSIZE_MODE_ANY_INT
762 max_bitsize_mode_any_int = MAX_BITSIZE_MODE_ANY_INT;
763 #else
764 max_bitsize_mode_any_int = 0;
765 #endif
768 /* Processing. */
770 /* Sort a list of modes into the order needed for the WIDER field:
771 major sort by precision, minor sort by component precision.
773 For instance:
774 QI < HI < SI < DI < TI
775 V4QI < V2HI < V8QI < V4HI < V2SI.
777 If the precision is not set, sort by the bytesize. A mode with
778 precision set gets sorted before a mode without precision set, if
779 they have the same bytesize; this is the right thing because
780 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
781 We don't have to do anything special to get this done -- an unset
782 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
783 static int
784 cmp_modes (const void *a, const void *b)
786 const struct mode_data *const m = *(const struct mode_data *const*)a;
787 const struct mode_data *const n = *(const struct mode_data *const*)b;
789 if (m->bytesize > n->bytesize)
790 return 1;
791 else if (m->bytesize < n->bytesize)
792 return -1;
794 if (m->precision > n->precision)
795 return 1;
796 else if (m->precision < n->precision)
797 return -1;
799 if (!m->component && !n->component)
801 if (m->counter < n->counter)
802 return -1;
803 else
804 return 1;
807 if (m->component->bytesize > n->component->bytesize)
808 return 1;
809 else if (m->component->bytesize < n->component->bytesize)
810 return -1;
812 if (m->component->precision > n->component->precision)
813 return 1;
814 else if (m->component->precision < n->component->precision)
815 return -1;
817 if (m->counter < n->counter)
818 return -1;
819 else
820 return 1;
823 static void
824 calc_wider_mode (void)
826 int c;
827 struct mode_data *m;
828 struct mode_data **sortbuf;
829 unsigned int max_n_modes = 0;
830 unsigned int i, j;
832 for (c = 0; c < MAX_MODE_CLASS; c++)
833 max_n_modes = MAX (max_n_modes, n_modes[c]);
835 /* Allocate max_n_modes + 1 entries to leave room for the extra null
836 pointer assigned after the qsort call below. */
837 sortbuf = XALLOCAVEC (struct mode_data *, max_n_modes + 1);
839 for (c = 0; c < MAX_MODE_CLASS; c++)
841 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
842 However, we want these in textual order, and we have
843 precisely the reverse. */
844 if (c == MODE_RANDOM || c == MODE_CC)
846 struct mode_data *prev, *next;
848 for (prev = 0, m = modes[c]; m; m = next)
850 m->wider = void_mode;
852 /* this is nreverse */
853 next = m->next;
854 m->next = prev;
855 prev = m;
857 modes[c] = prev;
859 else
861 if (!modes[c])
862 continue;
864 for (i = 0, m = modes[c]; m; i++, m = m->next)
865 sortbuf[i] = m;
867 qsort (sortbuf, i, sizeof (struct mode_data *), cmp_modes);
869 sortbuf[i] = 0;
870 for (j = 0; j < i; j++)
872 sortbuf[j]->next = sortbuf[j + 1];
873 if (c == MODE_PARTIAL_INT)
874 sortbuf[j]->wider = sortbuf[j]->component;
875 else
876 sortbuf[j]->wider = sortbuf[j]->next;
879 modes[c] = sortbuf[0];
884 /* Output routines. */
886 #define tagged_printf(FMT, ARG, TAG) do { \
887 int count_ = printf (" " FMT ",", ARG); \
888 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
889 } while (0)
891 #define print_decl(TYPE, NAME, ASIZE) \
892 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
894 #define print_maybe_const_decl(TYPE, NAME, ASIZE, CATEGORY) \
895 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
896 adj_##CATEGORY ? "" : "const ")
898 #define print_closer() puts ("};")
900 /* Compute the max bitsize of some of the classes of integers. It may
901 be that there are needs for the other integer classes, and this
902 code is easy to extend. */
903 static void
904 emit_max_int (void)
906 unsigned int max, mmax;
907 struct mode_data *i;
908 int j;
910 puts ("");
912 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit);
914 if (max_bitsize_mode_any_int == 0)
916 for (max = 1, i = modes[MODE_INT]; i; i = i->next)
917 if (max < i->bytesize)
918 max = i->bytesize;
919 mmax = max;
920 for (max = 1, i = modes[MODE_PARTIAL_INT]; i; i = i->next)
921 if (max < i->bytesize)
922 max = i->bytesize;
923 if (max > mmax)
924 mmax = max;
925 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax);
927 else
928 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int);
930 mmax = 0;
931 for (j = 0; j < MAX_MODE_CLASS; j++)
932 for (i = modes[j]; i; i = i->next)
933 if (mmax < i->bytesize)
934 mmax = i->bytesize;
935 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax);
938 /* Emit mode_size_inline routine into insn-modes.h header. */
939 static void
940 emit_mode_size_inline (void)
942 int c;
943 struct mode_adjust *a;
944 struct mode_data *m;
946 /* Size adjustments must be propagated to all containing modes. */
947 for (a = adj_bytesize; a; a = a->next)
949 a->mode->need_bytesize_adj = true;
950 for (m = a->mode->contained; m; m = m->next_cont)
951 m->need_bytesize_adj = true;
954 printf ("\
955 #ifdef __cplusplus\n\
956 inline __attribute__((__always_inline__))\n\
957 #else\n\
958 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
959 #endif\n\
960 unsigned char\n\
961 mode_size_inline (enum machine_mode mode)\n\
962 {\n\
963 extern %sunsigned char mode_size[NUM_MACHINE_MODES];\n\
964 switch (mode)\n\
965 {\n", adj_bytesize ? "" : "const ");
967 for_all_modes (c, m)
968 if (!m->need_bytesize_adj)
969 printf (" case %smode: return %u;\n", m->name, m->bytesize);
971 puts ("\
972 default: return mode_size[mode];\n\
973 }\n\
974 }\n");
977 /* Emit mode_nunits_inline routine into insn-modes.h header. */
978 static void
979 emit_mode_nunits_inline (void)
981 int c;
982 struct mode_data *m;
984 puts ("\
985 #ifdef __cplusplus\n\
986 inline __attribute__((__always_inline__))\n\
987 #else\n\
988 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
989 #endif\n\
990 unsigned char\n\
991 mode_nunits_inline (enum machine_mode mode)\n\
992 {\n\
993 extern const unsigned char mode_nunits[NUM_MACHINE_MODES];\n\
994 switch (mode)\n\
995 {");
997 for_all_modes (c, m)
998 printf (" case %smode: return %u;\n", m->name, m->ncomponents);
1000 puts ("\
1001 default: return mode_nunits[mode];\n\
1002 }\n\
1003 }\n");
1006 /* Emit mode_inner_inline routine into insn-modes.h header. */
1007 static void
1008 emit_mode_inner_inline (void)
1010 int c;
1011 struct mode_data *m;
1013 puts ("\
1014 #ifdef __cplusplus\n\
1015 inline __attribute__((__always_inline__))\n\
1016 #else\n\
1017 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1018 #endif\n\
1019 unsigned char\n\
1020 mode_inner_inline (enum machine_mode mode)\n\
1021 {\n\
1022 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1023 switch (mode)\n\
1024 {");
1026 for_all_modes (c, m)
1027 printf (" case %smode: return %smode;\n", m->name,
1028 c != MODE_PARTIAL_INT && m->component
1029 ? m->component->name : void_mode->name);
1031 puts ("\
1032 default: return mode_inner[mode];\n\
1033 }\n\
1034 }\n");
1037 static void
1038 emit_insn_modes_h (void)
1040 int c;
1041 struct mode_data *m, *first, *last;
1042 int n_int_n_ents = 0;
1044 printf ("/* Generated automatically from machmode.def%s%s\n",
1045 HAVE_EXTRA_MODES ? " and " : "",
1046 EXTRA_MODES_FILE);
1048 puts ("\
1049 by genmodes. */\n\
1051 #ifndef GCC_INSN_MODES_H\n\
1052 #define GCC_INSN_MODES_H\n\
1054 enum machine_mode\n{");
1056 for (c = 0; c < MAX_MODE_CLASS; c++)
1057 for (m = modes[c]; m; m = m->next)
1059 int count_ = printf (" %smode,", m->name);
1060 printf ("%*s/* %s:%d */\n", 27 - count_, "",
1061 trim_filename (m->file), m->line);
1062 printf ("#define HAVE_%smode\n", m->name);
1065 puts (" MAX_MACHINE_MODE,\n");
1067 for (c = 0; c < MAX_MODE_CLASS; c++)
1069 first = modes[c];
1070 last = 0;
1071 for (m = first; m; last = m, m = m->next)
1074 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1075 end will try to use it for bitfields in structures and the
1076 like, which we do not want. Only the target md file should
1077 generate BImode widgets. */
1078 if (first && first->precision == 1 && c == MODE_INT)
1079 first = first->next;
1081 if (first && last)
1082 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
1083 mode_class_names[c], first->name,
1084 mode_class_names[c], last->name);
1085 else
1086 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
1087 mode_class_names[c], void_mode->name,
1088 mode_class_names[c], void_mode->name);
1091 puts ("\
1092 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1093 };\n");
1095 /* I can't think of a better idea, can you? */
1096 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize ? "" : " const");
1097 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment ? "" : " const");
1098 #if 0 /* disabled for backward compatibility, temporary */
1099 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format ? "" :" const");
1100 #endif
1101 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit ? "" : " const");
1102 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit ? "" : " const");
1103 emit_max_int ();
1105 for_all_modes (c, m)
1106 if (m->int_n)
1107 n_int_n_ents ++;
1109 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents);
1111 puts ("\n#if GCC_VERSION >= 4001\n");
1112 emit_mode_size_inline ();
1113 emit_mode_nunits_inline ();
1114 emit_mode_inner_inline ();
1115 puts ("#endif /* GCC_VERSION >= 4001 */");
1117 puts ("\
1119 #endif /* insn-modes.h */");
1122 static void
1123 emit_insn_modes_c_header (void)
1125 printf ("/* Generated automatically from machmode.def%s%s\n",
1126 HAVE_EXTRA_MODES ? " and " : "",
1127 EXTRA_MODES_FILE);
1129 puts ("\
1130 by genmodes. */\n\
1132 #include \"config.h\"\n\
1133 #include \"system.h\"\n\
1134 #include \"coretypes.h\"\n\
1135 #include \"tm.h\"\n\
1136 #include \"machmode.h\"\n\
1137 #include \"real.h\"");
1140 static void
1141 emit_min_insn_modes_c_header (void)
1143 printf ("/* Generated automatically from machmode.def%s%s\n",
1144 HAVE_EXTRA_MODES ? " and " : "",
1145 EXTRA_MODES_FILE);
1147 puts ("\
1148 by genmodes. */\n\
1150 #include \"bconfig.h\"\n\
1151 #include \"system.h\"\n\
1152 #include \"machmode.h\"");
1155 static void
1156 emit_mode_name (void)
1158 int c;
1159 struct mode_data *m;
1161 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1163 for_all_modes (c, m)
1164 printf (" \"%s\",\n", m->name);
1166 print_closer ();
1169 static void
1170 emit_mode_class (void)
1172 int c;
1173 struct mode_data *m;
1175 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1177 for_all_modes (c, m)
1178 tagged_printf ("%s", mode_class_names[m->cl], m->name);
1180 print_closer ();
1183 static void
1184 emit_mode_precision (void)
1186 int c;
1187 struct mode_data *m;
1189 print_decl ("unsigned short", "mode_precision", "NUM_MACHINE_MODES");
1191 for_all_modes (c, m)
1192 if (m->precision != (unsigned int)-1)
1193 tagged_printf ("%u", m->precision, m->name);
1194 else
1195 tagged_printf ("%u*BITS_PER_UNIT", m->bytesize, m->name);
1197 print_closer ();
1200 static void
1201 emit_mode_size (void)
1203 int c;
1204 struct mode_data *m;
1206 print_maybe_const_decl ("%sunsigned char", "mode_size",
1207 "NUM_MACHINE_MODES", bytesize);
1209 for_all_modes (c, m)
1210 tagged_printf ("%u", m->bytesize, m->name);
1212 print_closer ();
1215 static void
1216 emit_mode_nunits (void)
1218 int c;
1219 struct mode_data *m;
1221 print_decl ("unsigned char", "mode_nunits", "NUM_MACHINE_MODES");
1223 for_all_modes (c, m)
1224 tagged_printf ("%u", m->ncomponents, m->name);
1226 print_closer ();
1229 static void
1230 emit_mode_wider (void)
1232 int c;
1233 struct mode_data *m;
1235 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1237 for_all_modes (c, m)
1238 tagged_printf ("%smode",
1239 m->wider ? m->wider->name : void_mode->name,
1240 m->name);
1242 print_closer ();
1243 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1245 for_all_modes (c, m)
1247 struct mode_data * m2;
1249 for (m2 = m;
1250 m2 && m2 != void_mode;
1251 m2 = m2->wider)
1253 if (m2->bytesize < 2 * m->bytesize)
1254 continue;
1255 if (m->precision != (unsigned int) -1)
1257 if (m2->precision != 2 * m->precision)
1258 continue;
1260 else
1262 if (m2->precision != (unsigned int) -1)
1263 continue;
1266 /* For vectors we want twice the number of components,
1267 with the same element type. */
1268 if (m->cl == MODE_VECTOR_INT
1269 || m->cl == MODE_VECTOR_FLOAT
1270 || m->cl == MODE_VECTOR_FRACT
1271 || m->cl == MODE_VECTOR_UFRACT
1272 || m->cl == MODE_VECTOR_ACCUM
1273 || m->cl == MODE_VECTOR_UACCUM)
1275 if (m2->ncomponents != 2 * m->ncomponents)
1276 continue;
1277 if (m->component != m2->component)
1278 continue;
1281 break;
1283 if (m2 == void_mode)
1284 m2 = 0;
1285 tagged_printf ("%smode",
1286 m2 ? m2->name : void_mode->name,
1287 m->name);
1290 print_closer ();
1293 static void
1294 emit_mode_mask (void)
1296 int c;
1297 struct mode_data *m;
1299 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1300 "NUM_MACHINE_MODES");
1301 puts ("\
1302 #define MODE_MASK(m) \\\n\
1303 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1304 ? ~(unsigned HOST_WIDE_INT) 0 \\\n\
1305 : ((unsigned HOST_WIDE_INT) 1 << (m)) - 1\n");
1307 for_all_modes (c, m)
1308 if (m->precision != (unsigned int)-1)
1309 tagged_printf ("MODE_MASK (%u)", m->precision, m->name);
1310 else
1311 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m->bytesize, m->name);
1313 puts ("#undef MODE_MASK");
1314 print_closer ();
1317 static void
1318 emit_mode_inner (void)
1320 int c;
1321 struct mode_data *m;
1323 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1325 for_all_modes (c, m)
1326 tagged_printf ("%smode",
1327 c != MODE_PARTIAL_INT && m->component
1328 ? m->component->name : void_mode->name,
1329 m->name);
1331 print_closer ();
1334 static void
1335 emit_mode_base_align (void)
1337 int c;
1338 struct mode_data *m;
1340 print_maybe_const_decl ("%sunsigned char",
1341 "mode_base_align", "NUM_MACHINE_MODES",
1342 alignment);
1344 for_all_modes (c, m)
1345 tagged_printf ("%u", m->alignment, m->name);
1347 print_closer ();
1350 static void
1351 emit_class_narrowest_mode (void)
1353 int c;
1355 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1357 for (c = 0; c < MAX_MODE_CLASS; c++)
1358 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1359 tagged_printf ("MIN_%s", mode_class_names[c],
1360 modes[c]
1361 ? ((c != MODE_INT || modes[c]->precision != 1)
1362 ? modes[c]->name
1363 : (modes[c]->next
1364 ? modes[c]->next->name
1365 : void_mode->name))
1366 : void_mode->name);
1368 print_closer ();
1371 static void
1372 emit_real_format_for_mode (void)
1374 struct mode_data *m;
1376 /* The entities pointed to by this table are constant, whether
1377 or not the table itself is constant.
1379 For backward compatibility this table is always writable
1380 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1381 convert all said targets to use ADJUST_FORMAT instead. */
1382 #if 0
1383 print_maybe_const_decl ("const struct real_format *%s",
1384 "real_format_for_mode",
1385 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1386 format);
1387 #else
1388 print_decl ("struct real_format *\n", "real_format_for_mode",
1389 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1390 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1391 #endif
1393 /* The beginning of the table is entries for float modes. */
1394 for (m = modes[MODE_FLOAT]; m; m = m->next)
1395 if (!strcmp (m->format, "0"))
1396 tagged_printf ("%s", m->format, m->name);
1397 else
1398 tagged_printf ("&%s", m->format, m->name);
1400 /* The end of the table is entries for decimal float modes. */
1401 for (m = modes[MODE_DECIMAL_FLOAT]; m; m = m->next)
1402 if (!strcmp (m->format, "0"))
1403 tagged_printf ("%s", m->format, m->name);
1404 else
1405 tagged_printf ("&%s", m->format, m->name);
1407 print_closer ();
1410 static void
1411 emit_mode_adjustments (void)
1413 struct mode_adjust *a;
1414 struct mode_data *m;
1416 puts ("\
1417 \nvoid\
1418 \ninit_adjust_machine_modes (void)\
1419 \n{\
1420 \n size_t s ATTRIBUTE_UNUSED;");
1422 /* Size adjustments must be propagated to all containing modes.
1423 A size adjustment forces us to recalculate the alignment too. */
1424 for (a = adj_bytesize; a; a = a->next)
1426 printf ("\n /* %s:%d */\n s = %s;\n",
1427 a->file, a->line, a->adjustment);
1428 printf (" mode_size[%smode] = s;\n", a->mode->name);
1429 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1430 a->mode->name);
1432 for (m = a->mode->contained; m; m = m->next_cont)
1434 switch (m->cl)
1436 case MODE_COMPLEX_INT:
1437 case MODE_COMPLEX_FLOAT:
1438 printf (" mode_size[%smode] = 2*s;\n", m->name);
1439 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1440 m->name);
1441 break;
1443 case MODE_VECTOR_INT:
1444 case MODE_VECTOR_FLOAT:
1445 case MODE_VECTOR_FRACT:
1446 case MODE_VECTOR_UFRACT:
1447 case MODE_VECTOR_ACCUM:
1448 case MODE_VECTOR_UACCUM:
1449 printf (" mode_size[%smode] = %d*s;\n",
1450 m->name, m->ncomponents);
1451 printf (" mode_base_align[%smode] = (%d*s) & (~(%d*s)+1);\n",
1452 m->name, m->ncomponents, m->ncomponents);
1453 break;
1455 default:
1456 internal_error (
1457 "mode %s is neither vector nor complex but contains %s",
1458 m->name, a->mode->name);
1459 /* NOTREACHED */
1464 /* Alignment adjustments propagate too.
1465 ??? This may not be the right thing for vector modes. */
1466 for (a = adj_alignment; a; a = a->next)
1468 printf ("\n /* %s:%d */\n s = %s;\n",
1469 a->file, a->line, a->adjustment);
1470 printf (" mode_base_align[%smode] = s;\n", a->mode->name);
1472 for (m = a->mode->contained; m; m = m->next_cont)
1474 switch (m->cl)
1476 case MODE_COMPLEX_INT:
1477 case MODE_COMPLEX_FLOAT:
1478 printf (" mode_base_align[%smode] = s;\n", m->name);
1479 break;
1481 case MODE_VECTOR_INT:
1482 case MODE_VECTOR_FLOAT:
1483 case MODE_VECTOR_FRACT:
1484 case MODE_VECTOR_UFRACT:
1485 case MODE_VECTOR_ACCUM:
1486 case MODE_VECTOR_UACCUM:
1487 printf (" mode_base_align[%smode] = %d*s;\n",
1488 m->name, m->ncomponents);
1489 break;
1491 default:
1492 internal_error (
1493 "mode %s is neither vector nor complex but contains %s",
1494 m->name, a->mode->name);
1495 /* NOTREACHED */
1500 /* Ibit adjustments don't have to propagate. */
1501 for (a = adj_ibit; a; a = a->next)
1503 printf ("\n /* %s:%d */\n s = %s;\n",
1504 a->file, a->line, a->adjustment);
1505 printf (" mode_ibit[%smode] = s;\n", a->mode->name);
1508 /* Fbit adjustments don't have to propagate. */
1509 for (a = adj_fbit; a; a = a->next)
1511 printf ("\n /* %s:%d */\n s = %s;\n",
1512 a->file, a->line, a->adjustment);
1513 printf (" mode_fbit[%smode] = s;\n", a->mode->name);
1516 /* Real mode formats don't have to propagate anywhere. */
1517 for (a = adj_format; a; a = a->next)
1518 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (%smode) = %s;\n",
1519 a->file, a->line, a->mode->name, a->adjustment);
1521 puts ("}");
1524 /* Emit ibit for all modes. */
1526 static void
1527 emit_mode_ibit (void)
1529 int c;
1530 struct mode_data *m;
1532 print_maybe_const_decl ("%sunsigned char",
1533 "mode_ibit", "NUM_MACHINE_MODES",
1534 ibit);
1536 for_all_modes (c, m)
1537 tagged_printf ("%u", m->ibit, m->name);
1539 print_closer ();
1542 /* Emit fbit for all modes. */
1544 static void
1545 emit_mode_fbit (void)
1547 int c;
1548 struct mode_data *m;
1550 print_maybe_const_decl ("%sunsigned char",
1551 "mode_fbit", "NUM_MACHINE_MODES",
1552 fbit);
1554 for_all_modes (c, m)
1555 tagged_printf ("%u", m->fbit, m->name);
1557 print_closer ();
1560 /* Emit __intN for all modes. */
1562 static void
1563 emit_mode_int_n (void)
1565 int c;
1566 struct mode_data *m;
1567 struct mode_data **mode_sort;
1568 int n_modes = 0;
1569 int i, j;
1571 print_decl ("int_n_data_t", "int_n_data", "");
1573 n_modes = 0;
1574 for_all_modes (c, m)
1575 if (m->int_n)
1576 n_modes ++;
1577 mode_sort = XALLOCAVEC (struct mode_data *, n_modes);
1579 n_modes = 0;
1580 for_all_modes (c, m)
1581 if (m->int_n)
1582 mode_sort[n_modes++] = m;
1584 /* Yes, this is a bubblesort, but there are at most four (and
1585 usually only 1-2) entries to sort. */
1586 for (i = 0; i<n_modes - 1; i++)
1587 for (j = i + 1; j < n_modes; j++)
1588 if (mode_sort[i]->int_n > mode_sort[j]->int_n)
1590 m = mode_sort[i];
1591 mode_sort[i] = mode_sort[j];
1592 mode_sort[j] = m;
1595 for (i = 0; i < n_modes; i ++)
1597 m = mode_sort[i];
1598 printf(" {\n");
1599 tagged_printf ("%u", m->int_n, m->name);
1600 printf ("%smode,", m->name);
1601 printf(" },\n");
1604 print_closer ();
1608 static void
1609 emit_insn_modes_c (void)
1611 emit_insn_modes_c_header ();
1612 emit_mode_name ();
1613 emit_mode_class ();
1614 emit_mode_precision ();
1615 emit_mode_size ();
1616 emit_mode_nunits ();
1617 emit_mode_wider ();
1618 emit_mode_mask ();
1619 emit_mode_inner ();
1620 emit_mode_base_align ();
1621 emit_class_narrowest_mode ();
1622 emit_real_format_for_mode ();
1623 emit_mode_adjustments ();
1624 emit_mode_ibit ();
1625 emit_mode_fbit ();
1626 emit_mode_int_n ();
1629 static void
1630 emit_min_insn_modes_c (void)
1632 emit_min_insn_modes_c_header ();
1633 emit_mode_name ();
1634 emit_mode_class ();
1635 emit_mode_wider ();
1636 emit_class_narrowest_mode ();
1639 /* Master control. */
1641 main (int argc, char **argv)
1643 bool gen_header = false, gen_min = false;
1644 progname = argv[0];
1646 if (argc == 1)
1648 else if (argc == 2 && !strcmp (argv[1], "-h"))
1649 gen_header = true;
1650 else if (argc == 2 && !strcmp (argv[1], "-m"))
1651 gen_min = true;
1652 else
1654 error ("usage: %s [-h|-m] > file", progname);
1655 return FATAL_EXIT_CODE;
1658 modes_by_name = htab_create_alloc (64, hash_mode, eq_mode, 0, xcalloc, free);
1660 create_modes ();
1661 complete_all_modes ();
1663 if (have_error)
1664 return FATAL_EXIT_CODE;
1666 calc_wider_mode ();
1668 if (gen_header)
1669 emit_insn_modes_h ();
1670 else if (gen_min)
1671 emit_min_insn_modes_c ();
1672 else
1673 emit_insn_modes_c ();
1675 if (fflush (stdout) || fclose (stdout))
1676 return FATAL_EXIT_CODE;
1677 return SUCCESS_EXIT_CODE;