]>
Commit | Line | Data |
---|---|---|
6f29feb1 | 1 | /* Allocate and read RTL for GNU C Compiler. |
1b0c6de6 | 2 | Copyright (C) 1987, 1988, 1991, 1994, 1997, 1998 Free Software Foundation, Inc. |
6f29feb1 JW |
3 | |
4 | This file is part of GNU CC. | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
e99215a3 RK |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
6f29feb1 JW |
20 | |
21 | ||
22 | #include "config.h" | |
670ee920 | 23 | #include "system.h" |
6f29feb1 | 24 | #include "rtl.h" |
a19a1b5d | 25 | #include "real.h" |
0dfa1860 | 26 | #include "bitmap.h" |
6f29feb1 JW |
27 | |
28 | #include "obstack.h" | |
29 | #define obstack_chunk_alloc xmalloc | |
30 | #define obstack_chunk_free free | |
6f29feb1 | 31 | |
987009bf ZW |
32 | #ifndef DIR_SEPARATOR |
33 | #define DIR_SEPARATOR '/' | |
34 | #endif | |
35 | ||
6f29feb1 JW |
36 | /* Obstack used for allocating RTL objects. |
37 | Between functions, this is the permanent_obstack. | |
38 | While parsing and expanding a function, this is maybepermanent_obstack | |
39 | so we can save it if it is an inline function. | |
40 | During optimization and output, this is function_obstack. */ | |
41 | ||
42 | extern struct obstack *rtl_obstack; | |
6f29feb1 | 43 | \f |
aa0b4465 ZW |
44 | |
45 | /* Calculate the format for CONST_DOUBLE. This depends on the relative | |
46 | widths of HOST_WIDE_INT and REAL_VALUE_TYPE. | |
47 | We only need to go out to e0wwww, since min(HOST_WIDE_INT)==32 and | |
48 | max(LONG_DOUBLE_TYPE_SIZE)==128. | |
49 | This is duplicated in gengenrtl.c. | |
50 | A number of places assume that there are always at least two 'w' | |
51 | slots in a CONST_DOUBLE, so we provide them even if one would suffice. */ | |
52 | #if HOST_BITS_PER_WIDE_INT >= LONG_DOUBLE_TYPE_SIZE | |
53 | #define CONST_DOUBLE_FORMAT "e0ww" | |
54 | #elif HOST_BITS_PER_WIDE_INT*2 >= LONG_DOUBLE_TYPE_SIZE | |
55 | #define CONST_DOUBLE_FORMAT "e0ww" | |
56 | #elif HOST_BITS_PER_WIDE_INT*3 >= LONG_DOUBLE_TYPE_SIZE | |
57 | #define CONST_DOUBLE_FORMAT "e0www" | |
58 | #elif HOST_BITS_PER_WIDE_INT*4 >= LONG_DOUBLE_TYPE_SIZE | |
59 | #define CONST_DOUBLE_FORMAT "e0wwww" | |
60 | #else | |
61 | #define CONST_DOUBLE_FORMAT /* nothing - will cause syntax error */ | |
62 | #endif | |
63 | ||
6f29feb1 | 64 | /* Indexed by rtx code, gives number of operands for an rtx with that code. |
aa0b4465 | 65 | Does NOT include rtx header data (code and links). */ |
6f29feb1 | 66 | |
aa0b4465 ZW |
67 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) sizeof FORMAT - 1 , |
68 | ||
69 | const int rtx_length[NUM_RTX_CODE + 1] = { | |
70 | #include "rtl.def" | |
71 | }; | |
72 | ||
73 | #undef DEF_RTL_EXPR | |
6f29feb1 JW |
74 | |
75 | /* Indexed by rtx code, gives the name of that kind of rtx, as a C string. */ | |
76 | ||
77 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME , | |
78 | ||
5f06c983 | 79 | const char * const rtx_name[] = { |
6f29feb1 JW |
80 | #include "rtl.def" /* rtl expressions are documented here */ |
81 | }; | |
82 | ||
83 | #undef DEF_RTL_EXPR | |
84 | ||
85 | /* Indexed by machine mode, gives the name of that machine mode. | |
86 | This name does not include the letters "mode". */ | |
87 | ||
88 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) NAME, | |
89 | ||
a4ec8d12 | 90 | const char * const mode_name[(int) MAX_MACHINE_MODE + 1] = { |
6f29feb1 | 91 | #include "machmode.def" |
913f68c1 JC |
92 | /* Add an extra field to avoid a core dump if someone tries to convert |
93 | MAX_MACHINE_MODE to a string. */ | |
94 | "" | |
6f29feb1 JW |
95 | }; |
96 | ||
97 | #undef DEF_MACHMODE | |
98 | ||
99 | /* Indexed by machine mode, gives the length of the mode, in bytes. | |
100 | GET_MODE_CLASS uses this. */ | |
101 | ||
102 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) CLASS, | |
103 | ||
aa0b4465 | 104 | const enum mode_class mode_class[(int) MAX_MACHINE_MODE] = { |
6f29feb1 JW |
105 | #include "machmode.def" |
106 | }; | |
107 | ||
108 | #undef DEF_MACHMODE | |
109 | ||
110 | /* Indexed by machine mode, gives the length of the mode, in bytes. | |
111 | GET_MODE_SIZE uses this. */ | |
112 | ||
113 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) SIZE, | |
114 | ||
aa0b4465 | 115 | const int mode_size[(int) MAX_MACHINE_MODE] = { |
6f29feb1 JW |
116 | #include "machmode.def" |
117 | }; | |
118 | ||
119 | #undef DEF_MACHMODE | |
120 | ||
121 | /* Indexed by machine mode, gives the length of the mode's subunit. | |
122 | GET_MODE_UNIT_SIZE uses this. */ | |
123 | ||
124 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) UNIT, | |
125 | ||
aa0b4465 | 126 | const int mode_unit_size[(int) MAX_MACHINE_MODE] = { |
6f29feb1 JW |
127 | #include "machmode.def" /* machine modes are documented here */ |
128 | }; | |
129 | ||
130 | #undef DEF_MACHMODE | |
131 | ||
132 | /* Indexed by machine mode, gives next wider natural mode | |
133 | (QI -> HI -> SI -> DI, etc.) Widening multiply instructions | |
134 | use this. */ | |
135 | ||
136 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) \ | |
913f68c1 | 137 | (unsigned char) WIDER, |
6f29feb1 | 138 | |
aa0b4465 | 139 | const unsigned char mode_wider_mode[(int) MAX_MACHINE_MODE] = { |
6f29feb1 JW |
140 | #include "machmode.def" /* machine modes are documented here */ |
141 | }; | |
142 | ||
143 | #undef DEF_MACHMODE | |
144 | ||
913f68c1 JC |
145 | #define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) \ |
146 | ((SIZE) * BITS_PER_UNIT >= HOST_BITS_PER_WIDE_INT) ? ~(unsigned HOST_WIDE_INT)0 : ((unsigned HOST_WIDE_INT) 1 << (SIZE) * BITS_PER_UNIT) - 1, | |
147 | ||
148 | /* Indexed by machine mode, gives mask of significant bits in mode. */ | |
149 | ||
aa0b4465 | 150 | const unsigned HOST_WIDE_INT mode_mask_array[(int) MAX_MACHINE_MODE] = { |
913f68c1 JC |
151 | #include "machmode.def" |
152 | }; | |
153 | ||
aa0b4465 ZW |
154 | /* Indexed by mode class, gives the narrowest mode for each class. |
155 | The Q modes are always of width 1 (2 for complex) - it is impossible | |
156 | for any mode to be narrower. */ | |
157 | ||
158 | const enum machine_mode class_narrowest_mode[(int) MAX_MODE_CLASS] = { | |
159 | /* MODE_RANDOM */ VOIDmode, | |
160 | /* MODE_INT */ QImode, | |
161 | /* MODE_FLOAT */ QFmode, | |
162 | /* MODE_PARTIAL_INT */ PQImode, | |
163 | /* MODE_CC */ CCmode, | |
164 | /* MODE_COMPLEX_INT */ CQImode, | |
165 | /* MODE_COMPLEX_FLOAT */ QCmode | |
166 | }; | |
167 | ||
4a39a918 | 168 | |
6f29feb1 JW |
169 | /* Indexed by rtx code, gives a sequence of operand-types for |
170 | rtx's of that code. The sequence is a C string in which | |
6dc42e49 | 171 | each character describes one operand. */ |
6f29feb1 | 172 | |
aa0b4465 | 173 | const char * const rtx_format[] = { |
6f29feb1 JW |
174 | /* "*" undefined. |
175 | can cause a warning message | |
176 | "0" field is unused (or used in a phase-dependent manner) | |
177 | prints nothing | |
178 | "i" an integer | |
179 | prints the integer | |
180 | "n" like "i", but prints entries from `note_insn_name' | |
c166a311 CH |
181 | "w" an integer of width HOST_BITS_PER_WIDE_INT |
182 | prints the integer | |
6f29feb1 JW |
183 | "s" a pointer to a string |
184 | prints the string | |
185 | "S" like "s", but optional: | |
186 | the containing rtx may end before this operand | |
187 | "e" a pointer to an rtl expression | |
188 | prints the expression | |
189 | "E" a pointer to a vector that points to a number of rtl expressions | |
190 | prints a list of the rtl expressions | |
191 | "V" like "E", but optional: | |
192 | the containing rtx may end before this operand | |
193 | "u" a pointer to another insn | |
0dfa1860 MM |
194 | prints the uid of the insn. |
195 | "b" is a pointer to a bitmap header. | |
196 | "t" is a tree pointer. */ | |
6f29feb1 JW |
197 | |
198 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT , | |
199 | #include "rtl.def" /* rtl expressions are defined here */ | |
200 | #undef DEF_RTL_EXPR | |
201 | }; | |
202 | ||
203 | /* Indexed by rtx code, gives a character representing the "class" of | |
204 | that rtx code. See rtl.def for documentation on the defined classes. */ | |
205 | ||
1f9a015e | 206 | const char rtx_class[] = { |
6f29feb1 JW |
207 | #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) CLASS, |
208 | #include "rtl.def" /* rtl expressions are defined here */ | |
209 | #undef DEF_RTL_EXPR | |
210 | }; | |
211 | ||
212 | /* Names for kinds of NOTEs and REG_NOTEs. */ | |
213 | ||
1f9a015e | 214 | const char * const note_insn_name[] = { 0 , "NOTE_INSN_DELETED", |
6f29feb1 JW |
215 | "NOTE_INSN_BLOCK_BEG", "NOTE_INSN_BLOCK_END", |
216 | "NOTE_INSN_LOOP_BEG", "NOTE_INSN_LOOP_END", | |
217 | "NOTE_INSN_FUNCTION_END", "NOTE_INSN_SETJMP", | |
bdac5f58 | 218 | "NOTE_INSN_LOOP_CONT", "NOTE_INSN_LOOP_VTOP", |
196cedd0 | 219 | "NOTE_INSN_PROLOGUE_END", "NOTE_INSN_EPILOGUE_BEG", |
3d195391 | 220 | "NOTE_INSN_DELETED_LABEL", "NOTE_INSN_FUNCTION_BEG", |
f6e3c1bb | 221 | "NOTE_INSN_EH_REGION_BEG", "NOTE_INSN_EH_REGION_END", |
0dfa1860 | 222 | "NOTE_REPEATED_LINE_NUMBER", "NOTE_INSN_RANGE_START", |
e881bb1b RH |
223 | "NOTE_INSN_RANGE_END", "NOTE_INSN_LIVE", |
224 | "NOTE_INSN_BASIC_BLOCK" }; | |
6f29feb1 | 225 | |
1f9a015e | 226 | const char * const reg_note_name[] = { "", "REG_DEAD", "REG_INC", "REG_EQUIV", "REG_WAS_0", |
6f29feb1 JW |
227 | "REG_EQUAL", "REG_RETVAL", "REG_LIBCALL", |
228 | "REG_NONNEG", "REG_NO_CONFLICT", "REG_UNUSED", | |
229 | "REG_CC_SETTER", "REG_CC_USER", "REG_LABEL", | |
f6e3c1bb | 230 | "REG_DEP_ANTI", "REG_DEP_OUTPUT", "REG_BR_PROB", |
c107334d | 231 | "REG_EXEC_COUNT", "REG_NOALIAS", "REG_SAVE_AREA", |
07ebc930 | 232 | "REG_BR_PRED", "REG_EH_CONTEXT", |
e6cfb550 AM |
233 | "REG_FRAME_RELATED_EXPR", "REG_EH_REGION", |
234 | "REG_EH_RETHROW" }; | |
6f29feb1 | 235 | |
bf94d1ec | 236 | static void dump_and_abort PROTO((int, int, FILE *)) ATTRIBUTE_NORETURN; |
956d6950 JL |
237 | static void read_name PROTO((char *, FILE *)); |
238 | \f | |
6f29feb1 JW |
239 | /* Allocate an rtx vector of N elements. |
240 | Store the length, and initialize all elements to zero. */ | |
241 | ||
242 | rtvec | |
243 | rtvec_alloc (n) | |
244 | int n; | |
245 | { | |
246 | rtvec rt; | |
247 | int i; | |
248 | ||
249 | rt = (rtvec) obstack_alloc (rtl_obstack, | |
250 | sizeof (struct rtvec_def) | |
8f985ec4 | 251 | + (( n - 1) * sizeof (rtx))); |
6f29feb1 JW |
252 | |
253 | /* clear out the vector */ | |
395d53bb RK |
254 | PUT_NUM_ELEM (rt, n); |
255 | ||
256 | for (i = 0; i < n; i++) | |
8f985ec4 | 257 | rt->elem[i] = 0; |
6f29feb1 JW |
258 | |
259 | return rt; | |
260 | } | |
261 | ||
262 | /* Allocate an rtx of code CODE. The CODE is stored in the rtx; | |
263 | all the rest is initialized to zero. */ | |
264 | ||
265 | rtx | |
266 | rtx_alloc (code) | |
267 | RTX_CODE code; | |
268 | { | |
269 | rtx rt; | |
270 | register struct obstack *ob = rtl_obstack; | |
271 | register int nelts = GET_RTX_LENGTH (code); | |
272 | register int length = sizeof (struct rtx_def) | |
273 | + (nelts - 1) * sizeof (rtunion); | |
274 | ||
275 | /* This function is called more than any other in GCC, | |
276 | so we manipulate the obstack directly. | |
277 | ||
278 | Even though rtx objects are word aligned, we may be sharing an obstack | |
279 | with tree nodes, which may have to be double-word aligned. So align | |
280 | our length to the alignment mask in the obstack. */ | |
281 | ||
282 | length = (length + ob->alignment_mask) & ~ ob->alignment_mask; | |
283 | ||
284 | if (ob->chunk_limit - ob->next_free < length) | |
285 | _obstack_newchunk (ob, length); | |
286 | rt = (rtx)ob->object_base; | |
287 | ob->next_free += length; | |
288 | ob->object_base = ob->next_free; | |
289 | ||
2151a093 RK |
290 | /* We want to clear everything up to the FLD array. Normally, this is |
291 | one int, but we don't want to assume that and it isn't very portable | |
292 | anyway; this is. */ | |
293 | ||
d6c0e1c8 | 294 | memset (rt, 0, sizeof (struct rtx_def) - sizeof (rtunion)); |
2151a093 | 295 | |
6f29feb1 JW |
296 | PUT_CODE (rt, code); |
297 | ||
298 | return rt; | |
299 | } | |
9b404774 RS |
300 | |
301 | /* Free the rtx X and all RTL allocated since X. */ | |
302 | ||
303 | void | |
304 | rtx_free (x) | |
305 | rtx x; | |
306 | { | |
307 | obstack_free (rtl_obstack, x); | |
308 | } | |
6f29feb1 JW |
309 | \f |
310 | /* Create a new copy of an rtx. | |
311 | Recursively copies the operands of the rtx, | |
312 | except for those few rtx codes that are sharable. */ | |
313 | ||
314 | rtx | |
315 | copy_rtx (orig) | |
316 | register rtx orig; | |
317 | { | |
318 | register rtx copy; | |
319 | register int i, j; | |
320 | register RTX_CODE code; | |
6f7d635c | 321 | register const char *format_ptr; |
6f29feb1 JW |
322 | |
323 | code = GET_CODE (orig); | |
324 | ||
325 | switch (code) | |
326 | { | |
327 | case REG: | |
328 | case QUEUED: | |
329 | case CONST_INT: | |
330 | case CONST_DOUBLE: | |
331 | case SYMBOL_REF: | |
332 | case CODE_LABEL: | |
333 | case PC: | |
334 | case CC0: | |
cf526dcc | 335 | case SCRATCH: |
0f41302f | 336 | /* SCRATCH must be shared because they represent distinct values. */ |
e9a25f70 | 337 | case ADDRESSOF: |
6f29feb1 | 338 | return orig; |
cf526dcc RK |
339 | |
340 | case CONST: | |
341 | /* CONST can be shared if it contains a SYMBOL_REF. If it contains | |
342 | a LABEL_REF, it isn't sharable. */ | |
343 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
344 | && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF | |
345 | && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT) | |
346 | return orig; | |
347 | break; | |
348 | ||
cc81e625 JW |
349 | /* A MEM with a constant address is not sharable. The problem is that |
350 | the constant address may need to be reloaded. If the mem is shared, | |
351 | then reloading one copy of this mem will cause all copies to appear | |
352 | to have been reloaded. */ | |
e9a25f70 JL |
353 | |
354 | default: | |
355 | break; | |
6f29feb1 JW |
356 | } |
357 | ||
358 | copy = rtx_alloc (code); | |
a4c6502a MM |
359 | |
360 | /* Copy the various flags, and other information. We assume that | |
361 | all fields need copying, and then clear the fields that should | |
362 | not be copied. That is the sensible default behavior, and forces | |
363 | us to explicitly document why we are *not* copying a flag. */ | |
8db99db2 | 364 | memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion)); |
a4c6502a MM |
365 | |
366 | /* We do not copy the USED flag, which is used as a mark bit during | |
367 | walks over the RTL. */ | |
368 | copy->used = 0; | |
369 | ||
370 | /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */ | |
371 | if (GET_RTX_CLASS (code) == 'i') | |
372 | { | |
373 | copy->jump = 0; | |
374 | copy->call = 0; | |
375 | copy->frame_related = 0; | |
376 | } | |
6f29feb1 JW |
377 | |
378 | format_ptr = GET_RTX_FORMAT (GET_CODE (copy)); | |
379 | ||
380 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++) | |
381 | { | |
382 | switch (*format_ptr++) | |
383 | { | |
384 | case 'e': | |
385 | XEXP (copy, i) = XEXP (orig, i); | |
386 | if (XEXP (orig, i) != NULL) | |
387 | XEXP (copy, i) = copy_rtx (XEXP (orig, i)); | |
388 | break; | |
389 | ||
c166a311 | 390 | case '0': |
f1027406 RK |
391 | case 'u': |
392 | XEXP (copy, i) = XEXP (orig, i); | |
393 | break; | |
394 | ||
6f29feb1 JW |
395 | case 'E': |
396 | case 'V': | |
397 | XVEC (copy, i) = XVEC (orig, i); | |
398 | if (XVEC (orig, i) != NULL) | |
399 | { | |
400 | XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i)); | |
401 | for (j = 0; j < XVECLEN (copy, i); j++) | |
402 | XVECEXP (copy, i, j) = copy_rtx (XVECEXP (orig, i, j)); | |
403 | } | |
404 | break; | |
405 | ||
0dfa1860 MM |
406 | case 'b': |
407 | { | |
408 | bitmap new_bits = BITMAP_OBSTACK_ALLOC (rtl_obstack); | |
409 | bitmap_copy (new_bits, XBITMAP (orig, i)); | |
410 | XBITMAP (copy, i) = new_bits; | |
411 | break; | |
412 | } | |
413 | ||
414 | case 't': | |
415 | XTREE (copy, i) = XTREE (orig, i); | |
416 | break; | |
417 | ||
c166a311 CH |
418 | case 'w': |
419 | XWINT (copy, i) = XWINT (orig, i); | |
420 | break; | |
421 | ||
422 | case 'i': | |
6f29feb1 JW |
423 | XINT (copy, i) = XINT (orig, i); |
424 | break; | |
c166a311 CH |
425 | |
426 | case 's': | |
427 | case 'S': | |
428 | XSTR (copy, i) = XSTR (orig, i); | |
429 | break; | |
430 | ||
431 | default: | |
432 | abort (); | |
6f29feb1 JW |
433 | } |
434 | } | |
435 | return copy; | |
436 | } | |
437 | ||
438 | /* Similar to `copy_rtx' except that if MAY_SHARE is present, it is | |
439 | placed in the result directly, rather than being copied. */ | |
440 | ||
441 | rtx | |
442 | copy_most_rtx (orig, may_share) | |
443 | register rtx orig; | |
444 | register rtx may_share; | |
445 | { | |
446 | register rtx copy; | |
447 | register int i, j; | |
448 | register RTX_CODE code; | |
6f7d635c | 449 | register const char *format_ptr; |
6f29feb1 JW |
450 | |
451 | if (orig == may_share) | |
452 | return orig; | |
453 | ||
454 | code = GET_CODE (orig); | |
455 | ||
456 | switch (code) | |
457 | { | |
458 | case REG: | |
459 | case QUEUED: | |
460 | case CONST_INT: | |
461 | case CONST_DOUBLE: | |
462 | case SYMBOL_REF: | |
463 | case CODE_LABEL: | |
464 | case PC: | |
465 | case CC0: | |
466 | return orig; | |
e9a25f70 JL |
467 | default: |
468 | break; | |
6f29feb1 JW |
469 | } |
470 | ||
471 | copy = rtx_alloc (code); | |
472 | PUT_MODE (copy, GET_MODE (orig)); | |
473 | copy->in_struct = orig->in_struct; | |
474 | copy->volatil = orig->volatil; | |
475 | copy->unchanging = orig->unchanging; | |
476 | copy->integrated = orig->integrated; | |
477 | ||
478 | format_ptr = GET_RTX_FORMAT (GET_CODE (copy)); | |
479 | ||
480 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++) | |
481 | { | |
482 | switch (*format_ptr++) | |
483 | { | |
484 | case 'e': | |
485 | XEXP (copy, i) = XEXP (orig, i); | |
486 | if (XEXP (orig, i) != NULL && XEXP (orig, i) != may_share) | |
487 | XEXP (copy, i) = copy_most_rtx (XEXP (orig, i), may_share); | |
488 | break; | |
f1027406 | 489 | |
c166a311 | 490 | case '0': |
f1027406 RK |
491 | case 'u': |
492 | XEXP (copy, i) = XEXP (orig, i); | |
493 | break; | |
6f29feb1 JW |
494 | |
495 | case 'E': | |
496 | case 'V': | |
497 | XVEC (copy, i) = XVEC (orig, i); | |
498 | if (XVEC (orig, i) != NULL) | |
499 | { | |
500 | XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i)); | |
501 | for (j = 0; j < XVECLEN (copy, i); j++) | |
502 | XVECEXP (copy, i, j) | |
503 | = copy_most_rtx (XVECEXP (orig, i, j), may_share); | |
504 | } | |
505 | break; | |
506 | ||
c166a311 CH |
507 | case 'w': |
508 | XWINT (copy, i) = XWINT (orig, i); | |
509 | break; | |
510 | ||
511 | case 'n': | |
512 | case 'i': | |
6f29feb1 JW |
513 | XINT (copy, i) = XINT (orig, i); |
514 | break; | |
c166a311 | 515 | |
8f985ec4 ZW |
516 | case 't': |
517 | XTREE (copy, i) = XTREE (orig, i); | |
518 | break; | |
519 | ||
c166a311 CH |
520 | case 's': |
521 | case 'S': | |
522 | XSTR (copy, i) = XSTR (orig, i); | |
523 | break; | |
524 | ||
525 | default: | |
526 | abort (); | |
6f29feb1 JW |
527 | } |
528 | } | |
529 | return copy; | |
530 | } | |
ce9d4c6d R |
531 | |
532 | /* Create a new copy of an rtx. Only copy just one level. */ | |
533 | rtx | |
534 | shallow_copy_rtx (orig) | |
535 | rtx orig; | |
536 | { | |
537 | register int i; | |
ce9d4c6d R |
538 | register RTX_CODE code = GET_CODE (orig); |
539 | register rtx copy = rtx_alloc (code); | |
540 | ||
541 | PUT_MODE (copy, GET_MODE (orig)); | |
542 | copy->in_struct = orig->in_struct; | |
543 | copy->volatil = orig->volatil; | |
544 | copy->unchanging = orig->unchanging; | |
545 | copy->integrated = orig->integrated; | |
546 | ||
547 | for (i = 0; i < GET_RTX_LENGTH (code); i++) | |
548 | copy->fld[i] = orig->fld[i]; | |
549 | ||
550 | return copy; | |
551 | } | |
6f29feb1 | 552 | \f |
6f29feb1 JW |
553 | /* Subroutines of read_rtx. */ |
554 | ||
555 | /* Dump code after printing a message. Used when read_rtx finds | |
556 | invalid data. */ | |
557 | ||
558 | static void | |
559 | dump_and_abort (expected_c, actual_c, infile) | |
560 | int expected_c, actual_c; | |
561 | FILE *infile; | |
562 | { | |
563 | int c, i; | |
564 | ||
565 | if (expected_c >= 0) | |
566 | fprintf (stderr, | |
567 | "Expected character %c. Found character %c.", | |
568 | expected_c, actual_c); | |
569 | fprintf (stderr, " At file position: %ld\n", ftell (infile)); | |
570 | fprintf (stderr, "Following characters are:\n\t"); | |
571 | for (i = 0; i < 200; i++) | |
572 | { | |
573 | c = getc (infile); | |
574 | if (EOF == c) break; | |
575 | putc (c, stderr); | |
576 | } | |
577 | fprintf (stderr, "Aborting.\n"); | |
578 | abort (); | |
579 | } | |
580 | ||
581 | /* Read chars from INFILE until a non-whitespace char | |
582 | and return that. Comments, both Lisp style and C style, | |
583 | are treated as whitespace. | |
584 | Tools such as genflags use this function. */ | |
585 | ||
586 | int | |
587 | read_skip_spaces (infile) | |
588 | FILE *infile; | |
589 | { | |
590 | register int c; | |
1d300e19 | 591 | while ((c = getc (infile))) |
6f29feb1 JW |
592 | { |
593 | if (c == ' ' || c == '\n' || c == '\t' || c == '\f') | |
594 | ; | |
595 | else if (c == ';') | |
596 | { | |
29cb1e1f NC |
597 | while ((c = getc (infile)) && c != '\n' && c != EOF) |
598 | ; | |
6f29feb1 JW |
599 | } |
600 | else if (c == '/') | |
601 | { | |
602 | register int prevc; | |
603 | c = getc (infile); | |
604 | if (c != '*') | |
605 | dump_and_abort ('*', c, infile); | |
606 | ||
607 | prevc = 0; | |
29cb1e1f | 608 | while ((c = getc (infile)) && c != EOF) |
6f29feb1 JW |
609 | { |
610 | if (prevc == '*' && c == '/') | |
611 | break; | |
612 | prevc = c; | |
613 | } | |
614 | } | |
615 | else break; | |
616 | } | |
617 | return c; | |
618 | } | |
619 | ||
620 | /* Read an rtx code name into the buffer STR[]. | |
621 | It is terminated by any of the punctuation chars of rtx printed syntax. */ | |
622 | ||
623 | static void | |
624 | read_name (str, infile) | |
625 | char *str; | |
626 | FILE *infile; | |
627 | { | |
628 | register char *p; | |
629 | register int c; | |
630 | ||
631 | c = read_skip_spaces(infile); | |
632 | ||
633 | p = str; | |
634 | while (1) | |
635 | { | |
636 | if (c == ' ' || c == '\n' || c == '\t' || c == '\f') | |
637 | break; | |
638 | if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/' | |
639 | || c == '(' || c == '[') | |
640 | { | |
641 | ungetc (c, infile); | |
642 | break; | |
643 | } | |
644 | *p++ = c; | |
645 | c = getc (infile); | |
646 | } | |
647 | if (p == str) | |
648 | { | |
649 | fprintf (stderr, "missing name or number"); | |
650 | dump_and_abort (-1, -1, infile); | |
651 | } | |
652 | ||
653 | *p = 0; | |
654 | } | |
655 | \f | |
cbe36725 RH |
656 | /* Provide a version of a function to read a long long if the system does |
657 | not provide one. */ | |
658 | #if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ) | |
659 | HOST_WIDE_INT | |
660 | atoll(p) | |
661 | const char *p; | |
662 | { | |
663 | int neg = 0; | |
664 | HOST_WIDE_INT tmp_wide; | |
665 | ||
e9a780ec | 666 | while (ISSPACE(*p)) |
cbe36725 RH |
667 | p++; |
668 | if (*p == '-') | |
669 | neg = 1, p++; | |
670 | else if (*p == '+') | |
671 | p++; | |
672 | ||
673 | tmp_wide = 0; | |
e9a780ec | 674 | while (ISDIGIT(*p)) |
cbe36725 RH |
675 | { |
676 | HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0'); | |
677 | if (new_wide < tmp_wide) | |
678 | { | |
679 | /* Return INT_MAX equiv on overflow. */ | |
680 | tmp_wide = (~(unsigned HOST_WIDE_INT)0) >> 1; | |
681 | break; | |
682 | } | |
683 | tmp_wide = new_wide; | |
684 | p++; | |
685 | } | |
686 | ||
687 | if (neg) | |
688 | tmp_wide = -tmp_wide; | |
689 | return tmp_wide; | |
690 | } | |
691 | #endif | |
692 | ||
6f29feb1 JW |
693 | /* Read an rtx in printed representation from INFILE |
694 | and return an actual rtx in core constructed accordingly. | |
695 | read_rtx is not used in the compiler proper, but rather in | |
696 | the utilities gen*.c that construct C code from machine descriptions. */ | |
697 | ||
698 | rtx | |
699 | read_rtx (infile) | |
700 | FILE *infile; | |
701 | { | |
702 | register int i, j, list_counter; | |
703 | RTX_CODE tmp_code; | |
6f7d635c | 704 | register const char *format_ptr; |
6f29feb1 JW |
705 | /* tmp_char is a buffer used for reading decimal integers |
706 | and names of rtx types and machine modes. | |
707 | Therefore, 256 must be enough. */ | |
708 | char tmp_char[256]; | |
709 | rtx return_rtx; | |
710 | register int c; | |
711 | int tmp_int; | |
c166a311 | 712 | HOST_WIDE_INT tmp_wide; |
6f29feb1 JW |
713 | |
714 | /* Linked list structure for making RTXs: */ | |
715 | struct rtx_list | |
716 | { | |
717 | struct rtx_list *next; | |
718 | rtx value; /* Value of this node... */ | |
719 | }; | |
720 | ||
721 | c = read_skip_spaces (infile); /* Should be open paren. */ | |
722 | if (c != '(') | |
723 | dump_and_abort ('(', c, infile); | |
724 | ||
725 | read_name (tmp_char, infile); | |
726 | ||
727 | tmp_code = UNKNOWN; | |
728 | ||
729 | for (i=0; i < NUM_RTX_CODE; i++) /* @@ might speed this search up */ | |
730 | { | |
731 | if (!(strcmp (tmp_char, GET_RTX_NAME (i)))) | |
732 | { | |
733 | tmp_code = (RTX_CODE) i; /* get value for name */ | |
734 | break; | |
735 | } | |
736 | } | |
737 | if (tmp_code == UNKNOWN) | |
738 | { | |
739 | fprintf (stderr, | |
740 | "Unknown rtx read in rtl.read_rtx(). Code name was %s .", | |
741 | tmp_char); | |
742 | } | |
743 | /* (NIL) stands for an expression that isn't there. */ | |
744 | if (tmp_code == NIL) | |
745 | { | |
746 | /* Discard the closeparen. */ | |
747 | while ((c = getc (infile)) && c != ')'); | |
748 | return 0; | |
749 | } | |
750 | ||
751 | return_rtx = rtx_alloc (tmp_code); /* if we end up with an insn expression | |
752 | then we free this space below. */ | |
753 | format_ptr = GET_RTX_FORMAT (GET_CODE (return_rtx)); | |
754 | ||
755 | /* If what follows is `: mode ', read it and | |
756 | store the mode in the rtx. */ | |
757 | ||
758 | i = read_skip_spaces (infile); | |
759 | if (i == ':') | |
760 | { | |
761 | register int k; | |
762 | read_name (tmp_char, infile); | |
763 | for (k = 0; k < NUM_MACHINE_MODES; k++) | |
764 | if (!strcmp (GET_MODE_NAME (k), tmp_char)) | |
765 | break; | |
766 | ||
767 | PUT_MODE (return_rtx, (enum machine_mode) k ); | |
768 | } | |
769 | else | |
770 | ungetc (i, infile); | |
771 | ||
772 | for (i = 0; i < GET_RTX_LENGTH (GET_CODE (return_rtx)); i++) | |
773 | switch (*format_ptr++) | |
774 | { | |
775 | /* 0 means a field for internal use only. | |
776 | Don't expect it to be present in the input. */ | |
777 | case '0': | |
778 | break; | |
779 | ||
780 | case 'e': | |
781 | case 'u': | |
782 | XEXP (return_rtx, i) = read_rtx (infile); | |
783 | break; | |
784 | ||
785 | case 'V': | |
786 | /* 'V' is an optional vector: if a closeparen follows, | |
787 | just store NULL for this element. */ | |
788 | c = read_skip_spaces (infile); | |
789 | ungetc (c, infile); | |
790 | if (c == ')') | |
791 | { | |
792 | XVEC (return_rtx, i) = 0; | |
793 | break; | |
794 | } | |
795 | /* Now process the vector. */ | |
796 | ||
797 | case 'E': | |
798 | { | |
799 | register struct rtx_list *next_rtx, *rtx_list_link; | |
4399e7a3 | 800 | struct rtx_list *list_rtx = NULL; |
6f29feb1 JW |
801 | |
802 | c = read_skip_spaces (infile); | |
803 | if (c != '[') | |
804 | dump_and_abort ('[', c, infile); | |
805 | ||
806 | /* add expressions to a list, while keeping a count */ | |
807 | next_rtx = NULL; | |
808 | list_counter = 0; | |
809 | while ((c = read_skip_spaces (infile)) && c != ']') | |
810 | { | |
811 | ungetc (c, infile); | |
812 | list_counter++; | |
813 | rtx_list_link = (struct rtx_list *) | |
814 | alloca (sizeof (struct rtx_list)); | |
815 | rtx_list_link->value = read_rtx (infile); | |
816 | if (next_rtx == 0) | |
817 | list_rtx = rtx_list_link; | |
818 | else | |
819 | next_rtx->next = rtx_list_link; | |
820 | next_rtx = rtx_list_link; | |
821 | rtx_list_link->next = 0; | |
822 | } | |
823 | /* get vector length and allocate it */ | |
824 | XVEC (return_rtx, i) = (list_counter | |
c166a311 | 825 | ? rtvec_alloc (list_counter) : NULL_RTVEC); |
6f29feb1 JW |
826 | if (list_counter > 0) |
827 | { | |
828 | next_rtx = list_rtx; | |
829 | for (j = 0; j < list_counter; j++, | |
830 | next_rtx = next_rtx->next) | |
831 | XVECEXP (return_rtx, i, j) = next_rtx->value; | |
832 | } | |
833 | /* close bracket gotten */ | |
834 | } | |
835 | break; | |
836 | ||
837 | case 'S': | |
838 | /* 'S' is an optional string: if a closeparen follows, | |
839 | just store NULL for this element. */ | |
840 | c = read_skip_spaces (infile); | |
841 | ungetc (c, infile); | |
842 | if (c == ')') | |
843 | { | |
844 | XSTR (return_rtx, i) = 0; | |
845 | break; | |
846 | } | |
847 | ||
848 | case 's': | |
849 | { | |
850 | int saw_paren = 0; | |
851 | register char *stringbuf; | |
6f29feb1 JW |
852 | |
853 | c = read_skip_spaces (infile); | |
854 | if (c == '(') | |
855 | { | |
856 | saw_paren = 1; | |
857 | c = read_skip_spaces (infile); | |
858 | } | |
859 | if (c != '"') | |
860 | dump_and_abort ('"', c, infile); | |
6f29feb1 JW |
861 | |
862 | while (1) | |
863 | { | |
2dcb563f RS |
864 | c = getc (infile); /* Read the string */ |
865 | if (c == '\\') | |
6f29feb1 | 866 | { |
2dcb563f | 867 | c = getc (infile); /* Read the string */ |
6f29feb1 JW |
868 | /* \; makes stuff for a C string constant containing |
869 | newline and tab. */ | |
2dcb563f | 870 | if (c == ';') |
81dd58a6 RS |
871 | { |
872 | obstack_grow (rtl_obstack, "\\n\\t", 4); | |
873 | continue; | |
874 | } | |
6f29feb1 | 875 | } |
2dcb563f | 876 | else if (c == '"') |
6f29feb1 | 877 | break; |
2dcb563f RS |
878 | |
879 | obstack_1grow (rtl_obstack, c); | |
6f29feb1 JW |
880 | } |
881 | ||
2dcb563f RS |
882 | obstack_1grow (rtl_obstack, 0); |
883 | stringbuf = (char *) obstack_finish (rtl_obstack); | |
6f29feb1 JW |
884 | |
885 | if (saw_paren) | |
886 | { | |
887 | c = read_skip_spaces (infile); | |
888 | if (c != ')') | |
889 | dump_and_abort (')', c, infile); | |
890 | } | |
891 | XSTR (return_rtx, i) = stringbuf; | |
892 | } | |
893 | break; | |
894 | ||
c166a311 CH |
895 | case 'w': |
896 | read_name (tmp_char, infile); | |
897 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT | |
898 | tmp_wide = atoi (tmp_char); | |
899 | #else | |
76d31c63 | 900 | #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG |
c166a311 | 901 | tmp_wide = atol (tmp_char); |
76d31c63 | 902 | #else |
cbe36725 RH |
903 | /* Prefer atoll over atoq, since the former is in the ISO C9X draft. |
904 | But prefer not to use our hand-rolled function above either. */ | |
905 | #if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ) | |
c5afbb49 JL |
906 | tmp_wide = atoll (tmp_char); |
907 | #else | |
76d31c63 JL |
908 | tmp_wide = atoq (tmp_char); |
909 | #endif | |
c5afbb49 | 910 | #endif |
c166a311 CH |
911 | #endif |
912 | XWINT (return_rtx, i) = tmp_wide; | |
913 | break; | |
914 | ||
6f29feb1 JW |
915 | case 'i': |
916 | case 'n': | |
917 | read_name (tmp_char, infile); | |
918 | tmp_int = atoi (tmp_char); | |
919 | XINT (return_rtx, i) = tmp_int; | |
920 | break; | |
921 | ||
922 | default: | |
923 | fprintf (stderr, | |
924 | "switch format wrong in rtl.read_rtx(). format was: %c.\n", | |
925 | format_ptr[-1]); | |
926 | fprintf (stderr, "\tfile position: %ld\n", ftell (infile)); | |
927 | abort (); | |
928 | } | |
929 | ||
930 | c = read_skip_spaces (infile); | |
931 | if (c != ')') | |
932 | dump_and_abort (')', c, infile); | |
933 | ||
934 | return return_rtx; | |
935 | } | |
987009bf ZW |
936 | |
937 | /* These are utility functions used by fatal-error functions all over the | |
938 | code. rtl.c happens to be linked by all the programs that need them, | |
939 | so these are here. In the future we want to break out all error handling | |
940 | to its own module. */ | |
941 | ||
942 | /* Given a partial pathname as input, return another pathname that | |
943 | shares no directory elements with the pathname of __FILE__. This | |
944 | is used by fancy_abort() to print `Internal compiler error in expr.c' | |
945 | instead of `Internal compiler error in ../../egcs/gcc/expr.c'. */ | |
946 | static const char * | |
947 | trim_filename (name) | |
948 | const char *name; | |
949 | { | |
aa0b4465 | 950 | static const char this_file[] = __FILE__; |
987009bf ZW |
951 | const char *p = name, *q = this_file; |
952 | ||
953 | while (*p == *q && *p != 0 && *q != 0) p++, q++; | |
954 | while (p > name && p[-1] != DIR_SEPARATOR | |
955 | #ifdef DIR_SEPARATOR_2 | |
956 | && p[-1] != DIR_SEPARATOR_2 | |
957 | #endif | |
958 | ) | |
959 | p--; | |
960 | ||
961 | return p; | |
962 | } | |
963 | ||
964 | /* Report an internal compiler error in a friendly manner and without | |
965 | dumping core. There are two versions because __FUNCTION__ isn't | |
966 | available except in gcc 2.7 and later. */ | |
967 | ||
968 | extern void fatal PVPROTO ((const char *, ...)) | |
969 | ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; | |
970 | ||
971 | void | |
972 | fancy_abort (file, line, function) | |
973 | const char *file; | |
974 | int line; | |
975 | const char *function; | |
976 | { | |
977 | if (function == NULL) | |
978 | function = "?"; | |
979 | fatal ( | |
980 | "Internal compiler error in `%s', at %s:%d\n\ | |
981 | Please submit a full bug report.\n\ | |
982 | See <URL:http://www.gnu.org/software/gcc/faq.html#bugreport> \ | |
983 | for instructions.", | |
984 | function, trim_filename (file), line); | |
985 | } |