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