2 Copyright (C) 1987, 1988, 1991, 1994, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 /* Disable rtl checking; it conflicts with the iterator handling. */
25 #undef ENABLE_RTL_CHECKING
28 #include "coretypes.h"
34 #include "gensupport.h"
36 /* One element in a singly-linked list of (integer, string) pairs. */
38 struct map_value *next;
43 /* Maps an iterator or attribute name to a list of (integer, string) pairs.
44 The integers are mode or code values; the strings are either C conditions
45 or attribute values. */
47 /* The name of the iterator or attribute. */
50 /* The group (modes or codes) to which the iterator or attribute belongs. */
51 struct iterator_group *group;
53 /* Gives a unique number to the attribute or iterator. Numbers are
54 allocated consecutively, starting at 0. */
57 /* The list of (integer, string) pairs. */
58 struct map_value *values;
61 /* A structure for abstracting the common parts of code and mode iterators. */
62 struct iterator_group {
63 /* Tables of "mapping" structures, one for attributes and one for iterators. */
64 htab_t attrs, iterators;
66 /* The number of "real" modes or codes (and by extension, the first
67 number available for use as an iterator placeholder). */
70 /* Treat the given string as the name of a standard mode or code and
71 return its integer value. */
72 int (*find_builtin) (const char *);
74 /* Return true if the given rtx uses the given mode or code. */
75 bool (*uses_iterator_p) (rtx, int);
77 /* Make the given rtx use the given mode or code. */
78 void (*apply_iterator) (rtx, int);
81 /* A structure used to pass data from read_rtx to apply_iterator_traverse
83 struct iterator_traverse_data {
84 /* Instruction queue. */
86 /* Attributes seen for modes. */
87 struct map_value *mode_maps;
88 /* The last unknown attribute used as a mode. */
89 const char *unknown_mode_attr;
92 /* If CODE is the number of a code iterator, return a real rtx code that
93 has the same format. Return CODE otherwise. */
94 #define BELLWETHER_CODE(CODE) \
95 ((CODE) < NUM_RTX_CODE ? CODE : bellwether_codes[CODE - NUM_RTX_CODE])
97 static int find_mode (const char *);
98 static bool uses_mode_iterator_p (rtx, int);
99 static void apply_mode_iterator (rtx, int);
100 static int find_code (const char *);
101 static bool uses_code_iterator_p (rtx, int);
102 static void apply_code_iterator (rtx, int);
103 static const char *apply_iterator_to_string (const char *, struct mapping *, int);
104 static rtx apply_iterator_to_rtx (rtx, struct mapping *, int,
105 struct map_value *, const char **);
106 static bool uses_iterator_p (rtx, struct mapping *);
107 static const char *add_condition_to_string (const char *, const char *);
108 static void add_condition_to_rtx (rtx, const char *);
109 static int apply_iterator_traverse (void **, void *);
110 static struct mapping *add_mapping (struct iterator_group *, htab_t t,
112 static struct map_value **add_map_value (struct map_value **,
114 static void initialize_iterators (void);
115 static void read_conditions (void);
116 static void validate_const_int (const char *);
117 static int find_iterator (struct iterator_group *, const char *);
118 static struct mapping *read_mapping (struct iterator_group *, htab_t);
119 static void check_code_iterator (struct mapping *);
120 static rtx read_rtx_1 (struct map_value **);
121 static rtx read_rtx_variadic (struct map_value **, rtx);
123 /* The mode and code iterator structures. */
124 static struct iterator_group modes, codes;
126 /* Index I is the value of BELLWETHER_CODE (I + NUM_RTX_CODE). */
127 static enum rtx_code *bellwether_codes;
129 /* Implementations of the iterator_group callbacks for modes. */
132 find_mode (const char *name)
136 for (i = 0; i < NUM_MACHINE_MODES; i++)
137 if (strcmp (GET_MODE_NAME (i), name) == 0)
140 fatal_with_file_and_line ("unknown mode `%s'", name);
144 uses_mode_iterator_p (rtx x, int mode)
146 return (int) GET_MODE (x) == mode;
150 apply_mode_iterator (rtx x, int mode)
152 PUT_MODE (x, (enum machine_mode) mode);
155 /* Implementations of the iterator_group callbacks for codes. */
158 find_code (const char *name)
162 for (i = 0; i < NUM_RTX_CODE; i++)
163 if (strcmp (GET_RTX_NAME (i), name) == 0)
166 fatal_with_file_and_line ("unknown rtx code `%s'", name);
170 uses_code_iterator_p (rtx x, int code)
172 return (int) GET_CODE (x) == code;
176 apply_code_iterator (rtx x, int code)
178 PUT_CODE (x, (enum rtx_code) code);
181 /* Map a code or mode attribute string P to the underlying string for
182 ITERATOR and VALUE. */
184 static struct map_value *
185 map_attr_string (const char *p, struct mapping *iterator, int value)
191 /* If there's a "iterator:" prefix, check whether the iterator name matches.
192 Set ATTR to the start of the attribute name. */
193 attr = strchr (p, ':');
198 if (strncmp (p, iterator->name, attr - p) != 0
199 || iterator->name[attr - p] != 0)
204 /* Find the attribute specification. */
205 m = (struct mapping *) htab_find (iterator->group->attrs, &attr);
209 /* Find the attribute value for VALUE. */
210 for (v = m->values; v != 0; v = v->next)
211 if (v->number == value)
217 /* Given an attribute string used as a machine mode, return an index
218 to store in the machine mode to be translated by
219 apply_iterator_to_rtx. */
222 mode_attr_index (struct map_value **mode_maps, const char *string)
225 struct map_value *mv;
227 /* Copy the attribute string into permanent storage, without the
228 angle brackets around it. */
229 obstack_grow0 (&string_obstack, string + 1, strlen (string) - 2);
230 p = XOBFINISH (&string_obstack, char *);
232 mv = XNEW (struct map_value);
233 mv->number = *mode_maps == 0 ? 0 : (*mode_maps)->number + 1;
235 mv->next = *mode_maps;
238 /* We return a code which we can map back into this string: the
239 number of machine modes + the number of mode iterators + the index
241 return MAX_MACHINE_MODE + htab_elements (modes.iterators) + mv->number;
244 /* Apply MODE_MAPS to the top level of X, expanding cases where an
245 attribute is used for a mode. ITERATOR is the current iterator we are
246 expanding, and VALUE is the value to which we are expanding it.
247 This sets *UNKNOWN to true if we find a mode attribute which has not
248 yet been defined, and does not change it otherwise. */
251 apply_mode_maps (rtx x, struct map_value *mode_maps, struct mapping *iterator,
252 int value, const char **unknown)
256 struct map_value *pm;
258 offset = MAX_MACHINE_MODE + htab_elements (modes.iterators);
259 if (GET_MODE (x) < offset)
262 indx = GET_MODE (x) - offset;
263 for (pm = mode_maps; pm; pm = pm->next)
265 if (pm->number == indx)
269 v = map_attr_string (pm->string, iterator, value);
271 PUT_MODE (x, (enum machine_mode) find_mode (v->string));
273 *unknown = pm->string;
279 /* Given that ITERATOR is being expanded as VALUE, apply the appropriate
280 string substitutions to STRING. Return the new string if any changes
281 were needed, otherwise return STRING itself. */
284 apply_iterator_to_string (const char *string, struct mapping *iterator, int value)
286 char *base, *copy, *p, *start, *end;
292 base = p = copy = ASTRDUP (string);
293 while ((start = strchr (p, '<')) && (end = strchr (start, '>')))
298 v = map_attr_string (p, iterator, value);
303 /* Add everything between the last copied byte and the '<',
304 then add in the attribute value. */
305 obstack_grow (&string_obstack, base, start - base);
306 obstack_grow (&string_obstack, v->string, strlen (v->string));
311 obstack_grow (&string_obstack, base, strlen (base) + 1);
312 copy = XOBFINISH (&string_obstack, char *);
313 copy_md_ptr_loc (copy, string);
319 /* Return a copy of ORIGINAL in which all uses of ITERATOR have been
320 replaced by VALUE. MODE_MAPS holds information about attribute
321 strings used for modes. This sets *UNKNOWN_MODE_ATTR to the value of
322 an unknown mode attribute, and does not change it otherwise. */
325 apply_iterator_to_rtx (rtx original, struct mapping *iterator, int value,
326 struct map_value *mode_maps,
327 const char **unknown_mode_attr)
329 struct iterator_group *group;
330 const char *format_ptr;
333 enum rtx_code bellwether_code;
338 /* Create a shallow copy of ORIGINAL. */
339 bellwether_code = BELLWETHER_CODE (GET_CODE (original));
340 x = rtx_alloc (bellwether_code);
341 memcpy (x, original, RTX_CODE_SIZE (bellwether_code));
343 /* Change the mode or code itself. */
344 group = iterator->group;
345 if (group->uses_iterator_p (x, iterator->index + group->num_builtins))
346 group->apply_iterator (x, value);
349 apply_mode_maps (x, mode_maps, iterator, value, unknown_mode_attr);
351 /* Change each string and recursively change each rtx. */
352 format_ptr = GET_RTX_FORMAT (bellwether_code);
353 for (i = 0; format_ptr[i] != 0; i++)
354 switch (format_ptr[i])
357 XTMPL (x, i) = apply_iterator_to_string (XTMPL (x, i), iterator, value);
362 XSTR (x, i) = apply_iterator_to_string (XSTR (x, i), iterator, value);
366 XEXP (x, i) = apply_iterator_to_rtx (XEXP (x, i), iterator, value,
367 mode_maps, unknown_mode_attr);
372 if (XVEC (original, i))
374 XVEC (x, i) = rtvec_alloc (XVECLEN (original, i));
375 for (j = 0; j < XVECLEN (x, i); j++)
376 XVECEXP (x, i, j) = apply_iterator_to_rtx (XVECEXP (original, i, j),
377 iterator, value, mode_maps,
388 /* Return true if X (or some subexpression of X) uses iterator ITERATOR. */
391 uses_iterator_p (rtx x, struct mapping *iterator)
393 struct iterator_group *group;
394 const char *format_ptr;
400 group = iterator->group;
401 if (group->uses_iterator_p (x, iterator->index + group->num_builtins))
404 format_ptr = GET_RTX_FORMAT (BELLWETHER_CODE (GET_CODE (x)));
405 for (i = 0; format_ptr[i] != 0; i++)
406 switch (format_ptr[i])
409 if (uses_iterator_p (XEXP (x, i), iterator))
416 for (j = 0; j < XVECLEN (x, i); j++)
417 if (uses_iterator_p (XVECEXP (x, i, j), iterator))
427 /* Return a condition that must satisfy both ORIGINAL and EXTRA. If ORIGINAL
428 has the form "&& ..." (as used in define_insn_and_splits), assume that
429 EXTRA is already satisfied. Empty strings are treated like "true". */
432 add_condition_to_string (const char *original, const char *extra)
434 if (original != 0 && original[0] == '&' && original[1] == '&')
436 return join_c_conditions (original, extra);
439 /* Like add_condition, but applied to all conditions in rtx X. */
442 add_condition_to_rtx (rtx x, const char *extra)
444 switch (GET_CODE (x))
448 XSTR (x, 2) = add_condition_to_string (XSTR (x, 2), extra);
452 case DEFINE_PEEPHOLE:
453 case DEFINE_PEEPHOLE2:
454 case DEFINE_COND_EXEC:
455 XSTR (x, 1) = add_condition_to_string (XSTR (x, 1), extra);
458 case DEFINE_INSN_AND_SPLIT:
459 XSTR (x, 2) = add_condition_to_string (XSTR (x, 2), extra);
460 XSTR (x, 4) = add_condition_to_string (XSTR (x, 4), extra);
468 /* A htab_traverse callback. Search the EXPR_LIST given by DATA
469 for rtxes that use the iterator in *SLOT. Replace each such rtx
470 with a list of expansions. */
473 apply_iterator_traverse (void **slot, void *data)
475 struct iterator_traverse_data *mtd = (struct iterator_traverse_data *) data;
476 struct mapping *iterator;
478 rtx elem, new_elem, original, x;
480 iterator = (struct mapping *) *slot;
481 for (elem = mtd->queue; elem != 0; elem = XEXP (elem, 1))
482 if (uses_iterator_p (XEXP (elem, 0), iterator))
484 /* For each iterator we expand, we set UNKNOWN_MODE_ATTR to NULL.
485 If apply_iterator_rtx finds an unknown attribute for a mode,
486 it will set it to the attribute. We want to know whether
487 the attribute is unknown after we have expanded all
488 possible iterators, so setting it to NULL here gives us the
489 right result when the hash table traversal is complete. */
490 mtd->unknown_mode_attr = NULL;
492 original = XEXP (elem, 0);
493 for (v = iterator->values; v != 0; v = v->next)
495 x = apply_iterator_to_rtx (original, iterator, v->number,
497 &mtd->unknown_mode_attr);
498 add_condition_to_rtx (x, v->string);
499 if (v != iterator->values)
501 /* Insert a new EXPR_LIST node after ELEM and put the
502 new expansion there. */
503 new_elem = rtx_alloc (EXPR_LIST);
504 XEXP (new_elem, 1) = XEXP (elem, 1);
505 XEXP (elem, 1) = new_elem;
514 /* Add a new "mapping" structure to hashtable TABLE. NAME is the name
515 of the mapping and GROUP is the group to which it belongs. */
517 static struct mapping *
518 add_mapping (struct iterator_group *group, htab_t table, const char *name)
523 m = XNEW (struct mapping);
524 m->name = xstrdup (name);
526 m->index = htab_elements (table);
529 slot = htab_find_slot (table, m, INSERT);
531 fatal_with_file_and_line ("`%s' already defined", name);
537 /* Add the pair (NUMBER, STRING) to a list of map_value structures.
538 END_PTR points to the current null terminator for the list; return
539 a pointer the new null terminator. */
541 static struct map_value **
542 add_map_value (struct map_value **end_ptr, int number, const char *string)
544 struct map_value *value;
546 value = XNEW (struct map_value);
548 value->number = number;
549 value->string = string;
555 /* Do one-time initialization of the mode and code attributes. */
558 initialize_iterators (void)
560 struct mapping *lower, *upper;
561 struct map_value **lower_ptr, **upper_ptr;
565 modes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
566 modes.iterators = htab_create (13, leading_string_hash,
567 leading_string_eq_p, 0);
568 modes.num_builtins = MAX_MACHINE_MODE;
569 modes.find_builtin = find_mode;
570 modes.uses_iterator_p = uses_mode_iterator_p;
571 modes.apply_iterator = apply_mode_iterator;
573 codes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0);
574 codes.iterators = htab_create (13, leading_string_hash,
575 leading_string_eq_p, 0);
576 codes.num_builtins = NUM_RTX_CODE;
577 codes.find_builtin = find_code;
578 codes.uses_iterator_p = uses_code_iterator_p;
579 codes.apply_iterator = apply_code_iterator;
581 lower = add_mapping (&modes, modes.attrs, "mode");
582 upper = add_mapping (&modes, modes.attrs, "MODE");
583 lower_ptr = &lower->values;
584 upper_ptr = &upper->values;
585 for (i = 0; i < MAX_MACHINE_MODE; i++)
587 copy = xstrdup (GET_MODE_NAME (i));
588 for (p = copy; *p != 0; p++)
591 upper_ptr = add_map_value (upper_ptr, i, GET_MODE_NAME (i));
592 lower_ptr = add_map_value (lower_ptr, i, copy);
595 lower = add_mapping (&codes, codes.attrs, "code");
596 upper = add_mapping (&codes, codes.attrs, "CODE");
597 lower_ptr = &lower->values;
598 upper_ptr = &upper->values;
599 for (i = 0; i < NUM_RTX_CODE; i++)
601 copy = xstrdup (GET_RTX_NAME (i));
602 for (p = copy; *p != 0; p++)
605 lower_ptr = add_map_value (lower_ptr, i, GET_RTX_NAME (i));
606 upper_ptr = add_map_value (upper_ptr, i, copy);
610 /* Provide a version of a function to read a long long if the system does
612 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ)
613 HOST_WIDE_INT atoll (const char *);
616 atoll (const char *p)
619 HOST_WIDE_INT tmp_wide;
631 HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0');
632 if (new_wide < tmp_wide)
634 /* Return INT_MAX equiv on overflow. */
635 tmp_wide = (~(unsigned HOST_WIDE_INT) 0) >> 1;
643 tmp_wide = -tmp_wide;
648 /* Process a define_conditions directive, starting with the optional
649 space after the "define_conditions". The directive looks like this:
657 It's not intended to appear in machine descriptions. It is
658 generated by (the program generated by) genconditions.c, and
659 slipped in at the beginning of the sequence of MD files read by
660 most of the other generators. */
662 read_conditions (void)
666 c = read_skip_spaces ();
668 fatal_expected_char ('[', c);
670 while ( (c = read_skip_spaces ()) != ']')
677 fatal_expected_char ('(', c);
680 validate_const_int (name.string);
681 value = atoi (name.string);
683 c = read_skip_spaces ();
685 fatal_expected_char ('"', c);
686 expr = read_quoted_string ();
688 c = read_skip_spaces ();
690 fatal_expected_char (')', c);
692 add_c_test (expr, value);
694 c = read_skip_spaces ();
696 fatal_expected_char (')', c);
700 validate_const_int (const char *string)
706 while (*cp && ISSPACE (*cp))
708 if (*cp == '-' || *cp == '+')
716 fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string);
719 /* Search GROUP for a mode or code called NAME and return its numerical
723 find_iterator (struct iterator_group *group, const char *name)
727 m = (struct mapping *) htab_find (group->iterators, &name);
729 return m->index + group->num_builtins;
730 return group->find_builtin (name);
733 /* Finish reading a declaration of the form:
735 (define... <name> [<value1> ... <valuen>])
737 from the MD file, where each <valuei> is either a bare symbol name or a
738 "(<name> <string>)" pair. The "(define..." part has already been read.
740 Represent the declaration as a "mapping" structure; add it to TABLE
741 (which belongs to GROUP) and return it. */
743 static struct mapping *
744 read_mapping (struct iterator_group *group, htab_t table)
748 struct map_value **end_ptr;
752 /* Read the mapping name and create a structure for it. */
754 m = add_mapping (group, table, name.string);
756 c = read_skip_spaces ();
758 fatal_expected_char ('[', c);
760 /* Read each value. */
761 end_ptr = &m->values;
762 c = read_skip_spaces ();
767 /* A bare symbol name that is implicitly paired to an
775 /* A "(name string)" pair. */
777 string = read_string (false);
778 c = read_skip_spaces ();
780 fatal_expected_char (')', c);
782 number = group->find_builtin (name.string);
783 end_ptr = add_map_value (end_ptr, number, string);
784 c = read_skip_spaces ();
788 c = read_skip_spaces ();
790 fatal_expected_char (')', c);
795 /* Check newly-created code iterator ITERATOR to see whether every code has the
796 same format. Initialize the iterator's entry in bellwether_codes. */
799 check_code_iterator (struct mapping *iterator)
802 enum rtx_code bellwether;
804 bellwether = (enum rtx_code) iterator->values->number;
805 for (v = iterator->values->next; v != 0; v = v->next)
806 if (strcmp (GET_RTX_FORMAT (bellwether), GET_RTX_FORMAT (v->number)) != 0)
807 fatal_with_file_and_line ("code iterator `%s' combines "
808 "different rtx formats", iterator->name);
810 bellwether_codes = XRESIZEVEC (enum rtx_code, bellwether_codes,
811 iterator->index + 1);
812 bellwether_codes[iterator->index] = bellwether;
815 /* Read an rtx in printed representation from the MD file and store
816 its core representation in *X. Also store the line number of the
817 opening '(' in *LINENO. Return true on success or false if the
818 end of file has been reached.
820 read_rtx is not used in the compiler proper, but rather in
821 the utilities gen*.c that construct C code from machine descriptions. */
824 read_rtx (rtx *x, int *lineno)
826 static rtx queue_head, queue_next;
827 static int queue_lineno;
830 /* Do one-time initialization. */
834 initialize_iterators ();
835 queue_head = rtx_alloc (EXPR_LIST);
840 struct map_value *mode_maps;
841 struct iterator_traverse_data mtd;
844 c = read_skip_spaces ();
849 queue_lineno = read_md_lineno;
851 from_file = read_rtx_1 (&mode_maps);
853 return false; /* This confuses a top level (nil) with end of
854 file, but a top level (nil) would have
855 crashed our caller anyway. */
857 queue_next = queue_head;
858 XEXP (queue_next, 0) = from_file;
859 XEXP (queue_next, 1) = 0;
861 mtd.queue = queue_next;
862 mtd.mode_maps = mode_maps;
863 mtd.unknown_mode_attr = mode_maps ? mode_maps->string : NULL;
864 htab_traverse (modes.iterators, apply_iterator_traverse, &mtd);
865 htab_traverse (codes.iterators, apply_iterator_traverse, &mtd);
866 if (mtd.unknown_mode_attr)
867 fatal_with_file_and_line ("undefined attribute '%s' used for mode",
868 mtd.unknown_mode_attr);
871 *x = XEXP (queue_next, 0);
872 *lineno = queue_lineno;
873 queue_next = XEXP (queue_next, 1);
878 /* Subroutine of read_rtx that reads one construct from the MD file but
879 doesn't apply any iterators. */
882 read_rtx_1 (struct map_value **mode_maps)
885 RTX_CODE real_code, bellwether_code;
886 const char *format_ptr;
891 HOST_WIDE_INT tmp_wide;
893 /* Linked list structure for making RTXs: */
896 struct rtx_list *next;
897 rtx value; /* Value of this node. */
901 c = read_skip_spaces (); /* Should be open paren. */
907 fatal_expected_char ('(', c);
910 if (strcmp (name.string, "nil") == 0)
912 /* (nil) stands for an expression that isn't there. */
913 c = read_skip_spaces ();
915 fatal_expected_char (')', c);
918 if (strcmp (name.string, "define_constants") == 0)
923 if (strcmp (name.string, "define_conditions") == 0)
928 if (strcmp (name.string, "define_mode_attr") == 0)
930 read_mapping (&modes, modes.attrs);
933 if (strcmp (name.string, "define_mode_iterator") == 0)
935 read_mapping (&modes, modes.iterators);
938 if (strcmp (name.string, "define_code_attr") == 0)
940 read_mapping (&codes, codes.attrs);
943 if (strcmp (name.string, "define_code_iterator") == 0)
945 check_code_iterator (read_mapping (&codes, codes.iterators));
948 real_code = (enum rtx_code) find_iterator (&codes, name.string);
949 bellwether_code = BELLWETHER_CODE (real_code);
951 /* If we end up with an insn expression then we free this space below. */
952 return_rtx = rtx_alloc (bellwether_code);
953 format_ptr = GET_RTX_FORMAT (bellwether_code);
954 PUT_CODE (return_rtx, real_code);
956 /* If what follows is `: mode ', read it and
957 store the mode in the rtx. */
959 i = read_skip_spaces ();
965 if (name.string[0] != '<' || name.string[strlen (name.string) - 1] != '>')
966 mode = find_iterator (&modes, name.string);
968 mode = mode_attr_index (mode_maps, name.string);
969 PUT_MODE (return_rtx, (enum machine_mode) mode);
970 if (GET_MODE (return_rtx) != mode)
971 fatal_with_file_and_line ("mode too large");
976 for (i = 0; format_ptr[i] != 0; i++)
977 switch (format_ptr[i])
979 /* 0 means a field for internal use only.
980 Don't expect it to be present in the input. */
986 XEXP (return_rtx, i) = read_rtx_1 (mode_maps);
990 /* 'V' is an optional vector: if a closeparen follows,
991 just store NULL for this element. */
992 c = read_skip_spaces ();
996 XVEC (return_rtx, i) = 0;
999 /* Now process the vector. */
1003 /* Obstack to store scratch vector in. */
1004 struct obstack vector_stack;
1005 int list_counter = 0;
1006 rtvec return_vec = NULL_RTVEC;
1008 c = read_skip_spaces ();
1010 fatal_expected_char ('[', c);
1012 /* Add expressions to a list, while keeping a count. */
1013 obstack_init (&vector_stack);
1014 while ((c = read_skip_spaces ()) && c != ']')
1017 fatal_expected_char (']', c);
1020 obstack_ptr_grow (&vector_stack, read_rtx_1 (mode_maps));
1022 if (list_counter > 0)
1024 return_vec = rtvec_alloc (list_counter);
1025 memcpy (&return_vec->elem[0], obstack_finish (&vector_stack),
1026 list_counter * sizeof (rtx));
1028 else if (format_ptr[i] == 'E')
1029 fatal_with_file_and_line ("vector must have at least one element");
1030 XVEC (return_rtx, i) = return_vec;
1031 obstack_free (&vector_stack, NULL);
1032 /* close bracket gotten */
1043 c = read_skip_spaces ();
1047 /* 'S' fields are optional and should be NULL if no string
1048 was given. Also allow normal 's' and 'T' strings to be
1049 omitted, treating them in the same way as empty strings. */
1050 XSTR (return_rtx, i) = (format_ptr[i] == 'S' ? NULL : "");
1054 /* The output template slot of a DEFINE_INSN,
1055 DEFINE_INSN_AND_SPLIT, or DEFINE_PEEPHOLE automatically
1056 gets a star inserted as its first character, if it is
1057 written with a brace block instead of a string constant. */
1058 star_if_braced = (format_ptr[i] == 'T');
1060 stringbuf = read_string (star_if_braced);
1062 /* For insn patterns, we want to provide a default name
1063 based on the file and line, like "*foo.md:12", if the
1064 given name is blank. These are only for define_insn and
1065 define_insn_and_split, to aid debugging. */
1066 if (*stringbuf == '\0'
1068 && (GET_CODE (return_rtx) == DEFINE_INSN
1069 || GET_CODE (return_rtx) == DEFINE_INSN_AND_SPLIT))
1072 const char *fn = (read_md_filename ? read_md_filename : "rtx");
1074 for (slash = fn; *slash; slash ++)
1075 if (*slash == '/' || *slash == '\\' || *slash == ':')
1077 obstack_1grow (&string_obstack, '*');
1078 obstack_grow (&string_obstack, fn, strlen (fn));
1079 sprintf (line_name, ":%d", read_md_lineno);
1080 obstack_grow (&string_obstack, line_name, strlen (line_name)+1);
1081 stringbuf = XOBFINISH (&string_obstack, char *);
1085 XTMPL (return_rtx, i) = stringbuf;
1087 XSTR (return_rtx, i) = stringbuf;
1093 validate_const_int (name.string);
1094 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1095 tmp_wide = atoi (name.string);
1097 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1098 tmp_wide = atol (name.string);
1100 /* Prefer atoll over atoq, since the former is in the ISO C99 standard.
1101 But prefer not to use our hand-rolled function above either. */
1102 #if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ)
1103 tmp_wide = atoll (name.string);
1105 tmp_wide = atoq (name.string);
1109 XWINT (return_rtx, i) = tmp_wide;
1115 validate_const_int (name.string);
1116 tmp_int = atoi (name.string);
1117 XINT (return_rtx, i) = tmp_int;
1124 c = read_skip_spaces ();
1127 /* Syntactic sugar for AND and IOR, allowing Lisp-like
1128 arbitrary number of arguments for them. */
1129 if (c == '(' && (GET_CODE (return_rtx) == AND
1130 || GET_CODE (return_rtx) == IOR))
1131 return read_rtx_variadic (mode_maps, return_rtx);
1133 fatal_expected_char (')', c);
1139 /* Mutually recursive subroutine of read_rtx which reads
1140 (thing x1 x2 x3 ...) and produces RTL as if
1141 (thing x1 (thing x2 (thing x3 ...))) had been written.
1142 When called, FORM is (thing x1 x2), and the file position
1143 is just past the leading parenthesis of x3. Only works
1144 for THINGs which are dyadic expressions, e.g. AND, IOR. */
1146 read_rtx_variadic (struct map_value **mode_maps, rtx form)
1155 q = rtx_alloc (GET_CODE (p));
1156 PUT_MODE (q, GET_MODE (p));
1158 XEXP (q, 0) = XEXP (p, 1);
1159 XEXP (q, 1) = read_rtx_1 (mode_maps);
1163 c = read_skip_spaces ();
1168 fatal_expected_char (')', c);