]>
Commit | Line | Data |
---|---|---|
6f29feb1 | 1 | /* Allocate and read RTL for GNU C Compiler. |
9311a396 | 2 | Copyright (C) 1987, 1988, 1991, 1994, 1997, 1998, 1999, 2000 |
c5c76735 | 3 | Free Software Foundation, Inc. |
6f29feb1 JW |
4 | |
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
e99215a3 RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
6f29feb1 JW |
21 | |
22 | ||
23 | #include "config.h" | |
670ee920 | 24 | #include "system.h" |
6f29feb1 | 25 | #include "rtl.h" |
a19a1b5d | 26 | #include "real.h" |
0dfa1860 | 27 | #include "bitmap.h" |
a3770a81 | 28 | #include "ggc.h" |
6f29feb1 | 29 | #include "obstack.h" |
17074a35 | 30 | #include "toplev.h" |
c25c12b8 | 31 | #include "hashtab.h" |
49886fe1 | 32 | |
6f29feb1 JW |
33 | #define obstack_chunk_alloc xmalloc |
34 | #define obstack_chunk_free free | |
6f29feb1 | 35 | |
6f29feb1 | 36 | \f |
aa0b4465 ZW |
37 | /* Calculate the format for CONST_DOUBLE. This depends on the relative |
38 | widths of HOST_WIDE_INT and REAL_VALUE_TYPE. | |
b6b4c6c6 RH |
39 | |
40 | We need to go out to e0wwwww, since REAL_ARITHMETIC assumes 16-bits | |
41 | per element in REAL_VALUE_TYPE. | |
42 | ||
aa0b4465 | 43 | This is duplicated in gengenrtl.c. |
b6b4c6c6 | 44 | |
aa0b4465 ZW |
45 | A number of places assume that there are always at least two 'w' |
46 | slots in a CONST_DOUBLE, so we provide them even if one would suffice. */ | |
b6b4c6c6 RH |
47 | |
48 | #ifdef REAL_ARITHMETIC | |
17dfb726 AM |
49 | # if MAX_LONG_DOUBLE_TYPE_SIZE == 96 |
50 | # define REAL_WIDTH \ | |
51 | (11*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT | |
52 | # else | |
53 | # if MAX_LONG_DOUBLE_TYPE_SIZE == 128 | |
54 | # define REAL_WIDTH \ | |
55 | (19*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT | |
56 | # else | |
57 | # if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT | |
58 | # define REAL_WIDTH \ | |
59 | (7*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT | |
60 | # endif | |
61 | # endif | |
62 | # endif | |
b6b4c6c6 RH |
63 | #endif /* REAL_ARITHMETIC */ |
64 | ||
65 | #ifndef REAL_WIDTH | |
17dfb726 AM |
66 | # if HOST_BITS_PER_WIDE_INT*2 >= MAX_LONG_DOUBLE_TYPE_SIZE |
67 | # define REAL_WIDTH 2 | |
68 | # else | |
69 | # if HOST_BITS_PER_WIDE_INT*3 >= MAX_LONG_DOUBLE_TYPE_SIZE | |
70 | # define REAL_WIDTH 3 | |
71 | # else | |
72 | # if HOST_BITS_PER_WIDE_INT*4 >= MAX_LONG_DOUBLE_TYPE_SIZE | |
73 | # define REAL_WIDTH 4 | |
74 | # endif | |
75 | # endif | |
76 | # endif | |
b6b4c6c6 RH |
77 | #endif /* REAL_WIDTH */ |
78 | ||
79 | #if REAL_WIDTH == 1 | |
17dfb726 | 80 | # define CONST_DOUBLE_FORMAT "e0ww" |
aa0b4465 | 81 | #else |
17dfb726 AM |
82 | # if REAL_WIDTH == 2 |
83 | # define CONST_DOUBLE_FORMAT "e0ww" | |
84 | # else | |
85 | # if REAL_WIDTH == 3 | |
86 | # define CONST_DOUBLE_FORMAT "e0www" | |
87 | # else | |
88 | # if REAL_WIDTH == 4 | |
89 | # define CONST_DOUBLE_FORMAT "e0wwww" | |
90 | # else | |
91 | # if REAL_WIDTH == 5 | |
92 | # define CONST_DOUBLE_FORMAT "e0wwwww" | |
93 | # else | |
94 | # define CONST_DOUBLE_FORMAT /* nothing - will cause syntax error */ | |
95 | # endif | |
96 | # endif | |
97 | # endif | |
98 | # endif | |
aa0b4465 ZW |
99 | #endif |
100 | ||
6f29feb1 | 101 | /* Indexed by rtx code, gives number of operands for an rtx with that code. |
aa0b4465 | 102 | Does NOT include rtx header data (code and links). */ |
6f29feb1 | 103 | |
aa0b4465 ZW |
104 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) sizeof FORMAT - 1 , |
105 | ||
106 | const int rtx_length[NUM_RTX_CODE + 1] = { | |
107 | #include "rtl.def" | |
108 | }; | |
109 | ||
110 | #undef DEF_RTL_EXPR | |
6f29feb1 JW |
111 | |
112 | /* Indexed by rtx code, gives the name of that kind of rtx, as a C string. */ | |
113 | ||
114 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME , | |
115 | ||
5f06c983 | 116 | const char * const rtx_name[] = { |
6f29feb1 JW |
117 | #include "rtl.def" /* rtl expressions are documented here */ |
118 | }; | |
119 | ||
120 | #undef DEF_RTL_EXPR | |
121 | ||
122 | /* Indexed by machine mode, gives the name of that machine mode. | |
123 | This name does not include the letters "mode". */ | |
124 | ||
a191f0ee | 125 | #define DEF_MACHMODE(SYM, NAME, CLASS, BITSIZE, SIZE, UNIT, WIDER) NAME, |
6f29feb1 | 126 | |
a4ec8d12 | 127 | const char * const mode_name[(int) MAX_MACHINE_MODE + 1] = { |
6f29feb1 | 128 | #include "machmode.def" |
913f68c1 JC |
129 | /* Add an extra field to avoid a core dump if someone tries to convert |
130 | MAX_MACHINE_MODE to a string. */ | |
131 | "" | |
6f29feb1 JW |
132 | }; |
133 | ||
134 | #undef DEF_MACHMODE | |
135 | ||
a191f0ee | 136 | /* Indexed by machine mode, gives the class mode for GET_MODE_CLASS. */ |
6f29feb1 | 137 | |
a191f0ee | 138 | #define DEF_MACHMODE(SYM, NAME, CLASS, BITSIZE, SIZE, UNIT, WIDER) CLASS, |
6f29feb1 | 139 | |
aa0b4465 | 140 | const enum mode_class mode_class[(int) MAX_MACHINE_MODE] = { |
6f29feb1 JW |
141 | #include "machmode.def" |
142 | }; | |
143 | ||
144 | #undef DEF_MACHMODE | |
145 | ||
a191f0ee RH |
146 | /* Indexed by machine mode, gives the length of the mode, in bits. |
147 | GET_MODE_BITSIZE uses this. */ | |
148 | ||
149 | #define DEF_MACHMODE(SYM, NAME, CLASS, BITSIZE, SIZE, UNIT, WIDER) BITSIZE, | |
150 | ||
151 | const unsigned int mode_bitsize[(int) MAX_MACHINE_MODE] = { | |
152 | #include "machmode.def" | |
153 | }; | |
154 | ||
155 | #undef DEF_MACHMODE | |
156 | ||
6f29feb1 JW |
157 | /* Indexed by machine mode, gives the length of the mode, in bytes. |
158 | GET_MODE_SIZE uses this. */ | |
159 | ||
a191f0ee | 160 | #define DEF_MACHMODE(SYM, NAME, CLASS, BITSIZE, SIZE, UNIT, WIDER) SIZE, |
6f29feb1 | 161 | |
770ae6cc | 162 | const unsigned int mode_size[(int) MAX_MACHINE_MODE] = { |
6f29feb1 JW |
163 | #include "machmode.def" |
164 | }; | |
165 | ||
166 | #undef DEF_MACHMODE | |
167 | ||
168 | /* Indexed by machine mode, gives the length of the mode's subunit. | |
169 | GET_MODE_UNIT_SIZE uses this. */ | |
170 | ||
a191f0ee | 171 | #define DEF_MACHMODE(SYM, NAME, CLASS, BITSIZE, SIZE, UNIT, WIDER) UNIT, |
6f29feb1 | 172 | |
770ae6cc | 173 | const unsigned int mode_unit_size[(int) MAX_MACHINE_MODE] = { |
6f29feb1 JW |
174 | #include "machmode.def" /* machine modes are documented here */ |
175 | }; | |
176 | ||
177 | #undef DEF_MACHMODE | |
178 | ||
179 | /* Indexed by machine mode, gives next wider natural mode | |
180 | (QI -> HI -> SI -> DI, etc.) Widening multiply instructions | |
181 | use this. */ | |
182 | ||
a191f0ee | 183 | #define DEF_MACHMODE(SYM, NAME, CLASS, BITSIZE, SIZE, UNIT, WIDER) \ |
913f68c1 | 184 | (unsigned char) WIDER, |
6f29feb1 | 185 | |
aa0b4465 | 186 | const unsigned char mode_wider_mode[(int) MAX_MACHINE_MODE] = { |
6f29feb1 JW |
187 | #include "machmode.def" /* machine modes are documented here */ |
188 | }; | |
189 | ||
190 | #undef DEF_MACHMODE | |
191 | ||
a191f0ee RH |
192 | #define DEF_MACHMODE(SYM, NAME, CLASS, BITSIZE, SIZE, UNIT, WIDER) \ |
193 | ((BITSIZE) >= HOST_BITS_PER_WIDE_INT) ? ~(unsigned HOST_WIDE_INT)0 : ((unsigned HOST_WIDE_INT) 1 << (BITSIZE)) - 1, | |
913f68c1 JC |
194 | |
195 | /* Indexed by machine mode, gives mask of significant bits in mode. */ | |
196 | ||
aa0b4465 | 197 | const unsigned HOST_WIDE_INT mode_mask_array[(int) MAX_MACHINE_MODE] = { |
913f68c1 JC |
198 | #include "machmode.def" |
199 | }; | |
200 | ||
aa0b4465 ZW |
201 | /* Indexed by mode class, gives the narrowest mode for each class. |
202 | The Q modes are always of width 1 (2 for complex) - it is impossible | |
a191f0ee RH |
203 | for any mode to be narrower. |
204 | ||
205 | Note that we use QImode instead of BImode for MODE_INT, since | |
206 | otherwise the middle end will try to use it for bitfields in | |
207 | structures and the like, which we do not want. Only the target | |
208 | md file should generate BImode widgets. */ | |
aa0b4465 ZW |
209 | |
210 | const enum machine_mode class_narrowest_mode[(int) MAX_MODE_CLASS] = { | |
211 | /* MODE_RANDOM */ VOIDmode, | |
212 | /* MODE_INT */ QImode, | |
213 | /* MODE_FLOAT */ QFmode, | |
214 | /* MODE_PARTIAL_INT */ PQImode, | |
215 | /* MODE_CC */ CCmode, | |
216 | /* MODE_COMPLEX_INT */ CQImode, | |
ff427764 BS |
217 | /* MODE_COMPLEX_FLOAT */ QCmode, |
218 | /* MODE_VECTOR_INT */ V2QImode, | |
219 | /* MODE_VECTOR_FLOAT */ V2SFmode | |
aa0b4465 | 220 | }; |
f590cca1 | 221 | |
4a39a918 | 222 | |
6f29feb1 JW |
223 | /* Indexed by rtx code, gives a sequence of operand-types for |
224 | rtx's of that code. The sequence is a C string in which | |
6dc42e49 | 225 | each character describes one operand. */ |
6f29feb1 | 226 | |
aa0b4465 | 227 | const char * const rtx_format[] = { |
6f29feb1 JW |
228 | /* "*" undefined. |
229 | can cause a warning message | |
230 | "0" field is unused (or used in a phase-dependent manner) | |
231 | prints nothing | |
232 | "i" an integer | |
233 | prints the integer | |
234 | "n" like "i", but prints entries from `note_insn_name' | |
c166a311 CH |
235 | "w" an integer of width HOST_BITS_PER_WIDE_INT |
236 | prints the integer | |
6f29feb1 JW |
237 | "s" a pointer to a string |
238 | prints the string | |
239 | "S" like "s", but optional: | |
240 | the containing rtx may end before this operand | |
241 | "e" a pointer to an rtl expression | |
242 | prints the expression | |
243 | "E" a pointer to a vector that points to a number of rtl expressions | |
244 | prints a list of the rtl expressions | |
245 | "V" like "E", but optional: | |
246 | the containing rtx may end before this operand | |
247 | "u" a pointer to another insn | |
0dfa1860 MM |
248 | prints the uid of the insn. |
249 | "b" is a pointer to a bitmap header. | |
250 | "t" is a tree pointer. */ | |
6f29feb1 JW |
251 | |
252 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT , | |
253 | #include "rtl.def" /* rtl expressions are defined here */ | |
254 | #undef DEF_RTL_EXPR | |
255 | }; | |
256 | ||
257 | /* Indexed by rtx code, gives a character representing the "class" of | |
258 | that rtx code. See rtl.def for documentation on the defined classes. */ | |
259 | ||
1f9a015e | 260 | const char rtx_class[] = { |
f590cca1 | 261 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) CLASS, |
6f29feb1 JW |
262 | #include "rtl.def" /* rtl expressions are defined here */ |
263 | #undef DEF_RTL_EXPR | |
264 | }; | |
265 | ||
266 | /* Names for kinds of NOTEs and REG_NOTEs. */ | |
267 | ||
d636c18c | 268 | const char * const note_insn_name[NOTE_INSN_MAX - NOTE_INSN_BIAS] = |
f590cca1 | 269 | { |
d636c18c | 270 | "", "NOTE_INSN_DELETED", |
f590cca1 RH |
271 | "NOTE_INSN_BLOCK_BEG", "NOTE_INSN_BLOCK_END", |
272 | "NOTE_INSN_LOOP_BEG", "NOTE_INSN_LOOP_END", | |
f590cca1 | 273 | "NOTE_INSN_LOOP_CONT", "NOTE_INSN_LOOP_VTOP", |
d636c18c | 274 | "NOTE_INSN_FUNCTION_END", "NOTE_INSN_SETJMP", |
f590cca1 RH |
275 | "NOTE_INSN_PROLOGUE_END", "NOTE_INSN_EPILOGUE_BEG", |
276 | "NOTE_INSN_DELETED_LABEL", "NOTE_INSN_FUNCTION_BEG", | |
277 | "NOTE_INSN_EH_REGION_BEG", "NOTE_INSN_EH_REGION_END", | |
b3b42a4d | 278 | "NOTE_INSN_REPEATED_LINE_NUMBER", "NOTE_INSN_RANGE_BEG", |
f590cca1 | 279 | "NOTE_INSN_RANGE_END", "NOTE_INSN_LIVE", |
994a57cd | 280 | "NOTE_INSN_BASIC_BLOCK", "NOTE_INSN_EXPECTED_VALUE" |
f590cca1 RH |
281 | }; |
282 | ||
283 | const char * const reg_note_name[] = | |
284 | { | |
285 | "", "REG_DEAD", "REG_INC", "REG_EQUIV", "REG_EQUAL", | |
286 | "REG_WAS_0", "REG_RETVAL", "REG_LIBCALL", "REG_NONNEG", | |
287 | "REG_NO_CONFLICT", "REG_UNUSED", "REG_CC_SETTER", "REG_CC_USER", | |
288 | "REG_LABEL", "REG_DEP_ANTI", "REG_DEP_OUTPUT", "REG_BR_PROB", | |
289 | "REG_EXEC_COUNT", "REG_NOALIAS", "REG_SAVE_AREA", "REG_BR_PRED", | |
290 | "REG_FRAME_RELATED_EXPR", "REG_EH_CONTEXT", "REG_EH_REGION", | |
4b01bd16 RH |
291 | "REG_EH_RETHROW", "REG_SAVE_NOTE", "REG_MAYBE_DEAD", "REG_NORETURN", |
292 | "REG_NON_LOCAL_GOTO" | |
f590cca1 | 293 | }; |
6f29feb1 | 294 | |
c25c12b8 R |
295 | static htab_t md_constants; |
296 | ||
cdadb1dd | 297 | static void fatal_with_file_and_line PARAMS ((FILE *, const char *, ...)) |
47ee9bcb | 298 | ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN; |
cdadb1dd KG |
299 | static void fatal_expected_char PARAMS ((FILE *, int, int)) ATTRIBUTE_NORETURN; |
300 | static void read_name PARAMS ((char *, FILE *)); | |
c25c12b8 R |
301 | static unsigned def_hash PARAMS ((const void *)); |
302 | static int def_name_eq_p PARAMS ((const void *, const void *)); | |
303 | static void read_constants PARAMS ((FILE *infile, char *tmp_char)); | |
fbfc1192 | 304 | |
956d6950 | 305 | \f |
6f29feb1 JW |
306 | /* Allocate an rtx vector of N elements. |
307 | Store the length, and initialize all elements to zero. */ | |
308 | ||
309 | rtvec | |
310 | rtvec_alloc (n) | |
311 | int n; | |
312 | { | |
313 | rtvec rt; | |
f590cca1 | 314 | |
1f8f4a0b | 315 | rt = ggc_alloc_rtvec (n); |
f8a83ee3 ZW |
316 | /* clear out the vector */ |
317 | memset (&rt->elem[0], 0, n * sizeof (rtx)); | |
6f29feb1 | 318 | |
395d53bb | 319 | PUT_NUM_ELEM (rt, n); |
6f29feb1 JW |
320 | return rt; |
321 | } | |
322 | ||
323 | /* Allocate an rtx of code CODE. The CODE is stored in the rtx; | |
324 | all the rest is initialized to zero. */ | |
325 | ||
326 | rtx | |
327 | rtx_alloc (code) | |
328 | RTX_CODE code; | |
329 | { | |
330 | rtx rt; | |
f8a83ee3 | 331 | int n = GET_RTX_LENGTH (code); |
6f29feb1 | 332 | |
1f8f4a0b | 333 | rt = ggc_alloc_rtx (n); |
a3770a81 | 334 | |
f8a83ee3 ZW |
335 | /* We want to clear everything up to the FLD array. Normally, this |
336 | is one int, but we don't want to assume that and it isn't very | |
337 | portable anyway; this is. */ | |
2151a093 | 338 | |
f8a83ee3 | 339 | memset (rt, 0, sizeof (struct rtx_def) - sizeof (rtunion)); |
6f29feb1 | 340 | PUT_CODE (rt, code); |
6f29feb1 JW |
341 | return rt; |
342 | } | |
9b404774 | 343 | |
6f29feb1 JW |
344 | \f |
345 | /* Create a new copy of an rtx. | |
346 | Recursively copies the operands of the rtx, | |
347 | except for those few rtx codes that are sharable. */ | |
348 | ||
349 | rtx | |
350 | copy_rtx (orig) | |
351 | register rtx orig; | |
352 | { | |
353 | register rtx copy; | |
354 | register int i, j; | |
355 | register RTX_CODE code; | |
6f7d635c | 356 | register const char *format_ptr; |
6f29feb1 JW |
357 | |
358 | code = GET_CODE (orig); | |
359 | ||
360 | switch (code) | |
361 | { | |
362 | case REG: | |
363 | case QUEUED: | |
364 | case CONST_INT: | |
365 | case CONST_DOUBLE: | |
366 | case SYMBOL_REF: | |
367 | case CODE_LABEL: | |
368 | case PC: | |
369 | case CC0: | |
cf526dcc | 370 | case SCRATCH: |
0f41302f | 371 | /* SCRATCH must be shared because they represent distinct values. */ |
e9a25f70 | 372 | case ADDRESSOF: |
6f29feb1 | 373 | return orig; |
cf526dcc RK |
374 | |
375 | case CONST: | |
376 | /* CONST can be shared if it contains a SYMBOL_REF. If it contains | |
377 | a LABEL_REF, it isn't sharable. */ | |
378 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
379 | && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF | |
380 | && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT) | |
381 | return orig; | |
382 | break; | |
383 | ||
cc81e625 JW |
384 | /* A MEM with a constant address is not sharable. The problem is that |
385 | the constant address may need to be reloaded. If the mem is shared, | |
386 | then reloading one copy of this mem will cause all copies to appear | |
387 | to have been reloaded. */ | |
e9a25f70 JL |
388 | |
389 | default: | |
390 | break; | |
6f29feb1 JW |
391 | } |
392 | ||
393 | copy = rtx_alloc (code); | |
a4c6502a MM |
394 | |
395 | /* Copy the various flags, and other information. We assume that | |
396 | all fields need copying, and then clear the fields that should | |
397 | not be copied. That is the sensible default behavior, and forces | |
398 | us to explicitly document why we are *not* copying a flag. */ | |
8db99db2 | 399 | memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion)); |
a4c6502a MM |
400 | |
401 | /* We do not copy the USED flag, which is used as a mark bit during | |
402 | walks over the RTL. */ | |
403 | copy->used = 0; | |
404 | ||
0a1c58a2 | 405 | /* We do not copy FRAME_RELATED for INSNs. */ |
a4c6502a | 406 | if (GET_RTX_CLASS (code) == 'i') |
0a1c58a2 JL |
407 | copy->frame_related = 0; |
408 | copy->jump = orig->jump; | |
409 | copy->call = orig->call; | |
410 | ||
6f29feb1 JW |
411 | format_ptr = GET_RTX_FORMAT (GET_CODE (copy)); |
412 | ||
413 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++) | |
414 | { | |
e63db8f6 | 415 | copy->fld[i] = orig->fld[i]; |
6f29feb1 JW |
416 | switch (*format_ptr++) |
417 | { | |
418 | case 'e': | |
6f29feb1 JW |
419 | if (XEXP (orig, i) != NULL) |
420 | XEXP (copy, i) = copy_rtx (XEXP (orig, i)); | |
421 | break; | |
422 | ||
423 | case 'E': | |
424 | case 'V': | |
6f29feb1 JW |
425 | if (XVEC (orig, i) != NULL) |
426 | { | |
427 | XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i)); | |
428 | for (j = 0; j < XVECLEN (copy, i); j++) | |
429 | XVECEXP (copy, i, j) = copy_rtx (XVECEXP (orig, i, j)); | |
430 | } | |
431 | break; | |
432 | ||
0dfa1860 | 433 | case 't': |
c166a311 | 434 | case 'w': |
c166a311 | 435 | case 'i': |
c166a311 CH |
436 | case 's': |
437 | case 'S': | |
e63db8f6 | 438 | case 'u': |
ef178af3 | 439 | case '0': |
e63db8f6 | 440 | /* These are left unchanged. */ |
ef178af3 | 441 | break; |
f590cca1 | 442 | |
c166a311 CH |
443 | default: |
444 | abort (); | |
6f29feb1 JW |
445 | } |
446 | } | |
447 | return copy; | |
448 | } | |
449 | ||
450 | /* Similar to `copy_rtx' except that if MAY_SHARE is present, it is | |
451 | placed in the result directly, rather than being copied. */ | |
452 | ||
453 | rtx | |
454 | copy_most_rtx (orig, may_share) | |
455 | register rtx orig; | |
456 | register rtx may_share; | |
457 | { | |
458 | register rtx copy; | |
459 | register int i, j; | |
460 | register RTX_CODE code; | |
6f7d635c | 461 | register const char *format_ptr; |
6f29feb1 JW |
462 | |
463 | if (orig == may_share) | |
464 | return orig; | |
465 | ||
466 | code = GET_CODE (orig); | |
467 | ||
468 | switch (code) | |
469 | { | |
470 | case REG: | |
471 | case QUEUED: | |
472 | case CONST_INT: | |
473 | case CONST_DOUBLE: | |
474 | case SYMBOL_REF: | |
475 | case CODE_LABEL: | |
476 | case PC: | |
477 | case CC0: | |
478 | return orig; | |
e9a25f70 JL |
479 | default: |
480 | break; | |
6f29feb1 JW |
481 | } |
482 | ||
483 | copy = rtx_alloc (code); | |
484 | PUT_MODE (copy, GET_MODE (orig)); | |
485 | copy->in_struct = orig->in_struct; | |
486 | copy->volatil = orig->volatil; | |
487 | copy->unchanging = orig->unchanging; | |
488 | copy->integrated = orig->integrated; | |
715e2ab1 | 489 | copy->frame_related = orig->frame_related; |
f590cca1 | 490 | |
6f29feb1 JW |
491 | format_ptr = GET_RTX_FORMAT (GET_CODE (copy)); |
492 | ||
493 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++) | |
494 | { | |
495 | switch (*format_ptr++) | |
496 | { | |
497 | case 'e': | |
498 | XEXP (copy, i) = XEXP (orig, i); | |
499 | if (XEXP (orig, i) != NULL && XEXP (orig, i) != may_share) | |
500 | XEXP (copy, i) = copy_most_rtx (XEXP (orig, i), may_share); | |
501 | break; | |
f1027406 RK |
502 | |
503 | case 'u': | |
504 | XEXP (copy, i) = XEXP (orig, i); | |
505 | break; | |
6f29feb1 JW |
506 | |
507 | case 'E': | |
508 | case 'V': | |
509 | XVEC (copy, i) = XVEC (orig, i); | |
510 | if (XVEC (orig, i) != NULL) | |
511 | { | |
512 | XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i)); | |
513 | for (j = 0; j < XVECLEN (copy, i); j++) | |
514 | XVECEXP (copy, i, j) | |
515 | = copy_most_rtx (XVECEXP (orig, i, j), may_share); | |
516 | } | |
517 | break; | |
518 | ||
c166a311 CH |
519 | case 'w': |
520 | XWINT (copy, i) = XWINT (orig, i); | |
521 | break; | |
522 | ||
523 | case 'n': | |
524 | case 'i': | |
6f29feb1 JW |
525 | XINT (copy, i) = XINT (orig, i); |
526 | break; | |
c166a311 | 527 | |
8f985ec4 ZW |
528 | case 't': |
529 | XTREE (copy, i) = XTREE (orig, i); | |
530 | break; | |
531 | ||
c166a311 CH |
532 | case 's': |
533 | case 'S': | |
534 | XSTR (copy, i) = XSTR (orig, i); | |
535 | break; | |
536 | ||
ef178af3 ZW |
537 | case '0': |
538 | /* Copy this through the wide int field; that's safest. */ | |
539 | X0WINT (copy, i) = X0WINT (orig, i); | |
540 | break; | |
541 | ||
c166a311 CH |
542 | default: |
543 | abort (); | |
6f29feb1 JW |
544 | } |
545 | } | |
546 | return copy; | |
547 | } | |
ce9d4c6d R |
548 | |
549 | /* Create a new copy of an rtx. Only copy just one level. */ | |
550 | rtx | |
551 | shallow_copy_rtx (orig) | |
552 | rtx orig; | |
553 | { | |
554 | register int i; | |
ce9d4c6d R |
555 | register RTX_CODE code = GET_CODE (orig); |
556 | register rtx copy = rtx_alloc (code); | |
557 | ||
558 | PUT_MODE (copy, GET_MODE (orig)); | |
559 | copy->in_struct = orig->in_struct; | |
560 | copy->volatil = orig->volatil; | |
561 | copy->unchanging = orig->unchanging; | |
562 | copy->integrated = orig->integrated; | |
715e2ab1 | 563 | copy->frame_related = orig->frame_related; |
ce9d4c6d R |
564 | |
565 | for (i = 0; i < GET_RTX_LENGTH (code); i++) | |
566 | copy->fld[i] = orig->fld[i]; | |
567 | ||
568 | return copy; | |
569 | } | |
6f29feb1 | 570 | \f |
b5ee7789 CM |
571 | /* This is 1 until after the rtl generation pass. */ |
572 | int rtx_equal_function_value_matters; | |
1b3d8f8a GK |
573 | |
574 | /* Nonzero when we are generating CONCATs. */ | |
575 | int generating_concat_p; | |
b5ee7789 CM |
576 | \f |
577 | /* Return 1 if X and Y are identical-looking rtx's. | |
578 | This is the Lisp function EQUAL for rtx arguments. */ | |
579 | ||
580 | int | |
581 | rtx_equal_p (x, y) | |
582 | rtx x, y; | |
583 | { | |
584 | register int i; | |
585 | register int j; | |
586 | register enum rtx_code code; | |
587 | register const char *fmt; | |
588 | ||
589 | if (x == y) | |
590 | return 1; | |
591 | if (x == 0 || y == 0) | |
592 | return 0; | |
593 | ||
594 | code = GET_CODE (x); | |
595 | /* Rtx's of different codes cannot be equal. */ | |
596 | if (code != GET_CODE (y)) | |
597 | return 0; | |
598 | ||
599 | /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. | |
600 | (REG:SI x) and (REG:HI x) are NOT equivalent. */ | |
601 | ||
602 | if (GET_MODE (x) != GET_MODE (y)) | |
603 | return 0; | |
604 | ||
c13e8210 MM |
605 | /* Some RTL can be compared nonrecursively. */ |
606 | switch (code) | |
607 | { | |
608 | case REG: | |
609 | /* Until rtl generation is complete, don't consider a reference to the | |
610 | return register of the current function the same as the return from a | |
611 | called function. This eases the job of function integration. Once the | |
612 | distinction is no longer needed, they can be considered equivalent. */ | |
613 | return (REGNO (x) == REGNO (y) | |
614 | && (! rtx_equal_function_value_matters | |
615 | || REG_FUNCTION_VALUE_P (x) == REG_FUNCTION_VALUE_P (y))); | |
616 | ||
617 | case LABEL_REF: | |
618 | return XEXP (x, 0) == XEXP (y, 0); | |
619 | ||
620 | case SYMBOL_REF: | |
621 | return XSTR (x, 0) == XSTR (y, 0); | |
622 | ||
623 | case SCRATCH: | |
624 | case CONST_DOUBLE: | |
625 | case CONST_INT: | |
626 | return 0; | |
627 | ||
628 | default: | |
629 | break; | |
630 | } | |
b5ee7789 CM |
631 | |
632 | /* Compare the elements. If any pair of corresponding elements | |
633 | fail to match, return 0 for the whole things. */ | |
634 | ||
635 | fmt = GET_RTX_FORMAT (code); | |
636 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
637 | { | |
638 | switch (fmt[i]) | |
639 | { | |
640 | case 'w': | |
641 | if (XWINT (x, i) != XWINT (y, i)) | |
642 | return 0; | |
643 | break; | |
644 | ||
645 | case 'n': | |
646 | case 'i': | |
647 | if (XINT (x, i) != XINT (y, i)) | |
648 | return 0; | |
649 | break; | |
650 | ||
651 | case 'V': | |
652 | case 'E': | |
653 | /* Two vectors must have the same length. */ | |
654 | if (XVECLEN (x, i) != XVECLEN (y, i)) | |
655 | return 0; | |
656 | ||
657 | /* And the corresponding elements must match. */ | |
658 | for (j = 0; j < XVECLEN (x, i); j++) | |
659 | if (rtx_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0) | |
660 | return 0; | |
661 | break; | |
662 | ||
663 | case 'e': | |
664 | if (rtx_equal_p (XEXP (x, i), XEXP (y, i)) == 0) | |
665 | return 0; | |
666 | break; | |
667 | ||
668 | case 'S': | |
669 | case 's': | |
670 | if (strcmp (XSTR (x, i), XSTR (y, i))) | |
671 | return 0; | |
672 | break; | |
673 | ||
674 | case 'u': | |
675 | /* These are just backpointers, so they don't matter. */ | |
676 | break; | |
677 | ||
678 | case '0': | |
679 | case 't': | |
680 | break; | |
681 | ||
682 | /* It is believed that rtx's at this level will never | |
683 | contain anything but integers and other rtx's, | |
684 | except for within LABEL_REFs and SYMBOL_REFs. */ | |
685 | default: | |
686 | abort (); | |
687 | } | |
688 | } | |
689 | return 1; | |
690 | } | |
691 | \f | |
6f29feb1 JW |
692 | /* Subroutines of read_rtx. */ |
693 | ||
bcdaba58 RH |
694 | /* The current line number for the file. */ |
695 | int read_rtx_lineno = 1; | |
696 | ||
697 | /* The filename for aborting with file and line. */ | |
698 | const char *read_rtx_filename = "<unknown>"; | |
6f29feb1 JW |
699 | |
700 | static void | |
0c386769 | 701 | fatal_with_file_and_line VPARAMS ((FILE *infile, const char *msg, ...)) |
6f29feb1 | 702 | { |
bcdaba58 RH |
703 | #ifndef ANSI_PROTOTYPES |
704 | FILE *infile; | |
0c386769 | 705 | const char *msg; |
bcdaba58 RH |
706 | #endif |
707 | va_list ap; | |
708 | char context[64]; | |
709 | size_t i; | |
710 | int c; | |
711 | ||
0c386769 | 712 | VA_START (ap, msg); |
bcdaba58 RH |
713 | |
714 | #ifndef ANSI_PROTOTYPES | |
715 | infile = va_arg (ap, FILE *); | |
716 | msg = va_arg (ap, const char *); | |
717 | #endif | |
718 | ||
719 | fprintf (stderr, "%s:%d: ", read_rtx_filename, read_rtx_lineno); | |
0c386769 | 720 | vfprintf (stderr, msg, ap); |
bcdaba58 RH |
721 | putc ('\n', stderr); |
722 | ||
723 | /* Gather some following context. */ | |
724 | for (i = 0; i < sizeof(context)-1; ++i) | |
6f29feb1 JW |
725 | { |
726 | c = getc (infile); | |
bcdaba58 RH |
727 | if (c == EOF) |
728 | break; | |
729 | if (c == '\r' || c == '\n') | |
730 | break; | |
731 | context[i] = c; | |
6f29feb1 | 732 | } |
bcdaba58 RH |
733 | context[i] = '\0'; |
734 | ||
0c386769 | 735 | fprintf (stderr, "%s:%d: following context is `%s'\n", |
bcdaba58 RH |
736 | read_rtx_filename, read_rtx_lineno, context); |
737 | ||
738 | va_end (ap); | |
739 | exit (1); | |
740 | } | |
741 | ||
742 | /* Dump code after printing a message. Used when read_rtx finds | |
743 | invalid data. */ | |
744 | ||
745 | static void | |
746 | fatal_expected_char (infile, expected_c, actual_c) | |
747 | FILE *infile; | |
748 | int expected_c, actual_c; | |
749 | { | |
750 | fatal_with_file_and_line (infile, "expected character `%c', found `%c'", | |
751 | expected_c, actual_c); | |
6f29feb1 JW |
752 | } |
753 | ||
754 | /* Read chars from INFILE until a non-whitespace char | |
755 | and return that. Comments, both Lisp style and C style, | |
756 | are treated as whitespace. | |
757 | Tools such as genflags use this function. */ | |
758 | ||
759 | int | |
760 | read_skip_spaces (infile) | |
761 | FILE *infile; | |
762 | { | |
763 | register int c; | |
bcdaba58 | 764 | while (1) |
6f29feb1 | 765 | { |
bcdaba58 RH |
766 | c = getc (infile); |
767 | switch (c) | |
6f29feb1 | 768 | { |
bcdaba58 RH |
769 | case '\n': |
770 | read_rtx_lineno++; | |
771 | break; | |
772 | ||
773 | case ' ': case '\t': case '\f': case '\r': | |
774 | break; | |
775 | ||
776 | case ';': | |
f590cca1 | 777 | do |
bcdaba58 RH |
778 | c = getc (infile); |
779 | while (c != '\n' && c != EOF); | |
780 | read_rtx_lineno++; | |
781 | break; | |
782 | ||
783 | case '/': | |
784 | { | |
785 | register int prevc; | |
786 | c = getc (infile); | |
787 | if (c != '*') | |
788 | fatal_expected_char (infile, '*', c); | |
f590cca1 | 789 | |
bcdaba58 RH |
790 | prevc = 0; |
791 | while ((c = getc (infile)) && c != EOF) | |
792 | { | |
793 | if (c == '\n') | |
794 | read_rtx_lineno++; | |
795 | else if (prevc == '*' && c == '/') | |
796 | break; | |
797 | prevc = c; | |
798 | } | |
799 | } | |
800 | break; | |
801 | ||
802 | default: | |
803 | return c; | |
6f29feb1 | 804 | } |
6f29feb1 | 805 | } |
6f29feb1 JW |
806 | } |
807 | ||
808 | /* Read an rtx code name into the buffer STR[]. | |
809 | It is terminated by any of the punctuation chars of rtx printed syntax. */ | |
810 | ||
811 | static void | |
812 | read_name (str, infile) | |
813 | char *str; | |
814 | FILE *infile; | |
815 | { | |
816 | register char *p; | |
817 | register int c; | |
818 | ||
819 | c = read_skip_spaces(infile); | |
820 | ||
821 | p = str; | |
822 | while (1) | |
823 | { | |
824 | if (c == ' ' || c == '\n' || c == '\t' || c == '\f') | |
825 | break; | |
826 | if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/' | |
827 | || c == '(' || c == '[') | |
828 | { | |
829 | ungetc (c, infile); | |
830 | break; | |
831 | } | |
832 | *p++ = c; | |
833 | c = getc (infile); | |
834 | } | |
835 | if (p == str) | |
bcdaba58 RH |
836 | fatal_with_file_and_line (infile, "missing name or number"); |
837 | if (c == '\n') | |
838 | read_rtx_lineno++; | |
6f29feb1 JW |
839 | |
840 | *p = 0; | |
c25c12b8 R |
841 | |
842 | if (md_constants) | |
843 | { | |
844 | /* Do constant expansion. */ | |
845 | struct md_constant *def; | |
846 | ||
847 | p = str; | |
848 | do | |
849 | { | |
850 | struct md_constant tmp_def; | |
851 | ||
852 | tmp_def.name = p; | |
853 | def = htab_find (md_constants, &tmp_def); | |
854 | if (def) | |
855 | p = def->value; | |
856 | } while (def); | |
857 | if (p != str) | |
858 | strcpy (str, p); | |
859 | } | |
6f29feb1 JW |
860 | } |
861 | \f | |
cbe36725 RH |
862 | /* Provide a version of a function to read a long long if the system does |
863 | not provide one. */ | |
864 | #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ) | |
865 | HOST_WIDE_INT | |
866 | atoll(p) | |
867 | const char *p; | |
868 | { | |
869 | int neg = 0; | |
870 | HOST_WIDE_INT tmp_wide; | |
871 | ||
e9a780ec | 872 | while (ISSPACE(*p)) |
cbe36725 RH |
873 | p++; |
874 | if (*p == '-') | |
875 | neg = 1, p++; | |
876 | else if (*p == '+') | |
877 | p++; | |
878 | ||
879 | tmp_wide = 0; | |
e9a780ec | 880 | while (ISDIGIT(*p)) |
cbe36725 RH |
881 | { |
882 | HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0'); | |
883 | if (new_wide < tmp_wide) | |
884 | { | |
885 | /* Return INT_MAX equiv on overflow. */ | |
886 | tmp_wide = (~(unsigned HOST_WIDE_INT)0) >> 1; | |
887 | break; | |
888 | } | |
889 | tmp_wide = new_wide; | |
890 | p++; | |
891 | } | |
892 | ||
893 | if (neg) | |
894 | tmp_wide = -tmp_wide; | |
895 | return tmp_wide; | |
896 | } | |
897 | #endif | |
898 | ||
c25c12b8 R |
899 | /* Given a constant definition, return a hash code for its name. */ |
900 | static unsigned | |
901 | def_hash (def) | |
902 | const void *def; | |
903 | { | |
904 | unsigned result, i; | |
905 | const char *string = ((const struct md_constant *)def)->name; | |
906 | ||
907 | for (result = i = 0;*string++ != '\0'; i++) | |
908 | result += ((unsigned char) *string << (i % CHAR_BIT)); | |
909 | return result; | |
910 | } | |
911 | ||
912 | /* Given two constant definitions, return true if they have the same name. */ | |
913 | static int | |
914 | def_name_eq_p (def1, def2) | |
915 | const void *def1, *def2; | |
916 | { | |
917 | return ! strcmp (((const struct md_constant *)def1)->name, | |
918 | ((const struct md_constant *)def2)->name); | |
919 | } | |
920 | ||
921 | /* INFILE is a FILE pointer to read text from. TMP_CHAR is a buffer suitable | |
922 | to read a name or number into. Process a define_constants directive, | |
923 | starting with the optional space after the "define_constants". */ | |
924 | static void | |
925 | read_constants (infile, tmp_char) | |
926 | FILE *infile; | |
927 | char *tmp_char; | |
928 | { | |
929 | int c; | |
930 | htab_t defs; | |
931 | ||
932 | c = read_skip_spaces (infile); | |
933 | if (c != '[') | |
934 | fatal_expected_char (infile, '[', c); | |
935 | defs = md_constants; | |
936 | if (! defs) | |
937 | defs = htab_create (32, def_hash, def_name_eq_p, (htab_del) 0); | |
938 | /* Disable constant expansion during definition processing. */ | |
939 | md_constants = 0; | |
940 | while ( (c = read_skip_spaces (infile)) != ']') | |
941 | { | |
942 | struct md_constant *def; | |
943 | void **entry_ptr; | |
944 | ||
945 | if (c != '(') | |
946 | fatal_expected_char (infile, '(', c); | |
947 | def = xmalloc (sizeof (struct md_constant)); | |
948 | def->name = tmp_char; | |
949 | read_name (tmp_char, infile); | |
950 | entry_ptr = htab_find_slot (defs, def, TRUE); | |
951 | if (! *entry_ptr) | |
952 | def->name = xstrdup (tmp_char); | |
953 | c = read_skip_spaces (infile); | |
954 | ungetc (c, infile); | |
955 | read_name (tmp_char, infile); | |
956 | if (! *entry_ptr) | |
957 | { | |
958 | def->value = xstrdup (tmp_char); | |
959 | *entry_ptr = def; | |
960 | } | |
961 | else | |
962 | { | |
963 | def = *entry_ptr; | |
964 | if (strcmp (def->value, tmp_char)) | |
965 | fatal_with_file_and_line (infile, | |
966 | "redefinition of %s, was %s, now %s", | |
967 | def->name, def->value, tmp_char); | |
968 | } | |
969 | c = read_skip_spaces (infile); | |
970 | if (c != ')') | |
971 | fatal_expected_char (infile, ')', c); | |
972 | } | |
973 | md_constants = defs; | |
974 | c = read_skip_spaces (infile); | |
975 | if (c != ')') | |
976 | fatal_expected_char (infile, ')', c); | |
977 | } | |
978 | ||
979 | /* For every constant definition, call CALLBACK with two arguments: | |
980 | a pointer a pointer to the constant definition and INFO. | |
981 | Stops when CALLBACK returns zero. */ | |
982 | void | |
983 | traverse_md_constants (callback, info) | |
984 | htab_trav callback; | |
985 | void *info; | |
986 | { | |
987 | if (md_constants) | |
988 | htab_traverse (md_constants, callback, info); | |
989 | } | |
990 | ||
6f29feb1 JW |
991 | /* Read an rtx in printed representation from INFILE |
992 | and return an actual rtx in core constructed accordingly. | |
993 | read_rtx is not used in the compiler proper, but rather in | |
994 | the utilities gen*.c that construct C code from machine descriptions. */ | |
995 | ||
996 | rtx | |
997 | read_rtx (infile) | |
998 | FILE *infile; | |
999 | { | |
b548dffb | 1000 | register int i, j; |
6f29feb1 | 1001 | RTX_CODE tmp_code; |
6f7d635c | 1002 | register const char *format_ptr; |
6f29feb1 JW |
1003 | /* tmp_char is a buffer used for reading decimal integers |
1004 | and names of rtx types and machine modes. | |
1005 | Therefore, 256 must be enough. */ | |
1006 | char tmp_char[256]; | |
1007 | rtx return_rtx; | |
1008 | register int c; | |
1009 | int tmp_int; | |
c166a311 | 1010 | HOST_WIDE_INT tmp_wide; |
6f29feb1 | 1011 | |
1f8f4a0b MM |
1012 | /* Obstack used for allocating RTL objects. */ |
1013 | static struct obstack rtl_obstack; | |
1014 | static int initialized; | |
1015 | ||
6f29feb1 JW |
1016 | /* Linked list structure for making RTXs: */ |
1017 | struct rtx_list | |
1018 | { | |
1019 | struct rtx_list *next; | |
bcdaba58 | 1020 | rtx value; /* Value of this node. */ |
6f29feb1 JW |
1021 | }; |
1022 | ||
1f8f4a0b MM |
1023 | if (!initialized) { |
1024 | _obstack_begin (&rtl_obstack,0, 0, | |
1025 | (void *(*) PARAMS ((long))) xmalloc, | |
1026 | (void (*) PARAMS ((void *))) free); | |
1027 | initialized = 1; | |
1028 | } | |
1029 | ||
c25c12b8 | 1030 | again: |
6f29feb1 JW |
1031 | c = read_skip_spaces (infile); /* Should be open paren. */ |
1032 | if (c != '(') | |
bcdaba58 | 1033 | fatal_expected_char (infile, '(', c); |
6f29feb1 JW |
1034 | |
1035 | read_name (tmp_char, infile); | |
1036 | ||
1037 | tmp_code = UNKNOWN; | |
1038 | ||
c25c12b8 R |
1039 | if (! strcmp (tmp_char, "define_constants")) |
1040 | { | |
1041 | read_constants (infile, tmp_char); | |
1042 | goto again; | |
1043 | } | |
14a774a9 RK |
1044 | for (i = 0; i < NUM_RTX_CODE; i++) |
1045 | if (! strcmp (tmp_char, GET_RTX_NAME (i))) | |
1046 | { | |
1047 | tmp_code = (RTX_CODE) i; /* get value for name */ | |
1048 | break; | |
1049 | } | |
1050 | ||
6f29feb1 | 1051 | if (tmp_code == UNKNOWN) |
49886fe1 | 1052 | fatal_with_file_and_line (infile, "unknown rtx code `%s'", tmp_char); |
14a774a9 | 1053 | |
6f29feb1 JW |
1054 | /* (NIL) stands for an expression that isn't there. */ |
1055 | if (tmp_code == NIL) | |
1056 | { | |
1057 | /* Discard the closeparen. */ | |
14a774a9 RK |
1058 | while ((c = getc (infile)) && c != ')') |
1059 | ; | |
1060 | ||
6f29feb1 JW |
1061 | return 0; |
1062 | } | |
1063 | ||
14a774a9 RK |
1064 | /* If we end up with an insn expression then we free this space below. */ |
1065 | return_rtx = rtx_alloc (tmp_code); | |
6f29feb1 JW |
1066 | format_ptr = GET_RTX_FORMAT (GET_CODE (return_rtx)); |
1067 | ||
1068 | /* If what follows is `: mode ', read it and | |
1069 | store the mode in the rtx. */ | |
1070 | ||
1071 | i = read_skip_spaces (infile); | |
1072 | if (i == ':') | |
1073 | { | |
6f29feb1 | 1074 | read_name (tmp_char, infile); |
14a774a9 RK |
1075 | for (j = 0; j < NUM_MACHINE_MODES; j++) |
1076 | if (! strcmp (GET_MODE_NAME (j), tmp_char)) | |
6f29feb1 JW |
1077 | break; |
1078 | ||
14a774a9 | 1079 | if (j == MAX_MACHINE_MODE) |
49886fe1 | 1080 | fatal_with_file_and_line (infile, "unknown mode `%s'", tmp_char); |
14a774a9 RK |
1081 | |
1082 | PUT_MODE (return_rtx, (enum machine_mode) j); | |
6f29feb1 JW |
1083 | } |
1084 | else | |
1085 | ungetc (i, infile); | |
1086 | ||
1087 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (return_rtx)); i++) | |
1088 | switch (*format_ptr++) | |
1089 | { | |
1090 | /* 0 means a field for internal use only. | |
1091 | Don't expect it to be present in the input. */ | |
1092 | case '0': | |
1093 | break; | |
1094 | ||
1095 | case 'e': | |
1096 | case 'u': | |
1097 | XEXP (return_rtx, i) = read_rtx (infile); | |
1098 | break; | |
1099 | ||
1100 | case 'V': | |
1101 | /* 'V' is an optional vector: if a closeparen follows, | |
1102 | just store NULL for this element. */ | |
1103 | c = read_skip_spaces (infile); | |
1104 | ungetc (c, infile); | |
1105 | if (c == ')') | |
1106 | { | |
1107 | XVEC (return_rtx, i) = 0; | |
1108 | break; | |
1109 | } | |
1110 | /* Now process the vector. */ | |
f590cca1 | 1111 | |
6f29feb1 JW |
1112 | case 'E': |
1113 | { | |
b548dffb ZW |
1114 | /* Obstack to store scratch vector in. */ |
1115 | struct obstack vector_stack; | |
1116 | int list_counter = 0; | |
1117 | rtvec return_vec = NULL_RTVEC; | |
6f29feb1 JW |
1118 | |
1119 | c = read_skip_spaces (infile); | |
1120 | if (c != '[') | |
bcdaba58 | 1121 | fatal_expected_char (infile, '[', c); |
6f29feb1 JW |
1122 | |
1123 | /* add expressions to a list, while keeping a count */ | |
b548dffb | 1124 | obstack_init (&vector_stack); |
6f29feb1 JW |
1125 | while ((c = read_skip_spaces (infile)) && c != ']') |
1126 | { | |
1127 | ungetc (c, infile); | |
1128 | list_counter++; | |
b548dffb | 1129 | obstack_ptr_grow (&vector_stack, (PTR) read_rtx (infile)); |
6f29feb1 | 1130 | } |
6f29feb1 JW |
1131 | if (list_counter > 0) |
1132 | { | |
b548dffb ZW |
1133 | return_vec = rtvec_alloc (list_counter); |
1134 | memcpy (&return_vec->elem[0], obstack_finish (&vector_stack), | |
1135 | list_counter * sizeof (rtx)); | |
6f29feb1 | 1136 | } |
b548dffb ZW |
1137 | XVEC (return_rtx, i) = return_vec; |
1138 | obstack_free (&vector_stack, NULL); | |
6f29feb1 JW |
1139 | /* close bracket gotten */ |
1140 | } | |
1141 | break; | |
1142 | ||
1143 | case 'S': | |
1144 | /* 'S' is an optional string: if a closeparen follows, | |
1145 | just store NULL for this element. */ | |
1146 | c = read_skip_spaces (infile); | |
1147 | ungetc (c, infile); | |
1148 | if (c == ')') | |
1149 | { | |
1150 | XSTR (return_rtx, i) = 0; | |
1151 | break; | |
1152 | } | |
1153 | ||
1154 | case 's': | |
1155 | { | |
1156 | int saw_paren = 0; | |
1157 | register char *stringbuf; | |
3ab9a08f | 1158 | int saw_anything = 0; |
6f29feb1 JW |
1159 | |
1160 | c = read_skip_spaces (infile); | |
1161 | if (c == '(') | |
1162 | { | |
1163 | saw_paren = 1; | |
1164 | c = read_skip_spaces (infile); | |
1165 | } | |
1166 | if (c != '"') | |
bcdaba58 | 1167 | fatal_expected_char (infile, '"', c); |
6f29feb1 JW |
1168 | |
1169 | while (1) | |
1170 | { | |
2dcb563f | 1171 | c = getc (infile); /* Read the string */ |
bcdaba58 RH |
1172 | if (c == '\n') |
1173 | read_rtx_lineno++; | |
2dcb563f | 1174 | if (c == '\\') |
6f29feb1 | 1175 | { |
2dcb563f | 1176 | c = getc (infile); /* Read the string */ |
6f29feb1 JW |
1177 | /* \; makes stuff for a C string constant containing |
1178 | newline and tab. */ | |
2dcb563f | 1179 | if (c == ';') |
81dd58a6 | 1180 | { |
1f8f4a0b | 1181 | obstack_grow (&rtl_obstack, "\\n\\t", 4); |
81dd58a6 RS |
1182 | continue; |
1183 | } | |
aece2740 RH |
1184 | if (c == '\n') |
1185 | read_rtx_lineno++; | |
6f29feb1 | 1186 | } |
2dcb563f | 1187 | else if (c == '"') |
6f29feb1 | 1188 | break; |
2dcb563f | 1189 | |
1f8f4a0b | 1190 | obstack_1grow (&rtl_obstack, c); |
3ab9a08f DD |
1191 | saw_anything = 1; |
1192 | } | |
1193 | ||
1194 | /* For insn patterns, we want to provide a default name | |
1195 | based on the file and line, like "*foo.md:12", if the | |
1196 | given name is blank. These are only for define_insn and | |
1197 | define_insn_and_split, to aid debugging. */ | |
1198 | if (!saw_anything | |
1199 | && i == 0 | |
1200 | && (GET_CODE (return_rtx) == DEFINE_INSN | |
1201 | || GET_CODE (return_rtx) == DEFINE_INSN_AND_SPLIT)) | |
1202 | { | |
1203 | char line_name[20]; | |
1204 | const char *fn = (read_rtx_filename ? read_rtx_filename : "rtx"); | |
237aa7a2 | 1205 | const char *slash; |
3ab9a08f DD |
1206 | for (slash = fn; *slash; slash ++) |
1207 | if (*slash == '/' || *slash == '\\' || *slash == ':') | |
1208 | fn = slash + 1; | |
1209 | obstack_1grow (&rtl_obstack, '*'); | |
1210 | obstack_grow (&rtl_obstack, fn, strlen (fn)); | |
1211 | sprintf (line_name, ":%d", read_rtx_lineno); | |
1212 | obstack_grow (&rtl_obstack, line_name, strlen (line_name)); | |
6f29feb1 JW |
1213 | } |
1214 | ||
1f8f4a0b MM |
1215 | obstack_1grow (&rtl_obstack, 0); |
1216 | stringbuf = (char *) obstack_finish (&rtl_obstack); | |
6f29feb1 JW |
1217 | |
1218 | if (saw_paren) | |
1219 | { | |
1220 | c = read_skip_spaces (infile); | |
1221 | if (c != ')') | |
bcdaba58 | 1222 | fatal_expected_char (infile, ')', c); |
6f29feb1 JW |
1223 | } |
1224 | XSTR (return_rtx, i) = stringbuf; | |
1225 | } | |
1226 | break; | |
1227 | ||
c166a311 CH |
1228 | case 'w': |
1229 | read_name (tmp_char, infile); | |
1230 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT | |
1231 | tmp_wide = atoi (tmp_char); | |
1232 | #else | |
76d31c63 | 1233 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG |
c166a311 | 1234 | tmp_wide = atol (tmp_char); |
76d31c63 | 1235 | #else |
526aba28 | 1236 | /* Prefer atoll over atoq, since the former is in the ISO C99 standard. |
cbe36725 RH |
1237 | But prefer not to use our hand-rolled function above either. */ |
1238 | #if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ) | |
c5afbb49 JL |
1239 | tmp_wide = atoll (tmp_char); |
1240 | #else | |
76d31c63 JL |
1241 | tmp_wide = atoq (tmp_char); |
1242 | #endif | |
c5afbb49 | 1243 | #endif |
c166a311 CH |
1244 | #endif |
1245 | XWINT (return_rtx, i) = tmp_wide; | |
1246 | break; | |
1247 | ||
6f29feb1 JW |
1248 | case 'i': |
1249 | case 'n': | |
1250 | read_name (tmp_char, infile); | |
1251 | tmp_int = atoi (tmp_char); | |
1252 | XINT (return_rtx, i) = tmp_int; | |
1253 | break; | |
1254 | ||
1255 | default: | |
1256 | fprintf (stderr, | |
1257 | "switch format wrong in rtl.read_rtx(). format was: %c.\n", | |
1258 | format_ptr[-1]); | |
1259 | fprintf (stderr, "\tfile position: %ld\n", ftell (infile)); | |
1260 | abort (); | |
1261 | } | |
1262 | ||
1263 | c = read_skip_spaces (infile); | |
1264 | if (c != ')') | |
bcdaba58 | 1265 | fatal_expected_char (infile, ')', c); |
6f29feb1 JW |
1266 | |
1267 | return return_rtx; | |
1268 | } | |
987009bf | 1269 | |
f4524c9e | 1270 | #if defined ENABLE_RTL_CHECKING && (GCC_VERSION >= 2007) |
ef178af3 ZW |
1271 | void |
1272 | rtl_check_failed_bounds (r, n, file, line, func) | |
1273 | rtx r; | |
1274 | int n; | |
1275 | const char *file; | |
1276 | int line; | |
1277 | const char *func; | |
1278 | { | |
fce687f8 RK |
1279 | internal_error |
1280 | ("RTL check: access of elt %d of `%s' with last elt %d in %s, at %s:%d", | |
1281 | n, GET_RTX_NAME (GET_CODE (r)), GET_RTX_LENGTH (GET_CODE (r)) - 1, | |
1282 | func, trim_filename (file), line); | |
ef178af3 ZW |
1283 | } |
1284 | ||
1285 | void | |
1286 | rtl_check_failed_type1 (r, n, c1, file, line, func) | |
1287 | rtx r; | |
1288 | int n; | |
1289 | int c1; | |
1290 | const char *file; | |
1291 | int line; | |
1292 | const char *func; | |
1293 | { | |
fce687f8 RK |
1294 | internal_error |
1295 | ("RTL check: expected elt %d type '%c', have '%c' (rtx %s) in %s, at %s:%d", | |
1296 | n, c1, GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE (r)), | |
1297 | func, trim_filename (file), line); | |
ef178af3 ZW |
1298 | } |
1299 | ||
1300 | void | |
1301 | rtl_check_failed_type2 (r, n, c1, c2, file, line, func) | |
1302 | rtx r; | |
1303 | int n; | |
1304 | int c1; | |
1305 | int c2; | |
1306 | const char *file; | |
1307 | int line; | |
1308 | const char *func; | |
1309 | { | |
fce687f8 RK |
1310 | internal_error |
1311 | ("RTL check: expected elt %d type '%c' or '%c', have '%c' (rtx %s) in %s, at %s:%d", | |
1312 | n, c1, c2, GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE (r)), | |
1313 | func, trim_filename (file), line); | |
ef178af3 ZW |
1314 | } |
1315 | ||
83ab3839 RH |
1316 | void |
1317 | rtl_check_failed_code1 (r, code, file, line, func) | |
1318 | rtx r; | |
1319 | enum rtx_code code; | |
1320 | const char *file; | |
1321 | int line; | |
1322 | const char *func; | |
1323 | { | |
fce687f8 RK |
1324 | internal_error ("RTL check: expected code `%s', have `%s' in %s, at %s:%d", |
1325 | GET_RTX_NAME (code), GET_RTX_NAME (GET_CODE (r)), func, | |
1326 | trim_filename (file), line); | |
83ab3839 RH |
1327 | } |
1328 | ||
1329 | void | |
1330 | rtl_check_failed_code2 (r, code1, code2, file, line, func) | |
1331 | rtx r; | |
1332 | enum rtx_code code1, code2; | |
1333 | const char *file; | |
1334 | int line; | |
1335 | const char *func; | |
1336 | { | |
fce687f8 RK |
1337 | internal_error |
1338 | ("RTL check: expected code `%s' or `%s', have `%s' in %s, at %s:%d", | |
1339 | GET_RTX_NAME (code1), GET_RTX_NAME (code2), GET_RTX_NAME (GET_CODE (r)), | |
5ea1bc0e | 1340 | func, trim_filename (file), line); |
83ab3839 RH |
1341 | } |
1342 | ||
ef178af3 ZW |
1343 | /* XXX Maybe print the vector? */ |
1344 | void | |
1345 | rtvec_check_failed_bounds (r, n, file, line, func) | |
1346 | rtvec r; | |
1347 | int n; | |
1348 | const char *file; | |
1349 | int line; | |
1350 | const char *func; | |
1351 | { | |
fce687f8 RK |
1352 | internal_error |
1353 | ("RTL check: access of elt %d of vector with last elt %d in %s, at %s:%d", | |
1354 | n, GET_NUM_ELEM (r) - 1, func, trim_filename (file), line); | |
ef178af3 | 1355 | } |
f4524c9e | 1356 | #endif /* ENABLE_RTL_CHECKING */ |