2 Copyright (C) 1987, 1988, 1991, 1994, 1997, 1998, 1999, 2000, 2001, 2002,
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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "coretypes.h"
31 static htab_t md_constants
;
33 /* One element in a singly-linked list of (integer, string) pairs. */
35 struct map_value
*next
;
40 /* Maps a macro or attribute name to a list of (integer, string) pairs.
41 The integers are mode or code values; the strings are either C conditions
42 or attribute values. */
44 /* The name of the macro or attribute. */
47 /* The group (modes or codes) to which the macro or attribute belongs. */
48 struct macro_group
*group
;
50 /* Gives a unique number to the attribute or macro. Numbers are
51 allocated consecutively, starting at 0. */
54 /* The list of (integer, string) pairs. */
55 struct map_value
*values
;
58 /* A structure for abstracting the common parts of code and mode macros. */
60 /* Tables of "mapping" structures, one for attributes and one for macros. */
63 /* The number of "real" modes or codes (and by extension, the first
64 number available for use as a macro placeholder). */
67 /* Treat the given string as the name of a standard mode or code and
68 return its integer value. Use the given file for error reporting. */
69 int (*find_builtin
) (const char *, FILE *);
71 /* Return true if the given rtx uses the given mode or code. */
72 bool (*uses_macro_p
) (rtx
, int);
74 /* Make the given rtx use the given mode or code. */
75 void (*apply_macro
) (rtx
, int);
78 /* If CODE is the number of a code macro, return a real rtx code that
79 has the same format. Return CODE otherwise. */
80 #define BELLWETHER_CODE(CODE) \
81 ((CODE) < NUM_RTX_CODE ? CODE : bellwether_codes[CODE - NUM_RTX_CODE])
83 static void fatal_with_file_and_line (FILE *, const char *, ...)
84 ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN
;
85 static void fatal_expected_char (FILE *, int, int) ATTRIBUTE_NORETURN
;
86 static int find_mode (const char *, FILE *);
87 static bool uses_mode_macro_p (rtx
, int);
88 static void apply_mode_macro (rtx
, int);
89 static int find_code (const char *, FILE *);
90 static bool uses_code_macro_p (rtx
, int);
91 static void apply_code_macro (rtx
, int);
92 static const char *apply_macro_to_string (const char *, struct mapping
*, int);
93 static rtx
apply_macro_to_rtx (rtx
, struct mapping
*, int);
94 static bool uses_macro_p (rtx
, struct mapping
*);
95 static const char *add_condition_to_string (const char *, const char *);
96 static void add_condition_to_rtx (rtx
, const char *);
97 static int apply_macro_traverse (void **, void *);
98 static struct mapping
*add_mapping (struct macro_group
*, htab_t t
,
99 const char *, FILE *);
100 static struct map_value
**add_map_value (struct map_value
**,
102 static void initialize_macros (void);
103 static void read_name (char *, FILE *);
104 static char *read_string (FILE *, int);
105 static char *read_quoted_string (FILE *);
106 static char *read_braced_string (FILE *);
107 static void read_escape (FILE *);
108 static hashval_t
def_hash (const void *);
109 static int def_name_eq_p (const void *, const void *);
110 static void read_constants (FILE *infile
, char *tmp_char
);
111 static void validate_const_int (FILE *, const char *);
112 static int find_macro (struct macro_group
*, const char *, FILE *);
113 static struct mapping
*read_mapping (struct macro_group
*, htab_t
, FILE *);
114 static void check_code_macro (struct mapping
*, FILE *);
115 static rtx
read_rtx_1 (FILE *);
117 /* The mode and code macro structures. */
118 static struct macro_group modes
, codes
;
120 /* Index I is the value of BELLWETHER_CODE (I + NUM_RTX_CODE). */
121 static enum rtx_code
*bellwether_codes
;
123 /* Obstack used for allocating RTL strings. */
124 static struct obstack string_obstack
;
126 /* Subroutines of read_rtx. */
128 /* The current line number for the file. */
129 int read_rtx_lineno
= 1;
131 /* The filename for aborting with file and line. */
132 const char *read_rtx_filename
= "<unknown>";
135 fatal_with_file_and_line (FILE *infile
, const char *msg
, ...)
144 fprintf (stderr
, "%s:%d: ", read_rtx_filename
, read_rtx_lineno
);
145 vfprintf (stderr
, msg
, ap
);
148 /* Gather some following context. */
149 for (i
= 0; i
< sizeof (context
)-1; ++i
)
154 if (c
== '\r' || c
== '\n')
160 fprintf (stderr
, "%s:%d: following context is `%s'\n",
161 read_rtx_filename
, read_rtx_lineno
, context
);
167 /* Dump code after printing a message. Used when read_rtx finds
171 fatal_expected_char (FILE *infile
, int expected_c
, int actual_c
)
173 fatal_with_file_and_line (infile
, "expected character `%c', found `%c'",
174 expected_c
, actual_c
);
177 /* Implementations of the macro_group callbacks for modes. */
180 find_mode (const char *name
, FILE *infile
)
184 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
185 if (strcmp (GET_MODE_NAME (i
), name
) == 0)
188 fatal_with_file_and_line (infile
, "unknown mode `%s'", name
);
192 uses_mode_macro_p (rtx x
, int mode
)
194 return (int) GET_MODE (x
) == mode
;
198 apply_mode_macro (rtx x
, int mode
)
203 /* Implementations of the macro_group callbacks for codes. */
206 find_code (const char *name
, FILE *infile
)
210 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
211 if (strcmp (GET_RTX_NAME (i
), name
) == 0)
214 fatal_with_file_and_line (infile
, "unknown rtx code `%s'", name
);
218 uses_code_macro_p (rtx x
, int code
)
220 return (int) GET_CODE (x
) == code
;
224 apply_code_macro (rtx x
, int code
)
229 /* Given that MACRO is being expanded as VALUE, apply the appropriate
230 string substitutions to STRING. Return the new string if any changes
231 were needed, otherwise return STRING itself. */
234 apply_macro_to_string (const char *string
, struct mapping
*macro
, int value
)
236 char *base
, *copy
, *p
, *attr
, *start
, *end
;
243 base
= p
= copy
= ASTRDUP (string
);
244 while ((start
= index (p
, '<')) && (end
= index (start
, '>')))
248 /* If there's a "macro:" prefix, check whether the macro name matches.
249 Set ATTR to the start of the attribute name. */
250 attr
= index (p
, ':');
251 if (attr
== 0 || attr
> end
)
255 if (strncmp (p
, macro
->name
, attr
- p
) != 0
256 || macro
->name
[attr
- p
] != 0)
261 /* Find the attribute specification. */
263 m
= (struct mapping
*) htab_find (macro
->group
->attrs
, &attr
);
268 /* Find the attribute value for VALUE. */
269 for (v
= m
->values
; v
!= 0; v
= v
->next
)
270 if (v
->number
== value
)
275 /* Add everything between the last copied byte and the '<',
276 then add in the attribute value. */
277 obstack_grow (&string_obstack
, base
, start
- base
);
278 obstack_grow (&string_obstack
, v
->string
, strlen (v
->string
));
283 obstack_grow (&string_obstack
, base
, strlen (base
) + 1);
284 return (char *) obstack_finish (&string_obstack
);
289 /* Return a copy of ORIGINAL in which all uses of MACRO have been
290 replaced by VALUE. */
293 apply_macro_to_rtx (rtx original
, struct mapping
*macro
, int value
)
295 struct macro_group
*group
;
296 const char *format_ptr
;
299 enum rtx_code bellwether_code
;
304 /* Create a shallow copy of ORIGINAL. */
305 bellwether_code
= BELLWETHER_CODE (GET_CODE (original
));
306 x
= rtx_alloc (bellwether_code
);
307 memcpy (x
, original
, RTX_SIZE (bellwether_code
));
309 /* Change the mode or code itself. */
310 group
= macro
->group
;
311 if (group
->uses_macro_p (x
, macro
->index
+ group
->num_builtins
))
312 group
->apply_macro (x
, value
);
314 /* Change each string and recursively change each rtx. */
315 format_ptr
= GET_RTX_FORMAT (bellwether_code
);
316 for (i
= 0; format_ptr
[i
] != 0; i
++)
317 switch (format_ptr
[i
])
322 XSTR (x
, i
) = apply_macro_to_string (XSTR (x
, i
), macro
, value
);
326 XEXP (x
, i
) = apply_macro_to_rtx (XEXP (x
, i
), macro
, value
);
331 if (XVEC (original
, i
))
333 XVEC (x
, i
) = rtvec_alloc (XVECLEN (original
, i
));
334 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
335 XVECEXP (x
, i
, j
) = apply_macro_to_rtx (XVECEXP (original
, i
, j
),
346 /* Return true if X (or some subexpression of X) uses macro MACRO. */
349 uses_macro_p (rtx x
, struct mapping
*macro
)
351 struct macro_group
*group
;
352 const char *format_ptr
;
358 group
= macro
->group
;
359 if (group
->uses_macro_p (x
, macro
->index
+ group
->num_builtins
))
362 format_ptr
= GET_RTX_FORMAT (BELLWETHER_CODE (GET_CODE (x
)));
363 for (i
= 0; format_ptr
[i
] != 0; i
++)
364 switch (format_ptr
[i
])
367 if (uses_macro_p (XEXP (x
, i
), macro
))
374 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
375 if (uses_macro_p (XVECEXP (x
, i
, j
), macro
))
385 /* Return a condition that must satisfy both ORIGINAL and EXTRA. If ORIGINAL
386 has the form "&& ..." (as used in define_insn_and_splits), assume that
387 EXTRA is already satisfied. Empty strings are treated like "true". */
390 add_condition_to_string (const char *original
, const char *extra
)
394 if (original
== 0 || original
[0] == 0)
397 if ((original
[0] == '&' && original
[1] == '&') || extra
[0] == 0)
400 asprintf (&result
, "(%s) && (%s)", original
, extra
);
404 /* Like add_condition, but applied to all conditions in rtx X. */
407 add_condition_to_rtx (rtx x
, const char *extra
)
409 switch (GET_CODE (x
))
413 XSTR (x
, 2) = add_condition_to_string (XSTR (x
, 2), extra
);
417 case DEFINE_PEEPHOLE
:
418 case DEFINE_PEEPHOLE2
:
419 case DEFINE_COND_EXEC
:
420 XSTR (x
, 1) = add_condition_to_string (XSTR (x
, 1), extra
);
423 case DEFINE_INSN_AND_SPLIT
:
424 XSTR (x
, 2) = add_condition_to_string (XSTR (x
, 2), extra
);
425 XSTR (x
, 4) = add_condition_to_string (XSTR (x
, 4), extra
);
433 /* A htab_traverse callback. Search the EXPR_LIST given by DATA
434 for rtxes that use the macro in *SLOT. Replace each such rtx
435 with a list of expansions. */
438 apply_macro_traverse (void **slot
, void *data
)
440 struct mapping
*macro
;
442 rtx elem
, new_elem
, original
, x
;
444 macro
= (struct mapping
*) *slot
;
445 for (elem
= (rtx
) data
; elem
!= 0; elem
= XEXP (elem
, 1))
446 if (uses_macro_p (XEXP (elem
, 0), macro
))
448 original
= XEXP (elem
, 0);
449 for (v
= macro
->values
; v
!= 0; v
= v
->next
)
451 x
= apply_macro_to_rtx (original
, macro
, v
->number
);
452 add_condition_to_rtx (x
, v
->string
);
453 if (v
!= macro
->values
)
455 /* Insert a new EXPR_LIST node after ELEM and put the
456 new expansion there. */
457 new_elem
= rtx_alloc (EXPR_LIST
);
458 XEXP (new_elem
, 1) = XEXP (elem
, 1);
459 XEXP (elem
, 1) = new_elem
;
468 /* Add a new "mapping" structure to hashtable TABLE. NAME is the name
469 of the mapping, GROUP is the group to which it belongs, and INFILE
470 is the file that defined the mapping. */
472 static struct mapping
*
473 add_mapping (struct macro_group
*group
, htab_t table
,
474 const char *name
, FILE *infile
)
479 m
= XNEW (struct mapping
);
480 m
->name
= xstrdup (name
);
482 m
->index
= htab_elements (table
);
485 slot
= htab_find_slot (table
, m
, INSERT
);
487 fatal_with_file_and_line (infile
, "`%s' already defined", name
);
493 /* Add the pair (NUMBER, STRING) to a list of map_value structures.
494 END_PTR points to the current null terminator for the list; return
495 a pointer the new null terminator. */
497 static struct map_value
**
498 add_map_value (struct map_value
**end_ptr
, int number
, const char *string
)
500 struct map_value
*value
;
502 value
= XNEW (struct map_value
);
504 value
->number
= number
;
505 value
->string
= string
;
511 /* Do one-time initialization of the mode and code attributes. */
514 initialize_macros (void)
516 struct mapping
*lower
, *upper
;
517 struct map_value
**lower_ptr
, **upper_ptr
;
521 modes
.attrs
= htab_create (13, def_hash
, def_name_eq_p
, 0);
522 modes
.macros
= htab_create (13, def_hash
, def_name_eq_p
, 0);
523 modes
.num_builtins
= MAX_MACHINE_MODE
;
524 modes
.find_builtin
= find_mode
;
525 modes
.uses_macro_p
= uses_mode_macro_p
;
526 modes
.apply_macro
= apply_mode_macro
;
528 codes
.attrs
= htab_create (13, def_hash
, def_name_eq_p
, 0);
529 codes
.macros
= htab_create (13, def_hash
, def_name_eq_p
, 0);
530 codes
.num_builtins
= NUM_RTX_CODE
;
531 codes
.find_builtin
= find_code
;
532 codes
.uses_macro_p
= uses_code_macro_p
;
533 codes
.apply_macro
= apply_code_macro
;
535 lower
= add_mapping (&modes
, modes
.attrs
, "mode", 0);
536 upper
= add_mapping (&modes
, modes
.attrs
, "MODE", 0);
537 lower_ptr
= &lower
->values
;
538 upper_ptr
= &upper
->values
;
539 for (i
= 0; i
< MAX_MACHINE_MODE
; i
++)
541 copy
= xstrdup (GET_MODE_NAME (i
));
542 for (p
= copy
; *p
!= 0; p
++)
545 upper_ptr
= add_map_value (upper_ptr
, i
, GET_MODE_NAME (i
));
546 lower_ptr
= add_map_value (lower_ptr
, i
, copy
);
549 lower
= add_mapping (&codes
, codes
.attrs
, "code", 0);
550 upper
= add_mapping (&codes
, codes
.attrs
, "CODE", 0);
551 lower_ptr
= &lower
->values
;
552 upper_ptr
= &upper
->values
;
553 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
555 copy
= xstrdup (GET_RTX_NAME (i
));
556 for (p
= copy
; *p
!= 0; p
++)
559 lower_ptr
= add_map_value (lower_ptr
, i
, GET_RTX_NAME (i
));
560 upper_ptr
= add_map_value (upper_ptr
, i
, copy
);
564 /* Read chars from INFILE until a non-whitespace char
565 and return that. Comments, both Lisp style and C style,
566 are treated as whitespace.
567 Tools such as genflags use this function. */
570 read_skip_spaces (FILE *infile
)
583 case ' ': case '\t': case '\f': case '\r':
589 while (c
!= '\n' && c
!= EOF
);
598 fatal_expected_char (infile
, '*', c
);
601 while ((c
= getc (infile
)) && c
!= EOF
)
605 else if (prevc
== '*' && c
== '/')
618 /* Read an rtx code name into the buffer STR[].
619 It is terminated by any of the punctuation chars of rtx printed syntax. */
622 read_name (char *str
, FILE *infile
)
627 c
= read_skip_spaces (infile
);
632 if (c
== ' ' || c
== '\n' || c
== '\t' || c
== '\f' || c
== '\r')
634 if (c
== ':' || c
== ')' || c
== ']' || c
== '"' || c
== '/'
635 || c
== '(' || c
== '[')
644 fatal_with_file_and_line (infile
, "missing name or number");
652 /* Do constant expansion. */
653 struct md_constant
*def
;
658 struct md_constant tmp_def
;
661 def
= (struct md_constant
*) htab_find (md_constants
, &tmp_def
);
670 /* Subroutine of the string readers. Handles backslash escapes.
671 Caller has read the backslash, but not placed it into the obstack. */
673 read_escape (FILE *infile
)
675 int c
= getc (infile
);
679 /* Backslash-newline is replaced by nothing, as in C. */
684 /* \" \' \\ are replaced by the second character. */
690 /* Standard C string escapes:
693 all are passed through to the output string unmolested.
694 In normal use these wind up in a string constant processed
695 by the C compiler, which will translate them appropriately.
696 We do not bother checking that \[0-7] are followed by up to
697 two octal digits, or that \x is followed by N hex digits.
698 \? \u \U are left out because they are not in traditional C. */
699 case 'a': case 'b': case 'f': case 'n': case 'r': case 't': case 'v':
700 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
702 obstack_1grow (&string_obstack
, '\\');
705 /* \; makes stuff for a C string constant containing
708 obstack_grow (&string_obstack
, "\\n\\t", 4);
711 /* pass anything else through, but issue a warning. */
713 fprintf (stderr
, "%s:%d: warning: unrecognized escape \\%c\n",
714 read_rtx_filename
, read_rtx_lineno
, c
);
715 obstack_1grow (&string_obstack
, '\\');
719 obstack_1grow (&string_obstack
, c
);
723 /* Read a double-quoted string onto the obstack. Caller has scanned
724 the leading quote. */
726 read_quoted_string (FILE *infile
)
732 c
= getc (infile
); /* Read the string */
737 read_escape (infile
);
743 obstack_1grow (&string_obstack
, c
);
746 obstack_1grow (&string_obstack
, 0);
747 return (char *) obstack_finish (&string_obstack
);
750 /* Read a braced string (a la Tcl) onto the string obstack. Caller
751 has scanned the leading brace. Note that unlike quoted strings,
752 the outermost braces _are_ included in the string constant. */
754 read_braced_string (FILE *infile
)
757 int brace_depth
= 1; /* caller-processed */
758 unsigned long starting_read_rtx_lineno
= read_rtx_lineno
;
760 obstack_1grow (&string_obstack
, '{');
763 c
= getc (infile
); /* Read the string */
773 read_escape (infile
);
777 fatal_with_file_and_line
778 (infile
, "missing closing } for opening brace on line %lu",
779 starting_read_rtx_lineno
);
781 obstack_1grow (&string_obstack
, c
);
784 obstack_1grow (&string_obstack
, 0);
785 return (char *) obstack_finish (&string_obstack
);
788 /* Read some kind of string constant. This is the high-level routine
789 used by read_rtx. It handles surrounding parentheses, leading star,
790 and dispatch to the appropriate string constant reader. */
793 read_string (FILE *infile
, int star_if_braced
)
799 c
= read_skip_spaces (infile
);
803 c
= read_skip_spaces (infile
);
807 stringbuf
= read_quoted_string (infile
);
811 obstack_1grow (&string_obstack
, '*');
812 stringbuf
= read_braced_string (infile
);
815 fatal_with_file_and_line (infile
, "expected `\"' or `{', found `%c'", c
);
819 c
= read_skip_spaces (infile
);
821 fatal_expected_char (infile
, ')', c
);
827 /* Provide a version of a function to read a long long if the system does
829 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ)
830 HOST_WIDE_INT
atoll (const char *);
833 atoll (const char *p
)
836 HOST_WIDE_INT tmp_wide
;
848 HOST_WIDE_INT new_wide
= tmp_wide
*10 + (*p
- '0');
849 if (new_wide
< tmp_wide
)
851 /* Return INT_MAX equiv on overflow. */
852 tmp_wide
= (~(unsigned HOST_WIDE_INT
) 0) >> 1;
860 tmp_wide
= -tmp_wide
;
865 /* Given an object that starts with a char * name field, return a hash
866 code for its name. */
868 def_hash (const void *def
)
871 const char *string
= *(const char *const *) def
;
873 for (result
= i
= 0; *string
++ != '\0'; i
++)
874 result
+= ((unsigned char) *string
<< (i
% CHAR_BIT
));
878 /* Given two objects that start with char * name fields, return true if
879 they have the same name. */
881 def_name_eq_p (const void *def1
, const void *def2
)
883 return ! strcmp (*(const char *const *) def1
,
884 *(const char *const *) def2
);
887 /* INFILE is a FILE pointer to read text from. TMP_CHAR is a buffer suitable
888 to read a name or number into. Process a define_constants directive,
889 starting with the optional space after the "define_constants". */
891 read_constants (FILE *infile
, char *tmp_char
)
896 c
= read_skip_spaces (infile
);
898 fatal_expected_char (infile
, '[', c
);
901 defs
= htab_create (32, def_hash
, def_name_eq_p
, (htab_del
) 0);
902 /* Disable constant expansion during definition processing. */
904 while ( (c
= read_skip_spaces (infile
)) != ']')
906 struct md_constant
*def
;
910 fatal_expected_char (infile
, '(', c
);
911 def
= XNEW (struct md_constant
);
912 def
->name
= tmp_char
;
913 read_name (tmp_char
, infile
);
914 entry_ptr
= htab_find_slot (defs
, def
, INSERT
);
916 def
->name
= xstrdup (tmp_char
);
917 c
= read_skip_spaces (infile
);
919 read_name (tmp_char
, infile
);
922 def
->value
= xstrdup (tmp_char
);
927 def
= (struct md_constant
*) *entry_ptr
;
928 if (strcmp (def
->value
, tmp_char
))
929 fatal_with_file_and_line (infile
,
930 "redefinition of %s, was %s, now %s",
931 def
->name
, def
->value
, tmp_char
);
933 c
= read_skip_spaces (infile
);
935 fatal_expected_char (infile
, ')', c
);
938 c
= read_skip_spaces (infile
);
940 fatal_expected_char (infile
, ')', c
);
943 /* For every constant definition, call CALLBACK with two arguments:
944 a pointer a pointer to the constant definition and INFO.
945 Stops when CALLBACK returns zero. */
947 traverse_md_constants (htab_trav callback
, void *info
)
950 htab_traverse (md_constants
, callback
, info
);
954 validate_const_int (FILE *infile
, const char *string
)
960 while (*cp
&& ISSPACE (*cp
))
962 if (*cp
== '-' || *cp
== '+')
970 fatal_with_file_and_line (infile
, "invalid decimal constant \"%s\"\n", string
);
973 /* Search GROUP for a mode or code called NAME and return its numerical
974 identifier. INFILE is the file that contained NAME. */
977 find_macro (struct macro_group
*group
, const char *name
, FILE *infile
)
981 m
= (struct mapping
*) htab_find (group
->macros
, &name
);
983 return m
->index
+ group
->num_builtins
;
984 return group
->find_builtin (name
, infile
);
987 /* Finish reading a declaration of the form:
989 (define... <name> [<value1> ... <valuen>])
991 from INFILE, where each <valuei> is either a bare symbol name or a
992 "(<name> <string>)" pair. The "(define..." part has already been read.
994 Represent the declaration as a "mapping" structure; add it to TABLE
995 (which belongs to GROUP) and return it. */
997 static struct mapping
*
998 read_mapping (struct macro_group
*group
, htab_t table
, FILE *infile
)
1002 struct map_value
**end_ptr
;
1006 /* Read the mapping name and create a structure for it. */
1007 read_name (tmp_char
, infile
);
1008 m
= add_mapping (group
, table
, tmp_char
, infile
);
1010 c
= read_skip_spaces (infile
);
1012 fatal_expected_char (infile
, '[', c
);
1014 /* Read each value. */
1015 end_ptr
= &m
->values
;
1016 c
= read_skip_spaces (infile
);
1021 /* A bare symbol name that is implicitly paired to an
1024 read_name (tmp_char
, infile
);
1029 /* A "(name string)" pair. */
1030 read_name (tmp_char
, infile
);
1031 string
= read_string (infile
, false);
1032 c
= read_skip_spaces (infile
);
1034 fatal_expected_char (infile
, ')', c
);
1036 number
= group
->find_builtin (tmp_char
, infile
);
1037 end_ptr
= add_map_value (end_ptr
, number
, string
);
1038 c
= read_skip_spaces (infile
);
1042 c
= read_skip_spaces (infile
);
1044 fatal_expected_char (infile
, ')', c
);
1049 /* Check newly-created code macro MACRO to see whether every code has the
1050 same format. Initialize the macro's entry in bellwether_codes. */
1053 check_code_macro (struct mapping
*macro
, FILE *infile
)
1055 struct map_value
*v
;
1056 enum rtx_code bellwether
;
1058 bellwether
= macro
->values
->number
;
1059 for (v
= macro
->values
->next
; v
!= 0; v
= v
->next
)
1060 if (strcmp (GET_RTX_FORMAT (bellwether
), GET_RTX_FORMAT (v
->number
)) != 0)
1061 fatal_with_file_and_line (infile
, "code macro `%s' combines "
1062 "different rtx formats", macro
->name
);
1064 bellwether_codes
= XRESIZEVEC (enum rtx_code
, bellwether_codes
,
1066 bellwether_codes
[macro
->index
] = bellwether
;
1069 /* Read an rtx in printed representation from INFILE
1070 and return an actual rtx in core constructed accordingly.
1071 read_rtx is not used in the compiler proper, but rather in
1072 the utilities gen*.c that construct C code from machine descriptions. */
1075 read_rtx (FILE *infile
)
1077 static rtx queue_head
, queue_next
;
1080 /* Do one-time initialization. */
1081 if (queue_head
== 0)
1083 initialize_macros ();
1084 obstack_init (&string_obstack
);
1085 queue_head
= rtx_alloc (EXPR_LIST
);
1088 if (queue_next
== 0)
1090 queue_next
= queue_head
;
1092 XEXP (queue_next
, 0) = read_rtx_1 (infile
);
1093 XEXP (queue_next
, 1) = 0;
1095 htab_traverse (modes
.macros
, apply_macro_traverse
, queue_next
);
1096 htab_traverse (codes
.macros
, apply_macro_traverse
, queue_next
);
1099 return_rtx
= XEXP (queue_next
, 0);
1100 queue_next
= XEXP (queue_next
, 1);
1105 /* Subroutine of read_rtx that reads one construct from INFILE but
1106 doesn't apply any macros. */
1109 read_rtx_1 (FILE *infile
)
1112 RTX_CODE real_code
, bellwether_code
;
1113 const char *format_ptr
;
1114 /* tmp_char is a buffer used for reading decimal integers
1115 and names of rtx types and machine modes.
1116 Therefore, 256 must be enough. */
1121 HOST_WIDE_INT tmp_wide
;
1123 /* Linked list structure for making RTXs: */
1126 struct rtx_list
*next
;
1127 rtx value
; /* Value of this node. */
1131 c
= read_skip_spaces (infile
); /* Should be open paren. */
1133 fatal_expected_char (infile
, '(', c
);
1135 read_name (tmp_char
, infile
);
1136 if (strcmp (tmp_char
, "nil") == 0)
1138 /* (nil) stands for an expression that isn't there. */
1139 c
= read_skip_spaces (infile
);
1141 fatal_expected_char (infile
, ')', c
);
1144 if (strcmp (tmp_char
, "define_constants") == 0)
1146 read_constants (infile
, tmp_char
);
1149 if (strcmp (tmp_char
, "define_mode_attr") == 0)
1151 read_mapping (&modes
, modes
.attrs
, infile
);
1154 if (strcmp (tmp_char
, "define_mode_macro") == 0)
1156 read_mapping (&modes
, modes
.macros
, infile
);
1159 if (strcmp (tmp_char
, "define_code_attr") == 0)
1161 read_mapping (&codes
, codes
.attrs
, infile
);
1164 if (strcmp (tmp_char
, "define_code_macro") == 0)
1166 check_code_macro (read_mapping (&codes
, codes
.macros
, infile
), infile
);
1169 real_code
= find_macro (&codes
, tmp_char
, infile
);
1170 bellwether_code
= BELLWETHER_CODE (real_code
);
1172 /* If we end up with an insn expression then we free this space below. */
1173 return_rtx
= rtx_alloc (bellwether_code
);
1174 format_ptr
= GET_RTX_FORMAT (bellwether_code
);
1175 PUT_CODE (return_rtx
, real_code
);
1177 /* If what follows is `: mode ', read it and
1178 store the mode in the rtx. */
1180 i
= read_skip_spaces (infile
);
1183 read_name (tmp_char
, infile
);
1184 PUT_MODE (return_rtx
, find_macro (&modes
, tmp_char
, infile
));
1189 for (i
= 0; format_ptr
[i
] != 0; i
++)
1190 switch (format_ptr
[i
])
1192 /* 0 means a field for internal use only.
1193 Don't expect it to be present in the input. */
1199 XEXP (return_rtx
, i
) = read_rtx_1 (infile
);
1203 /* 'V' is an optional vector: if a closeparen follows,
1204 just store NULL for this element. */
1205 c
= read_skip_spaces (infile
);
1209 XVEC (return_rtx
, i
) = 0;
1212 /* Now process the vector. */
1216 /* Obstack to store scratch vector in. */
1217 struct obstack vector_stack
;
1218 int list_counter
= 0;
1219 rtvec return_vec
= NULL_RTVEC
;
1221 c
= read_skip_spaces (infile
);
1223 fatal_expected_char (infile
, '[', c
);
1225 /* Add expressions to a list, while keeping a count. */
1226 obstack_init (&vector_stack
);
1227 while ((c
= read_skip_spaces (infile
)) && c
!= ']')
1231 obstack_ptr_grow (&vector_stack
, read_rtx_1 (infile
));
1233 if (list_counter
> 0)
1235 return_vec
= rtvec_alloc (list_counter
);
1236 memcpy (&return_vec
->elem
[0], obstack_finish (&vector_stack
),
1237 list_counter
* sizeof (rtx
));
1239 XVEC (return_rtx
, i
) = return_vec
;
1240 obstack_free (&vector_stack
, NULL
);
1241 /* close bracket gotten */
1252 c
= read_skip_spaces (infile
);
1256 /* 'S' fields are optional and should be NULL if no string
1257 was given. Also allow normal 's' and 'T' strings to be
1258 omitted, treating them in the same way as empty strings. */
1259 XSTR (return_rtx
, i
) = (format_ptr
[i
] == 'S' ? NULL
: "");
1263 /* The output template slot of a DEFINE_INSN,
1264 DEFINE_INSN_AND_SPLIT, or DEFINE_PEEPHOLE automatically
1265 gets a star inserted as its first character, if it is
1266 written with a brace block instead of a string constant. */
1267 star_if_braced
= (format_ptr
[i
] == 'T');
1269 stringbuf
= read_string (infile
, star_if_braced
);
1271 /* For insn patterns, we want to provide a default name
1272 based on the file and line, like "*foo.md:12", if the
1273 given name is blank. These are only for define_insn and
1274 define_insn_and_split, to aid debugging. */
1275 if (*stringbuf
== '\0'
1277 && (GET_CODE (return_rtx
) == DEFINE_INSN
1278 || GET_CODE (return_rtx
) == DEFINE_INSN_AND_SPLIT
))
1281 const char *fn
= (read_rtx_filename
? read_rtx_filename
: "rtx");
1283 for (slash
= fn
; *slash
; slash
++)
1284 if (*slash
== '/' || *slash
== '\\' || *slash
== ':')
1286 obstack_1grow (&string_obstack
, '*');
1287 obstack_grow (&string_obstack
, fn
, strlen (fn
));
1288 sprintf (line_name
, ":%d", read_rtx_lineno
);
1289 obstack_grow (&string_obstack
, line_name
, strlen (line_name
)+1);
1290 stringbuf
= (char *) obstack_finish (&string_obstack
);
1294 XTMPL (return_rtx
, i
) = stringbuf
;
1296 XSTR (return_rtx
, i
) = stringbuf
;
1301 read_name (tmp_char
, infile
);
1302 validate_const_int (infile
, tmp_char
);
1303 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1304 tmp_wide
= atoi (tmp_char
);
1306 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1307 tmp_wide
= atol (tmp_char
);
1309 /* Prefer atoll over atoq, since the former is in the ISO C99 standard.
1310 But prefer not to use our hand-rolled function above either. */
1311 #if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ)
1312 tmp_wide
= atoll (tmp_char
);
1314 tmp_wide
= atoq (tmp_char
);
1318 XWINT (return_rtx
, i
) = tmp_wide
;
1323 read_name (tmp_char
, infile
);
1324 validate_const_int (infile
, tmp_char
);
1325 tmp_int
= atoi (tmp_char
);
1326 XINT (return_rtx
, i
) = tmp_int
;
1331 "switch format wrong in rtl.read_rtx(). format was: %c.\n",
1333 fprintf (stderr
, "\tfile position: %ld\n", ftell (infile
));
1337 c
= read_skip_spaces (infile
);
1339 fatal_expected_char (infile
, ')', c
);