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 /* Disable rtl checking; it conflicts with the macro handling. */
26 #undef ENABLE_RTL_CHECKING
29 #include "coretypes.h"
35 static htab_t md_constants
;
37 /* One element in a singly-linked list of (integer, string) pairs. */
39 struct map_value
*next
;
44 /* Maps a macro or attribute name to a list of (integer, string) pairs.
45 The integers are mode or code values; the strings are either C conditions
46 or attribute values. */
48 /* The name of the macro or attribute. */
51 /* The group (modes or codes) to which the macro or attribute belongs. */
52 struct macro_group
*group
;
54 /* Gives a unique number to the attribute or macro. Numbers are
55 allocated consecutively, starting at 0. */
58 /* The list of (integer, string) pairs. */
59 struct map_value
*values
;
62 /* A structure for abstracting the common parts of code and mode macros. */
64 /* Tables of "mapping" structures, one for attributes and one for macros. */
67 /* The number of "real" modes or codes (and by extension, the first
68 number available for use as a macro placeholder). */
71 /* Treat the given string as the name of a standard mode or code and
72 return its integer value. Use the given file for error reporting. */
73 int (*find_builtin
) (const char *, FILE *);
75 /* Return true if the given rtx uses the given mode or code. */
76 bool (*uses_macro_p
) (rtx
, int);
78 /* Make the given rtx use the given mode or code. */
79 void (*apply_macro
) (rtx
, int);
82 /* If CODE is the number of a code macro, return a real rtx code that
83 has the same format. Return CODE otherwise. */
84 #define BELLWETHER_CODE(CODE) \
85 ((CODE) < NUM_RTX_CODE ? CODE : bellwether_codes[CODE - NUM_RTX_CODE])
87 static void fatal_with_file_and_line (FILE *, const char *, ...)
88 ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN
;
89 static void fatal_expected_char (FILE *, int, int) ATTRIBUTE_NORETURN
;
90 static int find_mode (const char *, FILE *);
91 static bool uses_mode_macro_p (rtx
, int);
92 static void apply_mode_macro (rtx
, int);
93 static int find_code (const char *, FILE *);
94 static bool uses_code_macro_p (rtx
, int);
95 static void apply_code_macro (rtx
, int);
96 static const char *apply_macro_to_string (const char *, struct mapping
*, int);
97 static rtx
apply_macro_to_rtx (rtx
, struct mapping
*, int);
98 static bool uses_macro_p (rtx
, struct mapping
*);
99 static const char *add_condition_to_string (const char *, const char *);
100 static void add_condition_to_rtx (rtx
, const char *);
101 static int apply_macro_traverse (void **, void *);
102 static struct mapping
*add_mapping (struct macro_group
*, htab_t t
,
103 const char *, FILE *);
104 static struct map_value
**add_map_value (struct map_value
**,
106 static void initialize_macros (void);
107 static void read_name (char *, FILE *);
108 static char *read_string (FILE *, int);
109 static char *read_quoted_string (FILE *);
110 static char *read_braced_string (FILE *);
111 static void read_escape (FILE *);
112 static hashval_t
def_hash (const void *);
113 static int def_name_eq_p (const void *, const void *);
114 static void read_constants (FILE *infile
, char *tmp_char
);
115 static void validate_const_int (FILE *, const char *);
116 static int find_macro (struct macro_group
*, const char *, FILE *);
117 static struct mapping
*read_mapping (struct macro_group
*, htab_t
, FILE *);
118 static void check_code_macro (struct mapping
*, FILE *);
119 static rtx
read_rtx_1 (FILE *);
121 /* The mode and code macro structures. */
122 static struct macro_group modes
, codes
;
124 /* Index I is the value of BELLWETHER_CODE (I + NUM_RTX_CODE). */
125 static enum rtx_code
*bellwether_codes
;
127 /* Obstack used for allocating RTL strings. */
128 static struct obstack string_obstack
;
130 /* Subroutines of read_rtx. */
132 /* The current line number for the file. */
133 int read_rtx_lineno
= 1;
135 /* The filename for aborting with file and line. */
136 const char *read_rtx_filename
= "<unknown>";
139 fatal_with_file_and_line (FILE *infile
, const char *msg
, ...)
148 fprintf (stderr
, "%s:%d: ", read_rtx_filename
, read_rtx_lineno
);
149 vfprintf (stderr
, msg
, ap
);
152 /* Gather some following context. */
153 for (i
= 0; i
< sizeof (context
)-1; ++i
)
158 if (c
== '\r' || c
== '\n')
164 fprintf (stderr
, "%s:%d: following context is `%s'\n",
165 read_rtx_filename
, read_rtx_lineno
, context
);
171 /* Dump code after printing a message. Used when read_rtx finds
175 fatal_expected_char (FILE *infile
, int expected_c
, int actual_c
)
177 fatal_with_file_and_line (infile
, "expected character `%c', found `%c'",
178 expected_c
, actual_c
);
181 /* Implementations of the macro_group callbacks for modes. */
184 find_mode (const char *name
, FILE *infile
)
188 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
189 if (strcmp (GET_MODE_NAME (i
), name
) == 0)
192 fatal_with_file_and_line (infile
, "unknown mode `%s'", name
);
196 uses_mode_macro_p (rtx x
, int mode
)
198 return (int) GET_MODE (x
) == mode
;
202 apply_mode_macro (rtx x
, int mode
)
207 /* Implementations of the macro_group callbacks for codes. */
210 find_code (const char *name
, FILE *infile
)
214 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
215 if (strcmp (GET_RTX_NAME (i
), name
) == 0)
218 fatal_with_file_and_line (infile
, "unknown rtx code `%s'", name
);
222 uses_code_macro_p (rtx x
, int code
)
224 return (int) GET_CODE (x
) == code
;
228 apply_code_macro (rtx x
, int code
)
233 /* Given that MACRO is being expanded as VALUE, apply the appropriate
234 string substitutions to STRING. Return the new string if any changes
235 were needed, otherwise return STRING itself. */
238 apply_macro_to_string (const char *string
, struct mapping
*macro
, int value
)
240 char *base
, *copy
, *p
, *attr
, *start
, *end
;
247 base
= p
= copy
= ASTRDUP (string
);
248 while ((start
= strchr (p
, '<')) && (end
= strchr (start
, '>')))
252 /* If there's a "macro:" prefix, check whether the macro name matches.
253 Set ATTR to the start of the attribute name. */
254 attr
= strchr (p
, ':');
255 if (attr
== 0 || attr
> end
)
259 if (strncmp (p
, macro
->name
, attr
- p
) != 0
260 || macro
->name
[attr
- p
] != 0)
265 /* Find the attribute specification. */
267 m
= (struct mapping
*) htab_find (macro
->group
->attrs
, &attr
);
272 /* Find the attribute value for VALUE. */
273 for (v
= m
->values
; v
!= 0; v
= v
->next
)
274 if (v
->number
== value
)
279 /* Add everything between the last copied byte and the '<',
280 then add in the attribute value. */
281 obstack_grow (&string_obstack
, base
, start
- base
);
282 obstack_grow (&string_obstack
, v
->string
, strlen (v
->string
));
287 obstack_grow (&string_obstack
, base
, strlen (base
) + 1);
288 return (char *) obstack_finish (&string_obstack
);
293 /* Return a copy of ORIGINAL in which all uses of MACRO have been
294 replaced by VALUE. */
297 apply_macro_to_rtx (rtx original
, struct mapping
*macro
, int value
)
299 struct macro_group
*group
;
300 const char *format_ptr
;
303 enum rtx_code bellwether_code
;
308 /* Create a shallow copy of ORIGINAL. */
309 bellwether_code
= BELLWETHER_CODE (GET_CODE (original
));
310 x
= rtx_alloc (bellwether_code
);
311 memcpy (x
, original
, RTX_SIZE (bellwether_code
));
313 /* Change the mode or code itself. */
314 group
= macro
->group
;
315 if (group
->uses_macro_p (x
, macro
->index
+ group
->num_builtins
))
316 group
->apply_macro (x
, value
);
318 /* Change each string and recursively change each rtx. */
319 format_ptr
= GET_RTX_FORMAT (bellwether_code
);
320 for (i
= 0; format_ptr
[i
] != 0; i
++)
321 switch (format_ptr
[i
])
324 XTMPL (x
, i
) = apply_macro_to_string (XTMPL (x
, i
), macro
, value
);
329 XSTR (x
, i
) = apply_macro_to_string (XSTR (x
, i
), macro
, value
);
333 XEXP (x
, i
) = apply_macro_to_rtx (XEXP (x
, i
), macro
, value
);
338 if (XVEC (original
, i
))
340 XVEC (x
, i
) = rtvec_alloc (XVECLEN (original
, i
));
341 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
342 XVECEXP (x
, i
, j
) = apply_macro_to_rtx (XVECEXP (original
, i
, j
),
353 /* Return true if X (or some subexpression of X) uses macro MACRO. */
356 uses_macro_p (rtx x
, struct mapping
*macro
)
358 struct macro_group
*group
;
359 const char *format_ptr
;
365 group
= macro
->group
;
366 if (group
->uses_macro_p (x
, macro
->index
+ group
->num_builtins
))
369 format_ptr
= GET_RTX_FORMAT (BELLWETHER_CODE (GET_CODE (x
)));
370 for (i
= 0; format_ptr
[i
] != 0; i
++)
371 switch (format_ptr
[i
])
374 if (uses_macro_p (XEXP (x
, i
), macro
))
381 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
382 if (uses_macro_p (XVECEXP (x
, i
, j
), macro
))
392 /* Return a condition that must satisfy both ORIGINAL and EXTRA. If ORIGINAL
393 has the form "&& ..." (as used in define_insn_and_splits), assume that
394 EXTRA is already satisfied. Empty strings are treated like "true". */
397 add_condition_to_string (const char *original
, const char *extra
)
401 if (original
== 0 || original
[0] == 0)
404 if ((original
[0] == '&' && original
[1] == '&') || extra
[0] == 0)
407 asprintf (&result
, "(%s) && (%s)", original
, extra
);
411 /* Like add_condition, but applied to all conditions in rtx X. */
414 add_condition_to_rtx (rtx x
, const char *extra
)
416 switch (GET_CODE (x
))
420 XSTR (x
, 2) = add_condition_to_string (XSTR (x
, 2), extra
);
424 case DEFINE_PEEPHOLE
:
425 case DEFINE_PEEPHOLE2
:
426 case DEFINE_COND_EXEC
:
427 XSTR (x
, 1) = add_condition_to_string (XSTR (x
, 1), extra
);
430 case DEFINE_INSN_AND_SPLIT
:
431 XSTR (x
, 2) = add_condition_to_string (XSTR (x
, 2), extra
);
432 XSTR (x
, 4) = add_condition_to_string (XSTR (x
, 4), extra
);
440 /* A htab_traverse callback. Search the EXPR_LIST given by DATA
441 for rtxes that use the macro in *SLOT. Replace each such rtx
442 with a list of expansions. */
445 apply_macro_traverse (void **slot
, void *data
)
447 struct mapping
*macro
;
449 rtx elem
, new_elem
, original
, x
;
451 macro
= (struct mapping
*) *slot
;
452 for (elem
= (rtx
) data
; elem
!= 0; elem
= XEXP (elem
, 1))
453 if (uses_macro_p (XEXP (elem
, 0), macro
))
455 original
= XEXP (elem
, 0);
456 for (v
= macro
->values
; v
!= 0; v
= v
->next
)
458 x
= apply_macro_to_rtx (original
, macro
, v
->number
);
459 add_condition_to_rtx (x
, v
->string
);
460 if (v
!= macro
->values
)
462 /* Insert a new EXPR_LIST node after ELEM and put the
463 new expansion there. */
464 new_elem
= rtx_alloc (EXPR_LIST
);
465 XEXP (new_elem
, 1) = XEXP (elem
, 1);
466 XEXP (elem
, 1) = new_elem
;
475 /* Add a new "mapping" structure to hashtable TABLE. NAME is the name
476 of the mapping, GROUP is the group to which it belongs, and INFILE
477 is the file that defined the mapping. */
479 static struct mapping
*
480 add_mapping (struct macro_group
*group
, htab_t table
,
481 const char *name
, FILE *infile
)
486 m
= XNEW (struct mapping
);
487 m
->name
= xstrdup (name
);
489 m
->index
= htab_elements (table
);
492 slot
= htab_find_slot (table
, m
, INSERT
);
494 fatal_with_file_and_line (infile
, "`%s' already defined", name
);
500 /* Add the pair (NUMBER, STRING) to a list of map_value structures.
501 END_PTR points to the current null terminator for the list; return
502 a pointer the new null terminator. */
504 static struct map_value
**
505 add_map_value (struct map_value
**end_ptr
, int number
, const char *string
)
507 struct map_value
*value
;
509 value
= XNEW (struct map_value
);
511 value
->number
= number
;
512 value
->string
= string
;
518 /* Do one-time initialization of the mode and code attributes. */
521 initialize_macros (void)
523 struct mapping
*lower
, *upper
;
524 struct map_value
**lower_ptr
, **upper_ptr
;
528 modes
.attrs
= htab_create (13, def_hash
, def_name_eq_p
, 0);
529 modes
.macros
= htab_create (13, def_hash
, def_name_eq_p
, 0);
530 modes
.num_builtins
= MAX_MACHINE_MODE
;
531 modes
.find_builtin
= find_mode
;
532 modes
.uses_macro_p
= uses_mode_macro_p
;
533 modes
.apply_macro
= apply_mode_macro
;
535 codes
.attrs
= htab_create (13, def_hash
, def_name_eq_p
, 0);
536 codes
.macros
= htab_create (13, def_hash
, def_name_eq_p
, 0);
537 codes
.num_builtins
= NUM_RTX_CODE
;
538 codes
.find_builtin
= find_code
;
539 codes
.uses_macro_p
= uses_code_macro_p
;
540 codes
.apply_macro
= apply_code_macro
;
542 lower
= add_mapping (&modes
, modes
.attrs
, "mode", 0);
543 upper
= add_mapping (&modes
, modes
.attrs
, "MODE", 0);
544 lower_ptr
= &lower
->values
;
545 upper_ptr
= &upper
->values
;
546 for (i
= 0; i
< MAX_MACHINE_MODE
; i
++)
548 copy
= xstrdup (GET_MODE_NAME (i
));
549 for (p
= copy
; *p
!= 0; p
++)
552 upper_ptr
= add_map_value (upper_ptr
, i
, GET_MODE_NAME (i
));
553 lower_ptr
= add_map_value (lower_ptr
, i
, copy
);
556 lower
= add_mapping (&codes
, codes
.attrs
, "code", 0);
557 upper
= add_mapping (&codes
, codes
.attrs
, "CODE", 0);
558 lower_ptr
= &lower
->values
;
559 upper_ptr
= &upper
->values
;
560 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
562 copy
= xstrdup (GET_RTX_NAME (i
));
563 for (p
= copy
; *p
!= 0; p
++)
566 lower_ptr
= add_map_value (lower_ptr
, i
, GET_RTX_NAME (i
));
567 upper_ptr
= add_map_value (upper_ptr
, i
, copy
);
571 /* Read chars from INFILE until a non-whitespace char
572 and return that. Comments, both Lisp style and C style,
573 are treated as whitespace.
574 Tools such as genflags use this function. */
577 read_skip_spaces (FILE *infile
)
590 case ' ': case '\t': case '\f': case '\r':
596 while (c
!= '\n' && c
!= EOF
);
605 fatal_expected_char (infile
, '*', c
);
608 while ((c
= getc (infile
)) && c
!= EOF
)
612 else if (prevc
== '*' && c
== '/')
625 /* Read an rtx code name into the buffer STR[].
626 It is terminated by any of the punctuation chars of rtx printed syntax. */
629 read_name (char *str
, FILE *infile
)
634 c
= read_skip_spaces (infile
);
639 if (c
== ' ' || c
== '\n' || c
== '\t' || c
== '\f' || c
== '\r')
641 if (c
== ':' || c
== ')' || c
== ']' || c
== '"' || c
== '/'
642 || c
== '(' || c
== '[')
651 fatal_with_file_and_line (infile
, "missing name or number");
659 /* Do constant expansion. */
660 struct md_constant
*def
;
665 struct md_constant tmp_def
;
668 def
= (struct md_constant
*) htab_find (md_constants
, &tmp_def
);
677 /* Subroutine of the string readers. Handles backslash escapes.
678 Caller has read the backslash, but not placed it into the obstack. */
680 read_escape (FILE *infile
)
682 int c
= getc (infile
);
686 /* Backslash-newline is replaced by nothing, as in C. */
691 /* \" \' \\ are replaced by the second character. */
697 /* Standard C string escapes:
700 all are passed through to the output string unmolested.
701 In normal use these wind up in a string constant processed
702 by the C compiler, which will translate them appropriately.
703 We do not bother checking that \[0-7] are followed by up to
704 two octal digits, or that \x is followed by N hex digits.
705 \? \u \U are left out because they are not in traditional C. */
706 case 'a': case 'b': case 'f': case 'n': case 'r': case 't': case 'v':
707 case '0': case '1': case '2': case '3': case '4': case '5': case '6':
709 obstack_1grow (&string_obstack
, '\\');
712 /* \; makes stuff for a C string constant containing
715 obstack_grow (&string_obstack
, "\\n\\t", 4);
718 /* pass anything else through, but issue a warning. */
720 fprintf (stderr
, "%s:%d: warning: unrecognized escape \\%c\n",
721 read_rtx_filename
, read_rtx_lineno
, c
);
722 obstack_1grow (&string_obstack
, '\\');
726 obstack_1grow (&string_obstack
, c
);
730 /* Read a double-quoted string onto the obstack. Caller has scanned
731 the leading quote. */
733 read_quoted_string (FILE *infile
)
739 c
= getc (infile
); /* Read the string */
744 read_escape (infile
);
750 obstack_1grow (&string_obstack
, c
);
753 obstack_1grow (&string_obstack
, 0);
754 return (char *) obstack_finish (&string_obstack
);
757 /* Read a braced string (a la Tcl) onto the string obstack. Caller
758 has scanned the leading brace. Note that unlike quoted strings,
759 the outermost braces _are_ included in the string constant. */
761 read_braced_string (FILE *infile
)
764 int brace_depth
= 1; /* caller-processed */
765 unsigned long starting_read_rtx_lineno
= read_rtx_lineno
;
767 obstack_1grow (&string_obstack
, '{');
770 c
= getc (infile
); /* Read the string */
780 read_escape (infile
);
784 fatal_with_file_and_line
785 (infile
, "missing closing } for opening brace on line %lu",
786 starting_read_rtx_lineno
);
788 obstack_1grow (&string_obstack
, c
);
791 obstack_1grow (&string_obstack
, 0);
792 return (char *) obstack_finish (&string_obstack
);
795 /* Read some kind of string constant. This is the high-level routine
796 used by read_rtx. It handles surrounding parentheses, leading star,
797 and dispatch to the appropriate string constant reader. */
800 read_string (FILE *infile
, int star_if_braced
)
806 c
= read_skip_spaces (infile
);
810 c
= read_skip_spaces (infile
);
814 stringbuf
= read_quoted_string (infile
);
818 obstack_1grow (&string_obstack
, '*');
819 stringbuf
= read_braced_string (infile
);
822 fatal_with_file_and_line (infile
, "expected `\"' or `{', found `%c'", c
);
826 c
= read_skip_spaces (infile
);
828 fatal_expected_char (infile
, ')', c
);
834 /* Provide a version of a function to read a long long if the system does
836 #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ)
837 HOST_WIDE_INT
atoll (const char *);
840 atoll (const char *p
)
843 HOST_WIDE_INT tmp_wide
;
855 HOST_WIDE_INT new_wide
= tmp_wide
*10 + (*p
- '0');
856 if (new_wide
< tmp_wide
)
858 /* Return INT_MAX equiv on overflow. */
859 tmp_wide
= (~(unsigned HOST_WIDE_INT
) 0) >> 1;
867 tmp_wide
= -tmp_wide
;
872 /* Given an object that starts with a char * name field, return a hash
873 code for its name. */
875 def_hash (const void *def
)
878 const char *string
= *(const char *const *) def
;
880 for (result
= i
= 0; *string
++ != '\0'; i
++)
881 result
+= ((unsigned char) *string
<< (i
% CHAR_BIT
));
885 /* Given two objects that start with char * name fields, return true if
886 they have the same name. */
888 def_name_eq_p (const void *def1
, const void *def2
)
890 return ! strcmp (*(const char *const *) def1
,
891 *(const char *const *) def2
);
894 /* INFILE is a FILE pointer to read text from. TMP_CHAR is a buffer suitable
895 to read a name or number into. Process a define_constants directive,
896 starting with the optional space after the "define_constants". */
898 read_constants (FILE *infile
, char *tmp_char
)
903 c
= read_skip_spaces (infile
);
905 fatal_expected_char (infile
, '[', c
);
908 defs
= htab_create (32, def_hash
, def_name_eq_p
, (htab_del
) 0);
909 /* Disable constant expansion during definition processing. */
911 while ( (c
= read_skip_spaces (infile
)) != ']')
913 struct md_constant
*def
;
917 fatal_expected_char (infile
, '(', c
);
918 def
= XNEW (struct md_constant
);
919 def
->name
= tmp_char
;
920 read_name (tmp_char
, infile
);
921 entry_ptr
= htab_find_slot (defs
, def
, INSERT
);
923 def
->name
= xstrdup (tmp_char
);
924 c
= read_skip_spaces (infile
);
926 read_name (tmp_char
, infile
);
929 def
->value
= xstrdup (tmp_char
);
934 def
= (struct md_constant
*) *entry_ptr
;
935 if (strcmp (def
->value
, tmp_char
))
936 fatal_with_file_and_line (infile
,
937 "redefinition of %s, was %s, now %s",
938 def
->name
, def
->value
, tmp_char
);
940 c
= read_skip_spaces (infile
);
942 fatal_expected_char (infile
, ')', c
);
945 c
= read_skip_spaces (infile
);
947 fatal_expected_char (infile
, ')', c
);
950 /* For every constant definition, call CALLBACK with two arguments:
951 a pointer a pointer to the constant definition and INFO.
952 Stops when CALLBACK returns zero. */
954 traverse_md_constants (htab_trav callback
, void *info
)
957 htab_traverse (md_constants
, callback
, info
);
961 validate_const_int (FILE *infile
, const char *string
)
967 while (*cp
&& ISSPACE (*cp
))
969 if (*cp
== '-' || *cp
== '+')
977 fatal_with_file_and_line (infile
, "invalid decimal constant \"%s\"\n", string
);
980 /* Search GROUP for a mode or code called NAME and return its numerical
981 identifier. INFILE is the file that contained NAME. */
984 find_macro (struct macro_group
*group
, const char *name
, FILE *infile
)
988 m
= (struct mapping
*) htab_find (group
->macros
, &name
);
990 return m
->index
+ group
->num_builtins
;
991 return group
->find_builtin (name
, infile
);
994 /* Finish reading a declaration of the form:
996 (define... <name> [<value1> ... <valuen>])
998 from INFILE, where each <valuei> is either a bare symbol name or a
999 "(<name> <string>)" pair. The "(define..." part has already been read.
1001 Represent the declaration as a "mapping" structure; add it to TABLE
1002 (which belongs to GROUP) and return it. */
1004 static struct mapping
*
1005 read_mapping (struct macro_group
*group
, htab_t table
, FILE *infile
)
1009 struct map_value
**end_ptr
;
1013 /* Read the mapping name and create a structure for it. */
1014 read_name (tmp_char
, infile
);
1015 m
= add_mapping (group
, table
, tmp_char
, infile
);
1017 c
= read_skip_spaces (infile
);
1019 fatal_expected_char (infile
, '[', c
);
1021 /* Read each value. */
1022 end_ptr
= &m
->values
;
1023 c
= read_skip_spaces (infile
);
1028 /* A bare symbol name that is implicitly paired to an
1031 read_name (tmp_char
, infile
);
1036 /* A "(name string)" pair. */
1037 read_name (tmp_char
, infile
);
1038 string
= read_string (infile
, false);
1039 c
= read_skip_spaces (infile
);
1041 fatal_expected_char (infile
, ')', c
);
1043 number
= group
->find_builtin (tmp_char
, infile
);
1044 end_ptr
= add_map_value (end_ptr
, number
, string
);
1045 c
= read_skip_spaces (infile
);
1049 c
= read_skip_spaces (infile
);
1051 fatal_expected_char (infile
, ')', c
);
1056 /* Check newly-created code macro MACRO to see whether every code has the
1057 same format. Initialize the macro's entry in bellwether_codes. */
1060 check_code_macro (struct mapping
*macro
, FILE *infile
)
1062 struct map_value
*v
;
1063 enum rtx_code bellwether
;
1065 bellwether
= macro
->values
->number
;
1066 for (v
= macro
->values
->next
; v
!= 0; v
= v
->next
)
1067 if (strcmp (GET_RTX_FORMAT (bellwether
), GET_RTX_FORMAT (v
->number
)) != 0)
1068 fatal_with_file_and_line (infile
, "code macro `%s' combines "
1069 "different rtx formats", macro
->name
);
1071 bellwether_codes
= XRESIZEVEC (enum rtx_code
, bellwether_codes
,
1073 bellwether_codes
[macro
->index
] = bellwether
;
1076 /* Read an rtx in printed representation from INFILE and store its
1077 core representation in *X. Also store the line number of the
1078 opening '(' in *LINENO. Return true on success or false if the
1079 end of file has been reached.
1081 read_rtx is not used in the compiler proper, but rather in
1082 the utilities gen*.c that construct C code from machine descriptions. */
1085 read_rtx (FILE *infile
, rtx
*x
, int *lineno
)
1087 static rtx queue_head
, queue_next
;
1088 static int queue_lineno
;
1091 /* Do one-time initialization. */
1092 if (queue_head
== 0)
1094 initialize_macros ();
1095 obstack_init (&string_obstack
);
1096 queue_head
= rtx_alloc (EXPR_LIST
);
1099 if (queue_next
== 0)
1101 c
= read_skip_spaces (infile
);
1106 queue_next
= queue_head
;
1107 queue_lineno
= read_rtx_lineno
;
1108 XEXP (queue_next
, 0) = read_rtx_1 (infile
);
1109 XEXP (queue_next
, 1) = 0;
1111 htab_traverse (modes
.macros
, apply_macro_traverse
, queue_next
);
1112 htab_traverse (codes
.macros
, apply_macro_traverse
, queue_next
);
1115 *x
= XEXP (queue_next
, 0);
1116 *lineno
= queue_lineno
;
1117 queue_next
= XEXP (queue_next
, 1);
1122 /* Subroutine of read_rtx that reads one construct from INFILE but
1123 doesn't apply any macros. */
1126 read_rtx_1 (FILE *infile
)
1129 RTX_CODE real_code
, bellwether_code
;
1130 const char *format_ptr
;
1131 /* tmp_char is a buffer used for reading decimal integers
1132 and names of rtx types and machine modes.
1133 Therefore, 256 must be enough. */
1138 HOST_WIDE_INT tmp_wide
;
1140 /* Linked list structure for making RTXs: */
1143 struct rtx_list
*next
;
1144 rtx value
; /* Value of this node. */
1148 c
= read_skip_spaces (infile
); /* Should be open paren. */
1150 fatal_expected_char (infile
, '(', c
);
1152 read_name (tmp_char
, infile
);
1153 if (strcmp (tmp_char
, "nil") == 0)
1155 /* (nil) stands for an expression that isn't there. */
1156 c
= read_skip_spaces (infile
);
1158 fatal_expected_char (infile
, ')', c
);
1161 if (strcmp (tmp_char
, "define_constants") == 0)
1163 read_constants (infile
, tmp_char
);
1166 if (strcmp (tmp_char
, "define_mode_attr") == 0)
1168 read_mapping (&modes
, modes
.attrs
, infile
);
1171 if (strcmp (tmp_char
, "define_mode_macro") == 0)
1173 read_mapping (&modes
, modes
.macros
, infile
);
1176 if (strcmp (tmp_char
, "define_code_attr") == 0)
1178 read_mapping (&codes
, codes
.attrs
, infile
);
1181 if (strcmp (tmp_char
, "define_code_macro") == 0)
1183 check_code_macro (read_mapping (&codes
, codes
.macros
, infile
), infile
);
1186 real_code
= find_macro (&codes
, tmp_char
, infile
);
1187 bellwether_code
= BELLWETHER_CODE (real_code
);
1189 /* If we end up with an insn expression then we free this space below. */
1190 return_rtx
= rtx_alloc (bellwether_code
);
1191 format_ptr
= GET_RTX_FORMAT (bellwether_code
);
1192 PUT_CODE (return_rtx
, real_code
);
1194 /* If what follows is `: mode ', read it and
1195 store the mode in the rtx. */
1197 i
= read_skip_spaces (infile
);
1200 read_name (tmp_char
, infile
);
1201 PUT_MODE (return_rtx
, find_macro (&modes
, tmp_char
, infile
));
1206 for (i
= 0; format_ptr
[i
] != 0; i
++)
1207 switch (format_ptr
[i
])
1209 /* 0 means a field for internal use only.
1210 Don't expect it to be present in the input. */
1216 XEXP (return_rtx
, i
) = read_rtx_1 (infile
);
1220 /* 'V' is an optional vector: if a closeparen follows,
1221 just store NULL for this element. */
1222 c
= read_skip_spaces (infile
);
1226 XVEC (return_rtx
, i
) = 0;
1229 /* Now process the vector. */
1233 /* Obstack to store scratch vector in. */
1234 struct obstack vector_stack
;
1235 int list_counter
= 0;
1236 rtvec return_vec
= NULL_RTVEC
;
1238 c
= read_skip_spaces (infile
);
1240 fatal_expected_char (infile
, '[', c
);
1242 /* Add expressions to a list, while keeping a count. */
1243 obstack_init (&vector_stack
);
1244 while ((c
= read_skip_spaces (infile
)) && c
!= ']')
1248 obstack_ptr_grow (&vector_stack
, read_rtx_1 (infile
));
1250 if (list_counter
> 0)
1252 return_vec
= rtvec_alloc (list_counter
);
1253 memcpy (&return_vec
->elem
[0], obstack_finish (&vector_stack
),
1254 list_counter
* sizeof (rtx
));
1256 XVEC (return_rtx
, i
) = return_vec
;
1257 obstack_free (&vector_stack
, NULL
);
1258 /* close bracket gotten */
1269 c
= read_skip_spaces (infile
);
1273 /* 'S' fields are optional and should be NULL if no string
1274 was given. Also allow normal 's' and 'T' strings to be
1275 omitted, treating them in the same way as empty strings. */
1276 XSTR (return_rtx
, i
) = (format_ptr
[i
] == 'S' ? NULL
: "");
1280 /* The output template slot of a DEFINE_INSN,
1281 DEFINE_INSN_AND_SPLIT, or DEFINE_PEEPHOLE automatically
1282 gets a star inserted as its first character, if it is
1283 written with a brace block instead of a string constant. */
1284 star_if_braced
= (format_ptr
[i
] == 'T');
1286 stringbuf
= read_string (infile
, star_if_braced
);
1288 /* For insn patterns, we want to provide a default name
1289 based on the file and line, like "*foo.md:12", if the
1290 given name is blank. These are only for define_insn and
1291 define_insn_and_split, to aid debugging. */
1292 if (*stringbuf
== '\0'
1294 && (GET_CODE (return_rtx
) == DEFINE_INSN
1295 || GET_CODE (return_rtx
) == DEFINE_INSN_AND_SPLIT
))
1298 const char *fn
= (read_rtx_filename
? read_rtx_filename
: "rtx");
1300 for (slash
= fn
; *slash
; slash
++)
1301 if (*slash
== '/' || *slash
== '\\' || *slash
== ':')
1303 obstack_1grow (&string_obstack
, '*');
1304 obstack_grow (&string_obstack
, fn
, strlen (fn
));
1305 sprintf (line_name
, ":%d", read_rtx_lineno
);
1306 obstack_grow (&string_obstack
, line_name
, strlen (line_name
)+1);
1307 stringbuf
= (char *) obstack_finish (&string_obstack
);
1311 XTMPL (return_rtx
, i
) = stringbuf
;
1313 XSTR (return_rtx
, i
) = stringbuf
;
1318 read_name (tmp_char
, infile
);
1319 validate_const_int (infile
, tmp_char
);
1320 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1321 tmp_wide
= atoi (tmp_char
);
1323 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1324 tmp_wide
= atol (tmp_char
);
1326 /* Prefer atoll over atoq, since the former is in the ISO C99 standard.
1327 But prefer not to use our hand-rolled function above either. */
1328 #if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ)
1329 tmp_wide
= atoll (tmp_char
);
1331 tmp_wide
= atoq (tmp_char
);
1335 XWINT (return_rtx
, i
) = tmp_wide
;
1340 read_name (tmp_char
, infile
);
1341 validate_const_int (infile
, tmp_char
);
1342 tmp_int
= atoi (tmp_char
);
1343 XINT (return_rtx
, i
) = tmp_int
;
1348 "switch format wrong in rtl.read_rtx(). format was: %c.\n",
1350 fprintf (stderr
, "\tfile position: %ld\n", ftell (infile
));
1354 c
= read_skip_spaces (infile
);
1356 fatal_expected_char (infile
, ')', c
);