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