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_code (const char *, struct map_value
**);
121 static rtx
read_nested_rtx (struct map_value
**);
122 static rtx
read_rtx_variadic (struct map_value
**, rtx
);
124 /* The mode and code iterator structures. */
125 static struct iterator_group modes
, codes
;
127 /* Index I is the value of BELLWETHER_CODE (I + NUM_RTX_CODE). */
128 static enum rtx_code
*bellwether_codes
;
130 /* Implementations of the iterator_group callbacks for modes. */
133 find_mode (const char *name
)
137 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
138 if (strcmp (GET_MODE_NAME (i
), name
) == 0)
141 fatal_with_file_and_line ("unknown mode `%s'", name
);
145 uses_mode_iterator_p (rtx x
, int mode
)
147 return (int) GET_MODE (x
) == mode
;
151 apply_mode_iterator (rtx x
, int mode
)
153 PUT_MODE (x
, (enum machine_mode
) mode
);
156 /* Implementations of the iterator_group callbacks for codes. */
159 find_code (const char *name
)
163 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
164 if (strcmp (GET_RTX_NAME (i
), name
) == 0)
167 fatal_with_file_and_line ("unknown rtx code `%s'", name
);
171 uses_code_iterator_p (rtx x
, int code
)
173 return (int) GET_CODE (x
) == code
;
177 apply_code_iterator (rtx x
, int code
)
179 PUT_CODE (x
, (enum rtx_code
) code
);
182 /* Map a code or mode attribute string P to the underlying string for
183 ITERATOR and VALUE. */
185 static struct map_value
*
186 map_attr_string (const char *p
, struct mapping
*iterator
, int value
)
192 /* If there's a "iterator:" prefix, check whether the iterator name matches.
193 Set ATTR to the start of the attribute name. */
194 attr
= strchr (p
, ':');
199 if (strncmp (p
, iterator
->name
, attr
- p
) != 0
200 || iterator
->name
[attr
- p
] != 0)
205 /* Find the attribute specification. */
206 m
= (struct mapping
*) htab_find (iterator
->group
->attrs
, &attr
);
210 /* Find the attribute value for VALUE. */
211 for (v
= m
->values
; v
!= 0; v
= v
->next
)
212 if (v
->number
== value
)
218 /* Given an attribute string used as a machine mode, return an index
219 to store in the machine mode to be translated by
220 apply_iterator_to_rtx. */
223 mode_attr_index (struct map_value
**mode_maps
, const char *string
)
226 struct map_value
*mv
;
228 /* Copy the attribute string into permanent storage, without the
229 angle brackets around it. */
230 obstack_grow0 (&string_obstack
, string
+ 1, strlen (string
) - 2);
231 p
= XOBFINISH (&string_obstack
, char *);
233 mv
= XNEW (struct map_value
);
234 mv
->number
= *mode_maps
== 0 ? 0 : (*mode_maps
)->number
+ 1;
236 mv
->next
= *mode_maps
;
239 /* We return a code which we can map back into this string: the
240 number of machine modes + the number of mode iterators + the index
242 return MAX_MACHINE_MODE
+ htab_elements (modes
.iterators
) + mv
->number
;
245 /* Apply MODE_MAPS to the top level of X, expanding cases where an
246 attribute is used for a mode. ITERATOR is the current iterator we are
247 expanding, and VALUE is the value to which we are expanding it.
248 This sets *UNKNOWN to true if we find a mode attribute which has not
249 yet been defined, and does not change it otherwise. */
252 apply_mode_maps (rtx x
, struct map_value
*mode_maps
, struct mapping
*iterator
,
253 int value
, const char **unknown
)
257 struct map_value
*pm
;
259 offset
= MAX_MACHINE_MODE
+ htab_elements (modes
.iterators
);
260 if (GET_MODE (x
) < offset
)
263 indx
= GET_MODE (x
) - offset
;
264 for (pm
= mode_maps
; pm
; pm
= pm
->next
)
266 if (pm
->number
== indx
)
270 v
= map_attr_string (pm
->string
, iterator
, value
);
272 PUT_MODE (x
, (enum machine_mode
) find_mode (v
->string
));
274 *unknown
= pm
->string
;
280 /* Given that ITERATOR is being expanded as VALUE, apply the appropriate
281 string substitutions to STRING. Return the new string if any changes
282 were needed, otherwise return STRING itself. */
285 apply_iterator_to_string (const char *string
, struct mapping
*iterator
, int value
)
287 char *base
, *copy
, *p
, *start
, *end
;
293 base
= p
= copy
= ASTRDUP (string
);
294 while ((start
= strchr (p
, '<')) && (end
= strchr (start
, '>')))
299 v
= map_attr_string (p
, iterator
, value
);
304 /* Add everything between the last copied byte and the '<',
305 then add in the attribute value. */
306 obstack_grow (&string_obstack
, base
, start
- base
);
307 obstack_grow (&string_obstack
, v
->string
, strlen (v
->string
));
312 obstack_grow (&string_obstack
, base
, strlen (base
) + 1);
313 copy
= XOBFINISH (&string_obstack
, char *);
314 copy_md_ptr_loc (copy
, string
);
320 /* Return a copy of ORIGINAL in which all uses of ITERATOR have been
321 replaced by VALUE. MODE_MAPS holds information about attribute
322 strings used for modes. This sets *UNKNOWN_MODE_ATTR to the value of
323 an unknown mode attribute, and does not change it otherwise. */
326 apply_iterator_to_rtx (rtx original
, struct mapping
*iterator
, int value
,
327 struct map_value
*mode_maps
,
328 const char **unknown_mode_attr
)
330 struct iterator_group
*group
;
331 const char *format_ptr
;
334 enum rtx_code bellwether_code
;
339 /* Create a shallow copy of ORIGINAL. */
340 bellwether_code
= BELLWETHER_CODE (GET_CODE (original
));
341 x
= rtx_alloc (bellwether_code
);
342 memcpy (x
, original
, RTX_CODE_SIZE (bellwether_code
));
344 /* Change the mode or code itself. */
345 group
= iterator
->group
;
346 if (group
->uses_iterator_p (x
, iterator
->index
+ group
->num_builtins
))
347 group
->apply_iterator (x
, value
);
350 apply_mode_maps (x
, mode_maps
, iterator
, value
, unknown_mode_attr
);
352 /* Change each string and recursively change each rtx. */
353 format_ptr
= GET_RTX_FORMAT (bellwether_code
);
354 for (i
= 0; format_ptr
[i
] != 0; i
++)
355 switch (format_ptr
[i
])
358 XTMPL (x
, i
) = apply_iterator_to_string (XTMPL (x
, i
), iterator
, value
);
363 XSTR (x
, i
) = apply_iterator_to_string (XSTR (x
, i
), iterator
, value
);
367 XEXP (x
, i
) = apply_iterator_to_rtx (XEXP (x
, i
), iterator
, value
,
368 mode_maps
, unknown_mode_attr
);
373 if (XVEC (original
, i
))
375 XVEC (x
, i
) = rtvec_alloc (XVECLEN (original
, i
));
376 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
377 XVECEXP (x
, i
, j
) = apply_iterator_to_rtx (XVECEXP (original
, i
, j
),
378 iterator
, value
, mode_maps
,
389 /* Return true if X (or some subexpression of X) uses iterator ITERATOR. */
392 uses_iterator_p (rtx x
, struct mapping
*iterator
)
394 struct iterator_group
*group
;
395 const char *format_ptr
;
401 group
= iterator
->group
;
402 if (group
->uses_iterator_p (x
, iterator
->index
+ group
->num_builtins
))
405 format_ptr
= GET_RTX_FORMAT (BELLWETHER_CODE (GET_CODE (x
)));
406 for (i
= 0; format_ptr
[i
] != 0; i
++)
407 switch (format_ptr
[i
])
410 if (uses_iterator_p (XEXP (x
, i
), iterator
))
417 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
418 if (uses_iterator_p (XVECEXP (x
, i
, j
), iterator
))
428 /* Return a condition that must satisfy both ORIGINAL and EXTRA. If ORIGINAL
429 has the form "&& ..." (as used in define_insn_and_splits), assume that
430 EXTRA is already satisfied. Empty strings are treated like "true". */
433 add_condition_to_string (const char *original
, const char *extra
)
435 if (original
!= 0 && original
[0] == '&' && original
[1] == '&')
437 return join_c_conditions (original
, extra
);
440 /* Like add_condition, but applied to all conditions in rtx X. */
443 add_condition_to_rtx (rtx x
, const char *extra
)
445 switch (GET_CODE (x
))
449 XSTR (x
, 2) = add_condition_to_string (XSTR (x
, 2), extra
);
453 case DEFINE_PEEPHOLE
:
454 case DEFINE_PEEPHOLE2
:
455 case DEFINE_COND_EXEC
:
456 XSTR (x
, 1) = add_condition_to_string (XSTR (x
, 1), extra
);
459 case DEFINE_INSN_AND_SPLIT
:
460 XSTR (x
, 2) = add_condition_to_string (XSTR (x
, 2), extra
);
461 XSTR (x
, 4) = add_condition_to_string (XSTR (x
, 4), extra
);
469 /* A htab_traverse callback. Search the EXPR_LIST given by DATA
470 for rtxes that use the iterator in *SLOT. Replace each such rtx
471 with a list of expansions. */
474 apply_iterator_traverse (void **slot
, void *data
)
476 struct iterator_traverse_data
*mtd
= (struct iterator_traverse_data
*) data
;
477 struct mapping
*iterator
;
479 rtx elem
, new_elem
, original
, x
;
481 iterator
= (struct mapping
*) *slot
;
482 for (elem
= mtd
->queue
; elem
!= 0; elem
= XEXP (elem
, 1))
483 if (uses_iterator_p (XEXP (elem
, 0), iterator
))
485 /* For each iterator we expand, we set UNKNOWN_MODE_ATTR to NULL.
486 If apply_iterator_rtx finds an unknown attribute for a mode,
487 it will set it to the attribute. We want to know whether
488 the attribute is unknown after we have expanded all
489 possible iterators, so setting it to NULL here gives us the
490 right result when the hash table traversal is complete. */
491 mtd
->unknown_mode_attr
= NULL
;
493 original
= XEXP (elem
, 0);
494 for (v
= iterator
->values
; v
!= 0; v
= v
->next
)
496 x
= apply_iterator_to_rtx (original
, iterator
, v
->number
,
498 &mtd
->unknown_mode_attr
);
499 add_condition_to_rtx (x
, v
->string
);
500 if (v
!= iterator
->values
)
502 /* Insert a new EXPR_LIST node after ELEM and put the
503 new expansion there. */
504 new_elem
= rtx_alloc (EXPR_LIST
);
505 XEXP (new_elem
, 1) = XEXP (elem
, 1);
506 XEXP (elem
, 1) = new_elem
;
515 /* Add a new "mapping" structure to hashtable TABLE. NAME is the name
516 of the mapping and GROUP is the group to which it belongs. */
518 static struct mapping
*
519 add_mapping (struct iterator_group
*group
, htab_t table
, const char *name
)
524 m
= XNEW (struct mapping
);
525 m
->name
= xstrdup (name
);
527 m
->index
= htab_elements (table
);
530 slot
= htab_find_slot (table
, m
, INSERT
);
532 fatal_with_file_and_line ("`%s' already defined", name
);
538 /* Add the pair (NUMBER, STRING) to a list of map_value structures.
539 END_PTR points to the current null terminator for the list; return
540 a pointer the new null terminator. */
542 static struct map_value
**
543 add_map_value (struct map_value
**end_ptr
, int number
, const char *string
)
545 struct map_value
*value
;
547 value
= XNEW (struct map_value
);
549 value
->number
= number
;
550 value
->string
= string
;
556 /* Do one-time initialization of the mode and code attributes. */
559 initialize_iterators (void)
561 struct mapping
*lower
, *upper
;
562 struct map_value
**lower_ptr
, **upper_ptr
;
566 modes
.attrs
= htab_create (13, leading_string_hash
, leading_string_eq_p
, 0);
567 modes
.iterators
= htab_create (13, leading_string_hash
,
568 leading_string_eq_p
, 0);
569 modes
.num_builtins
= MAX_MACHINE_MODE
;
570 modes
.find_builtin
= find_mode
;
571 modes
.uses_iterator_p
= uses_mode_iterator_p
;
572 modes
.apply_iterator
= apply_mode_iterator
;
574 codes
.attrs
= htab_create (13, leading_string_hash
, leading_string_eq_p
, 0);
575 codes
.iterators
= htab_create (13, leading_string_hash
,
576 leading_string_eq_p
, 0);
577 codes
.num_builtins
= NUM_RTX_CODE
;
578 codes
.find_builtin
= find_code
;
579 codes
.uses_iterator_p
= uses_code_iterator_p
;
580 codes
.apply_iterator
= apply_code_iterator
;
582 lower
= add_mapping (&modes
, modes
.attrs
, "mode");
583 upper
= add_mapping (&modes
, modes
.attrs
, "MODE");
584 lower_ptr
= &lower
->values
;
585 upper_ptr
= &upper
->values
;
586 for (i
= 0; i
< MAX_MACHINE_MODE
; i
++)
588 copy
= xstrdup (GET_MODE_NAME (i
));
589 for (p
= copy
; *p
!= 0; p
++)
592 upper_ptr
= add_map_value (upper_ptr
, i
, GET_MODE_NAME (i
));
593 lower_ptr
= add_map_value (lower_ptr
, i
, copy
);
596 lower
= add_mapping (&codes
, codes
.attrs
, "code");
597 upper
= add_mapping (&codes
, codes
.attrs
, "CODE");
598 lower_ptr
= &lower
->values
;
599 upper_ptr
= &upper
->values
;
600 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
602 copy
= xstrdup (GET_RTX_NAME (i
));
603 for (p
= copy
; *p
!= 0; p
++)
606 lower_ptr
= add_map_value (lower_ptr
, i
, GET_RTX_NAME (i
));
607 upper_ptr
= add_map_value (upper_ptr
, i
, copy
);
611 /* Provide a version of a function to read a long long if the system does
613 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ)
614 HOST_WIDE_INT
atoll (const char *);
617 atoll (const char *p
)
620 HOST_WIDE_INT tmp_wide
;
632 HOST_WIDE_INT new_wide
= tmp_wide
*10 + (*p
- '0');
633 if (new_wide
< tmp_wide
)
635 /* Return INT_MAX equiv on overflow. */
636 tmp_wide
= (~(unsigned HOST_WIDE_INT
) 0) >> 1;
644 tmp_wide
= -tmp_wide
;
649 /* Process a define_conditions directive, starting with the optional
650 space after the "define_conditions". The directive looks like this:
658 It's not intended to appear in machine descriptions. It is
659 generated by (the program generated by) genconditions.c, and
660 slipped in at the beginning of the sequence of MD files read by
661 most of the other generators. */
663 read_conditions (void)
667 c
= read_skip_spaces ();
669 fatal_expected_char ('[', c
);
671 while ( (c
= read_skip_spaces ()) != ']')
678 fatal_expected_char ('(', c
);
681 validate_const_int (name
.string
);
682 value
= atoi (name
.string
);
684 c
= read_skip_spaces ();
686 fatal_expected_char ('"', c
);
687 expr
= read_quoted_string ();
689 c
= read_skip_spaces ();
691 fatal_expected_char (')', c
);
693 add_c_test (expr
, value
);
698 validate_const_int (const char *string
)
704 while (*cp
&& ISSPACE (*cp
))
706 if (*cp
== '-' || *cp
== '+')
714 fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string
);
717 /* Search GROUP for a mode or code called NAME and return its numerical
721 find_iterator (struct iterator_group
*group
, const char *name
)
725 m
= (struct mapping
*) htab_find (group
->iterators
, &name
);
727 return m
->index
+ group
->num_builtins
;
728 return group
->find_builtin (name
);
731 /* Finish reading a declaration of the form:
733 (define... <name> [<value1> ... <valuen>])
735 from the MD file, where each <valuei> is either a bare symbol name or a
736 "(<name> <string>)" pair. The "(define..." part has already been read.
738 Represent the declaration as a "mapping" structure; add it to TABLE
739 (which belongs to GROUP) and return it. */
741 static struct mapping
*
742 read_mapping (struct iterator_group
*group
, htab_t table
)
746 struct map_value
**end_ptr
;
750 /* Read the mapping name and create a structure for it. */
752 m
= add_mapping (group
, table
, name
.string
);
754 c
= read_skip_spaces ();
756 fatal_expected_char ('[', c
);
758 /* Read each value. */
759 end_ptr
= &m
->values
;
760 c
= read_skip_spaces ();
765 /* A bare symbol name that is implicitly paired to an
773 /* A "(name string)" pair. */
775 string
= read_string (false);
776 c
= read_skip_spaces ();
778 fatal_expected_char (')', c
);
780 number
= group
->find_builtin (name
.string
);
781 end_ptr
= add_map_value (end_ptr
, number
, string
);
782 c
= read_skip_spaces ();
789 /* Check newly-created code iterator ITERATOR to see whether every code has the
790 same format. Initialize the iterator's entry in bellwether_codes. */
793 check_code_iterator (struct mapping
*iterator
)
796 enum rtx_code bellwether
;
798 bellwether
= (enum rtx_code
) iterator
->values
->number
;
799 for (v
= iterator
->values
->next
; v
!= 0; v
= v
->next
)
800 if (strcmp (GET_RTX_FORMAT (bellwether
), GET_RTX_FORMAT (v
->number
)) != 0)
801 fatal_with_file_and_line ("code iterator `%s' combines "
802 "different rtx formats", iterator
->name
);
804 bellwether_codes
= XRESIZEVEC (enum rtx_code
, bellwether_codes
,
805 iterator
->index
+ 1);
806 bellwether_codes
[iterator
->index
] = bellwether
;
809 /* Read an rtx-related declaration from the MD file, given that it
810 starts with directive name RTX_NAME. Return true if it expands to
811 one or more rtxes (as defined by rtx.def). When returning true,
812 store the list of rtxes as an EXPR_LIST in *X. */
815 read_rtx (const char *rtx_name
, rtx
*x
)
817 static rtx queue_head
;
818 struct map_value
*mode_maps
;
819 struct iterator_traverse_data mtd
;
821 /* Do one-time initialization. */
824 initialize_iterators ();
825 queue_head
= rtx_alloc (EXPR_LIST
);
828 /* Handle various rtx-related declarations that aren't themselves
830 if (strcmp (rtx_name
, "define_conditions") == 0)
835 if (strcmp (rtx_name
, "define_mode_attr") == 0)
837 read_mapping (&modes
, modes
.attrs
);
840 if (strcmp (rtx_name
, "define_mode_iterator") == 0)
842 read_mapping (&modes
, modes
.iterators
);
845 if (strcmp (rtx_name
, "define_code_attr") == 0)
847 read_mapping (&codes
, codes
.attrs
);
850 if (strcmp (rtx_name
, "define_code_iterator") == 0)
852 check_code_iterator (read_mapping (&codes
, codes
.iterators
));
857 XEXP (queue_head
, 0) = read_rtx_code (rtx_name
, &mode_maps
);
858 XEXP (queue_head
, 1) = 0;
860 mtd
.queue
= queue_head
;
861 mtd
.mode_maps
= mode_maps
;
862 mtd
.unknown_mode_attr
= mode_maps
? mode_maps
->string
: NULL
;
863 htab_traverse (modes
.iterators
, apply_iterator_traverse
, &mtd
);
864 htab_traverse (codes
.iterators
, apply_iterator_traverse
, &mtd
);
865 if (mtd
.unknown_mode_attr
)
866 fatal_with_file_and_line ("undefined attribute '%s' used for mode",
867 mtd
.unknown_mode_attr
);
873 /* Subroutine of read_rtx and read_nested_rtx. CODE_NAME is the name of
874 either an rtx code or a code iterator. Parse the rest of the rtx and
875 return it. MODE_MAPS is as for iterator_traverse_data. */
878 read_rtx_code (const char *code_name
, struct map_value
**mode_maps
)
881 RTX_CODE real_code
, bellwether_code
;
882 const char *format_ptr
;
887 HOST_WIDE_INT tmp_wide
;
889 /* Linked list structure for making RTXs: */
892 struct rtx_list
*next
;
893 rtx value
; /* Value of this node. */
896 real_code
= (enum rtx_code
) find_iterator (&codes
, code_name
);
897 bellwether_code
= BELLWETHER_CODE (real_code
);
899 /* If we end up with an insn expression then we free this space below. */
900 return_rtx
= rtx_alloc (bellwether_code
);
901 format_ptr
= GET_RTX_FORMAT (bellwether_code
);
902 PUT_CODE (return_rtx
, real_code
);
904 /* If what follows is `: mode ', read it and
905 store the mode in the rtx. */
907 i
= read_skip_spaces ();
913 if (name
.string
[0] != '<' || name
.string
[strlen (name
.string
) - 1] != '>')
914 mode
= find_iterator (&modes
, name
.string
);
916 mode
= mode_attr_index (mode_maps
, name
.string
);
917 PUT_MODE (return_rtx
, (enum machine_mode
) mode
);
918 if (GET_MODE (return_rtx
) != mode
)
919 fatal_with_file_and_line ("mode too large");
924 for (i
= 0; format_ptr
[i
] != 0; i
++)
925 switch (format_ptr
[i
])
927 /* 0 means a field for internal use only.
928 Don't expect it to be present in the input. */
934 XEXP (return_rtx
, i
) = read_nested_rtx (mode_maps
);
938 /* 'V' is an optional vector: if a closeparen follows,
939 just store NULL for this element. */
940 c
= read_skip_spaces ();
944 XVEC (return_rtx
, i
) = 0;
947 /* Now process the vector. */
951 /* Obstack to store scratch vector in. */
952 struct obstack vector_stack
;
953 int list_counter
= 0;
954 rtvec return_vec
= NULL_RTVEC
;
956 c
= read_skip_spaces ();
958 fatal_expected_char ('[', c
);
960 /* Add expressions to a list, while keeping a count. */
961 obstack_init (&vector_stack
);
962 while ((c
= read_skip_spaces ()) && c
!= ']')
965 fatal_expected_char (']', c
);
968 obstack_ptr_grow (&vector_stack
, read_nested_rtx (mode_maps
));
970 if (list_counter
> 0)
972 return_vec
= rtvec_alloc (list_counter
);
973 memcpy (&return_vec
->elem
[0], obstack_finish (&vector_stack
),
974 list_counter
* sizeof (rtx
));
976 else if (format_ptr
[i
] == 'E')
977 fatal_with_file_and_line ("vector must have at least one element");
978 XVEC (return_rtx
, i
) = return_vec
;
979 obstack_free (&vector_stack
, NULL
);
980 /* close bracket gotten */
991 c
= read_skip_spaces ();
995 /* 'S' fields are optional and should be NULL if no string
996 was given. Also allow normal 's' and 'T' strings to be
997 omitted, treating them in the same way as empty strings. */
998 XSTR (return_rtx
, i
) = (format_ptr
[i
] == 'S' ? NULL
: "");
1002 /* The output template slot of a DEFINE_INSN,
1003 DEFINE_INSN_AND_SPLIT, or DEFINE_PEEPHOLE automatically
1004 gets a star inserted as its first character, if it is
1005 written with a brace block instead of a string constant. */
1006 star_if_braced
= (format_ptr
[i
] == 'T');
1008 stringbuf
= read_string (star_if_braced
);
1010 /* For insn patterns, we want to provide a default name
1011 based on the file and line, like "*foo.md:12", if the
1012 given name is blank. These are only for define_insn and
1013 define_insn_and_split, to aid debugging. */
1014 if (*stringbuf
== '\0'
1016 && (GET_CODE (return_rtx
) == DEFINE_INSN
1017 || GET_CODE (return_rtx
) == DEFINE_INSN_AND_SPLIT
))
1020 const char *fn
= (read_md_filename
? read_md_filename
: "rtx");
1022 for (slash
= fn
; *slash
; slash
++)
1023 if (*slash
== '/' || *slash
== '\\' || *slash
== ':')
1025 obstack_1grow (&string_obstack
, '*');
1026 obstack_grow (&string_obstack
, fn
, strlen (fn
));
1027 sprintf (line_name
, ":%d", read_md_lineno
);
1028 obstack_grow (&string_obstack
, line_name
, strlen (line_name
)+1);
1029 stringbuf
= XOBFINISH (&string_obstack
, char *);
1033 XTMPL (return_rtx
, i
) = stringbuf
;
1035 XSTR (return_rtx
, i
) = stringbuf
;
1041 validate_const_int (name
.string
);
1042 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1043 tmp_wide
= atoi (name
.string
);
1045 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1046 tmp_wide
= atol (name
.string
);
1048 /* Prefer atoll over atoq, since the former is in the ISO C99 standard.
1049 But prefer not to use our hand-rolled function above either. */
1050 #if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ)
1051 tmp_wide
= atoll (name
.string
);
1053 tmp_wide
= atoq (name
.string
);
1057 XWINT (return_rtx
, i
) = tmp_wide
;
1063 validate_const_int (name
.string
);
1064 tmp_int
= atoi (name
.string
);
1065 XINT (return_rtx
, i
) = tmp_int
;
1072 c
= read_skip_spaces ();
1073 /* Syntactic sugar for AND and IOR, allowing Lisp-like
1074 arbitrary number of arguments for them. */
1076 && (GET_CODE (return_rtx
) == AND
1077 || GET_CODE (return_rtx
) == IOR
))
1078 return read_rtx_variadic (mode_maps
, return_rtx
);
1084 /* Read a nested rtx construct from the MD file and return it.
1085 MODE_MAPS is as for iterator_traverse_data. */
1088 read_nested_rtx (struct map_value
**mode_maps
)
1090 struct md_name name
;
1094 c
= read_skip_spaces ();
1096 fatal_expected_char ('(', c
);
1099 if (strcmp (name
.string
, "nil") == 0)
1102 return_rtx
= read_rtx_code (name
.string
, mode_maps
);
1104 c
= read_skip_spaces ();
1106 fatal_expected_char (')', c
);
1111 /* Mutually recursive subroutine of read_rtx which reads
1112 (thing x1 x2 x3 ...) and produces RTL as if
1113 (thing x1 (thing x2 (thing x3 ...))) had been written.
1114 When called, FORM is (thing x1 x2), and the file position
1115 is just past the leading parenthesis of x3. Only works
1116 for THINGs which are dyadic expressions, e.g. AND, IOR. */
1118 read_rtx_variadic (struct map_value
**mode_maps
, rtx form
)
1127 q
= rtx_alloc (GET_CODE (p
));
1128 PUT_MODE (q
, GET_MODE (p
));
1130 XEXP (q
, 0) = XEXP (p
, 1);
1131 XEXP (q
, 1) = read_nested_rtx (mode_maps
);
1135 c
= read_skip_spaces ();