]> gcc.gnu.org Git - gcc.git/blame - gcc/rtl.c
gcc toplevel:
[gcc.git] / gcc / rtl.c
CommitLineData
6f29feb1 1/* Allocate and read RTL for GNU C Compiler.
c5c76735
JL
2 Copyright (C) 1987, 1988, 1991, 1994, 1997, 1998, 1999
3 Free Software Foundation, Inc.
6f29feb1
JW
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
e99215a3
RK
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, 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
JW
29#include "obstack.h"
30#define obstack_chunk_alloc xmalloc
31#define obstack_chunk_free free
6f29feb1 32
987009bf
ZW
33#ifndef DIR_SEPARATOR
34#define DIR_SEPARATOR '/'
35#endif
36
6f29feb1
JW
37/* Obstack used for allocating RTL objects.
38 Between functions, this is the permanent_obstack.
39 While parsing and expanding a function, this is maybepermanent_obstack
40 so we can save it if it is an inline function.
41 During optimization and output, this is function_obstack. */
42
43extern struct obstack *rtl_obstack;
6f29feb1 44\f
aa0b4465
ZW
45/* Calculate the format for CONST_DOUBLE. This depends on the relative
46 widths of HOST_WIDE_INT and REAL_VALUE_TYPE.
b6b4c6c6
RH
47
48 We need to go out to e0wwwww, since REAL_ARITHMETIC assumes 16-bits
49 per element in REAL_VALUE_TYPE.
50
aa0b4465 51 This is duplicated in gengenrtl.c.
b6b4c6c6 52
aa0b4465
ZW
53 A number of places assume that there are always at least two 'w'
54 slots in a CONST_DOUBLE, so we provide them even if one would suffice. */
b6b4c6c6
RH
55
56#ifdef REAL_ARITHMETIC
57#if LONG_DOUBLE_TYPE_SIZE == 96
58#define REAL_WIDTH (11*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT
59#elif LONG_DOUBLE_TYPE_SIZE == 128
60#define REAL_WIDTH (19*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT
61#elif HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
62#define REAL_WIDTH (7*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT
63#endif
64#endif /* REAL_ARITHMETIC */
65
66#ifndef REAL_WIDTH
67#if HOST_BITS_PER_WIDE_INT*2 >= LONG_DOUBLE_TYPE_SIZE
68#define REAL_WIDTH 2
69#elif HOST_BITS_PER_WIDE_INT*3 >= LONG_DOUBLE_TYPE_SIZE
70#define REAL_WIDTH 3
71#elif HOST_BITS_PER_WIDE_INT*4 >= LONG_DOUBLE_TYPE_SIZE
72#define REAL_WIDTH 4
73#endif
74#endif /* REAL_WIDTH */
75
76#if REAL_WIDTH == 1
aa0b4465 77#define CONST_DOUBLE_FORMAT "e0ww"
b6b4c6c6 78#elif REAL_WIDTH == 2
aa0b4465 79#define CONST_DOUBLE_FORMAT "e0ww"
b6b4c6c6 80#elif REAL_WIDTH == 3
aa0b4465 81#define CONST_DOUBLE_FORMAT "e0www"
b6b4c6c6 82#elif REAL_WIDTH == 4
aa0b4465 83#define CONST_DOUBLE_FORMAT "e0wwww"
b6b4c6c6
RH
84#elif REAL_WIDTH == 5
85#define CONST_DOUBLE_FORMAT "e0wwwww"
aa0b4465
ZW
86#else
87#define CONST_DOUBLE_FORMAT /* nothing - will cause syntax error */
88#endif
89
6f29feb1 90/* Indexed by rtx code, gives number of operands for an rtx with that code.
aa0b4465 91 Does NOT include rtx header data (code and links). */
6f29feb1 92
aa0b4465
ZW
93#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) sizeof FORMAT - 1 ,
94
95const int rtx_length[NUM_RTX_CODE + 1] = {
96#include "rtl.def"
97};
98
99#undef DEF_RTL_EXPR
6f29feb1
JW
100
101/* Indexed by rtx code, gives the name of that kind of rtx, as a C string. */
102
103#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
104
5f06c983 105const char * const rtx_name[] = {
6f29feb1
JW
106#include "rtl.def" /* rtl expressions are documented here */
107};
108
109#undef DEF_RTL_EXPR
110
111/* Indexed by machine mode, gives the name of that machine mode.
112 This name does not include the letters "mode". */
113
114#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) NAME,
115
a4ec8d12 116const char * const mode_name[(int) MAX_MACHINE_MODE + 1] = {
6f29feb1 117#include "machmode.def"
913f68c1
JC
118 /* Add an extra field to avoid a core dump if someone tries to convert
119 MAX_MACHINE_MODE to a string. */
120 ""
6f29feb1
JW
121};
122
123#undef DEF_MACHMODE
124
125/* Indexed by machine mode, gives the length of the mode, in bytes.
126 GET_MODE_CLASS uses this. */
127
128#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) CLASS,
129
aa0b4465 130const enum mode_class mode_class[(int) MAX_MACHINE_MODE] = {
6f29feb1
JW
131#include "machmode.def"
132};
133
134#undef DEF_MACHMODE
135
136/* Indexed by machine mode, gives the length of the mode, in bytes.
137 GET_MODE_SIZE uses this. */
138
139#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) SIZE,
140
aa0b4465 141const int mode_size[(int) MAX_MACHINE_MODE] = {
6f29feb1
JW
142#include "machmode.def"
143};
144
145#undef DEF_MACHMODE
146
147/* Indexed by machine mode, gives the length of the mode's subunit.
148 GET_MODE_UNIT_SIZE uses this. */
149
150#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) UNIT,
151
aa0b4465 152const int mode_unit_size[(int) MAX_MACHINE_MODE] = {
6f29feb1
JW
153#include "machmode.def" /* machine modes are documented here */
154};
155
156#undef DEF_MACHMODE
157
158/* Indexed by machine mode, gives next wider natural mode
159 (QI -> HI -> SI -> DI, etc.) Widening multiply instructions
160 use this. */
161
162#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) \
913f68c1 163 (unsigned char) WIDER,
6f29feb1 164
aa0b4465 165const unsigned char mode_wider_mode[(int) MAX_MACHINE_MODE] = {
6f29feb1
JW
166#include "machmode.def" /* machine modes are documented here */
167};
168
169#undef DEF_MACHMODE
170
913f68c1
JC
171#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) \
172 ((SIZE) * BITS_PER_UNIT >= HOST_BITS_PER_WIDE_INT) ? ~(unsigned HOST_WIDE_INT)0 : ((unsigned HOST_WIDE_INT) 1 << (SIZE) * BITS_PER_UNIT) - 1,
173
174/* Indexed by machine mode, gives mask of significant bits in mode. */
175
aa0b4465 176const unsigned HOST_WIDE_INT mode_mask_array[(int) MAX_MACHINE_MODE] = {
913f68c1
JC
177#include "machmode.def"
178};
179
aa0b4465
ZW
180/* Indexed by mode class, gives the narrowest mode for each class.
181 The Q modes are always of width 1 (2 for complex) - it is impossible
182 for any mode to be narrower. */
183
184const enum machine_mode class_narrowest_mode[(int) MAX_MODE_CLASS] = {
185 /* MODE_RANDOM */ VOIDmode,
186 /* MODE_INT */ QImode,
187 /* MODE_FLOAT */ QFmode,
188 /* MODE_PARTIAL_INT */ PQImode,
189 /* MODE_CC */ CCmode,
190 /* MODE_COMPLEX_INT */ CQImode,
191 /* MODE_COMPLEX_FLOAT */ QCmode
192};
193
4a39a918 194
6f29feb1
JW
195/* Indexed by rtx code, gives a sequence of operand-types for
196 rtx's of that code. The sequence is a C string in which
6dc42e49 197 each character describes one operand. */
6f29feb1 198
aa0b4465 199const char * const rtx_format[] = {
6f29feb1
JW
200 /* "*" undefined.
201 can cause a warning message
202 "0" field is unused (or used in a phase-dependent manner)
203 prints nothing
204 "i" an integer
205 prints the integer
206 "n" like "i", but prints entries from `note_insn_name'
c166a311
CH
207 "w" an integer of width HOST_BITS_PER_WIDE_INT
208 prints the integer
6f29feb1
JW
209 "s" a pointer to a string
210 prints the string
211 "S" like "s", but optional:
212 the containing rtx may end before this operand
213 "e" a pointer to an rtl expression
214 prints the expression
215 "E" a pointer to a vector that points to a number of rtl expressions
216 prints a list of the rtl expressions
217 "V" like "E", but optional:
218 the containing rtx may end before this operand
219 "u" a pointer to another insn
0dfa1860
MM
220 prints the uid of the insn.
221 "b" is a pointer to a bitmap header.
222 "t" is a tree pointer. */
6f29feb1
JW
223
224#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
225#include "rtl.def" /* rtl expressions are defined here */
226#undef DEF_RTL_EXPR
227};
228
229/* Indexed by rtx code, gives a character representing the "class" of
230 that rtx code. See rtl.def for documentation on the defined classes. */
231
1f9a015e 232const char rtx_class[] = {
6f29feb1
JW
233#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) CLASS,
234#include "rtl.def" /* rtl expressions are defined here */
235#undef DEF_RTL_EXPR
236};
237
238/* Names for kinds of NOTEs and REG_NOTEs. */
239
1f9a015e 240const char * const note_insn_name[] = { 0 , "NOTE_INSN_DELETED",
6f29feb1
JW
241 "NOTE_INSN_BLOCK_BEG", "NOTE_INSN_BLOCK_END",
242 "NOTE_INSN_LOOP_BEG", "NOTE_INSN_LOOP_END",
243 "NOTE_INSN_FUNCTION_END", "NOTE_INSN_SETJMP",
bdac5f58 244 "NOTE_INSN_LOOP_CONT", "NOTE_INSN_LOOP_VTOP",
196cedd0 245 "NOTE_INSN_PROLOGUE_END", "NOTE_INSN_EPILOGUE_BEG",
3d195391 246 "NOTE_INSN_DELETED_LABEL", "NOTE_INSN_FUNCTION_BEG",
f6e3c1bb 247 "NOTE_INSN_EH_REGION_BEG", "NOTE_INSN_EH_REGION_END",
0dfa1860 248 "NOTE_REPEATED_LINE_NUMBER", "NOTE_INSN_RANGE_START",
e881bb1b
RH
249 "NOTE_INSN_RANGE_END", "NOTE_INSN_LIVE",
250 "NOTE_INSN_BASIC_BLOCK" };
6f29feb1 251
1f9a015e 252const char * const reg_note_name[] = { "", "REG_DEAD", "REG_INC", "REG_EQUIV", "REG_WAS_0",
6f29feb1
JW
253 "REG_EQUAL", "REG_RETVAL", "REG_LIBCALL",
254 "REG_NONNEG", "REG_NO_CONFLICT", "REG_UNUSED",
255 "REG_CC_SETTER", "REG_CC_USER", "REG_LABEL",
f6e3c1bb 256 "REG_DEP_ANTI", "REG_DEP_OUTPUT", "REG_BR_PROB",
c107334d 257 "REG_EXEC_COUNT", "REG_NOALIAS", "REG_SAVE_AREA",
07ebc930 258 "REG_BR_PRED", "REG_EH_CONTEXT",
e6cfb550 259 "REG_FRAME_RELATED_EXPR", "REG_EH_REGION",
c46a37c4 260 "REG_EH_RETHROW", "REG_SAVE_NOTE" };
6f29feb1 261
bf94d1ec 262static void dump_and_abort PROTO((int, int, FILE *)) ATTRIBUTE_NORETURN;
956d6950 263static void read_name PROTO((char *, FILE *));
95d75019 264static const char *trim_filename PROTO((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
269rtvec
270rtvec_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
297rtx
298rtx_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
341void
342rtx_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
353rtx
354copy_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
467rtx
468copy_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. */
563rtx
564shallow_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
6f29feb1
JW
583/* Subroutines of read_rtx. */
584
585/* Dump code after printing a message. Used when read_rtx finds
586 invalid data. */
587
588static void
589dump_and_abort (expected_c, actual_c, infile)
590 int expected_c, actual_c;
591 FILE *infile;
592{
593 int c, i;
594
595 if (expected_c >= 0)
596 fprintf (stderr,
597 "Expected character %c. Found character %c.",
598 expected_c, actual_c);
599 fprintf (stderr, " At file position: %ld\n", ftell (infile));
600 fprintf (stderr, "Following characters are:\n\t");
601 for (i = 0; i < 200; i++)
602 {
603 c = getc (infile);
604 if (EOF == c) break;
605 putc (c, stderr);
606 }
607 fprintf (stderr, "Aborting.\n");
608 abort ();
609}
610
611/* Read chars from INFILE until a non-whitespace char
612 and return that. Comments, both Lisp style and C style,
613 are treated as whitespace.
614 Tools such as genflags use this function. */
615
616int
617read_skip_spaces (infile)
618 FILE *infile;
619{
620 register int c;
1d300e19 621 while ((c = getc (infile)))
6f29feb1
JW
622 {
623 if (c == ' ' || c == '\n' || c == '\t' || c == '\f')
624 ;
625 else if (c == ';')
626 {
29cb1e1f
NC
627 while ((c = getc (infile)) && c != '\n' && c != EOF)
628 ;
6f29feb1
JW
629 }
630 else if (c == '/')
631 {
632 register int prevc;
633 c = getc (infile);
634 if (c != '*')
635 dump_and_abort ('*', c, infile);
636
637 prevc = 0;
29cb1e1f 638 while ((c = getc (infile)) && c != EOF)
6f29feb1
JW
639 {
640 if (prevc == '*' && c == '/')
641 break;
642 prevc = c;
643 }
644 }
645 else break;
646 }
647 return c;
648}
649
650/* Read an rtx code name into the buffer STR[].
651 It is terminated by any of the punctuation chars of rtx printed syntax. */
652
653static void
654read_name (str, infile)
655 char *str;
656 FILE *infile;
657{
658 register char *p;
659 register int c;
660
661 c = read_skip_spaces(infile);
662
663 p = str;
664 while (1)
665 {
666 if (c == ' ' || c == '\n' || c == '\t' || c == '\f')
667 break;
668 if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/'
669 || c == '(' || c == '[')
670 {
671 ungetc (c, infile);
672 break;
673 }
674 *p++ = c;
675 c = getc (infile);
676 }
677 if (p == str)
678 {
679 fprintf (stderr, "missing name or number");
680 dump_and_abort (-1, -1, infile);
681 }
682
683 *p = 0;
684}
685\f
cbe36725
RH
686/* Provide a version of a function to read a long long if the system does
687 not provide one. */
688#if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ)
689HOST_WIDE_INT
690atoll(p)
691 const char *p;
692{
693 int neg = 0;
694 HOST_WIDE_INT tmp_wide;
695
e9a780ec 696 while (ISSPACE(*p))
cbe36725
RH
697 p++;
698 if (*p == '-')
699 neg = 1, p++;
700 else if (*p == '+')
701 p++;
702
703 tmp_wide = 0;
e9a780ec 704 while (ISDIGIT(*p))
cbe36725
RH
705 {
706 HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0');
707 if (new_wide < tmp_wide)
708 {
709 /* Return INT_MAX equiv on overflow. */
710 tmp_wide = (~(unsigned HOST_WIDE_INT)0) >> 1;
711 break;
712 }
713 tmp_wide = new_wide;
714 p++;
715 }
716
717 if (neg)
718 tmp_wide = -tmp_wide;
719 return tmp_wide;
720}
721#endif
722
6f29feb1
JW
723/* Read an rtx in printed representation from INFILE
724 and return an actual rtx in core constructed accordingly.
725 read_rtx is not used in the compiler proper, but rather in
726 the utilities gen*.c that construct C code from machine descriptions. */
727
728rtx
729read_rtx (infile)
730 FILE *infile;
731{
732 register int i, j, list_counter;
733 RTX_CODE tmp_code;
6f7d635c 734 register const char *format_ptr;
6f29feb1
JW
735 /* tmp_char is a buffer used for reading decimal integers
736 and names of rtx types and machine modes.
737 Therefore, 256 must be enough. */
738 char tmp_char[256];
739 rtx return_rtx;
740 register int c;
741 int tmp_int;
c166a311 742 HOST_WIDE_INT tmp_wide;
6f29feb1
JW
743
744 /* Linked list structure for making RTXs: */
745 struct rtx_list
746 {
747 struct rtx_list *next;
748 rtx value; /* Value of this node... */
749 };
750
751 c = read_skip_spaces (infile); /* Should be open paren. */
752 if (c != '(')
753 dump_and_abort ('(', c, infile);
754
755 read_name (tmp_char, infile);
756
757 tmp_code = UNKNOWN;
758
759 for (i=0; i < NUM_RTX_CODE; i++) /* @@ might speed this search up */
760 {
761 if (!(strcmp (tmp_char, GET_RTX_NAME (i))))
762 {
763 tmp_code = (RTX_CODE) i; /* get value for name */
764 break;
765 }
766 }
767 if (tmp_code == UNKNOWN)
768 {
769 fprintf (stderr,
770 "Unknown rtx read in rtl.read_rtx(). Code name was %s .",
771 tmp_char);
772 }
773 /* (NIL) stands for an expression that isn't there. */
774 if (tmp_code == NIL)
775 {
776 /* Discard the closeparen. */
777 while ((c = getc (infile)) && c != ')');
778 return 0;
779 }
780
781 return_rtx = rtx_alloc (tmp_code); /* if we end up with an insn expression
782 then we free this space below. */
783 format_ptr = GET_RTX_FORMAT (GET_CODE (return_rtx));
784
785 /* If what follows is `: mode ', read it and
786 store the mode in the rtx. */
787
788 i = read_skip_spaces (infile);
789 if (i == ':')
790 {
791 register int k;
792 read_name (tmp_char, infile);
793 for (k = 0; k < NUM_MACHINE_MODES; k++)
794 if (!strcmp (GET_MODE_NAME (k), tmp_char))
795 break;
796
797 PUT_MODE (return_rtx, (enum machine_mode) k );
798 }
799 else
800 ungetc (i, infile);
801
802 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (return_rtx)); i++)
803 switch (*format_ptr++)
804 {
805 /* 0 means a field for internal use only.
806 Don't expect it to be present in the input. */
807 case '0':
808 break;
809
810 case 'e':
811 case 'u':
812 XEXP (return_rtx, i) = read_rtx (infile);
813 break;
814
815 case 'V':
816 /* 'V' is an optional vector: if a closeparen follows,
817 just store NULL for this element. */
818 c = read_skip_spaces (infile);
819 ungetc (c, infile);
820 if (c == ')')
821 {
822 XVEC (return_rtx, i) = 0;
823 break;
824 }
825 /* Now process the vector. */
826
827 case 'E':
828 {
829 register struct rtx_list *next_rtx, *rtx_list_link;
4399e7a3 830 struct rtx_list *list_rtx = NULL;
6f29feb1
JW
831
832 c = read_skip_spaces (infile);
833 if (c != '[')
834 dump_and_abort ('[', c, infile);
835
836 /* add expressions to a list, while keeping a count */
837 next_rtx = NULL;
838 list_counter = 0;
839 while ((c = read_skip_spaces (infile)) && c != ']')
840 {
841 ungetc (c, infile);
842 list_counter++;
843 rtx_list_link = (struct rtx_list *)
844 alloca (sizeof (struct rtx_list));
845 rtx_list_link->value = read_rtx (infile);
846 if (next_rtx == 0)
847 list_rtx = rtx_list_link;
848 else
849 next_rtx->next = rtx_list_link;
850 next_rtx = rtx_list_link;
851 rtx_list_link->next = 0;
852 }
853 /* get vector length and allocate it */
854 XVEC (return_rtx, i) = (list_counter
c166a311 855 ? rtvec_alloc (list_counter) : NULL_RTVEC);
6f29feb1
JW
856 if (list_counter > 0)
857 {
858 next_rtx = list_rtx;
859 for (j = 0; j < list_counter; j++,
860 next_rtx = next_rtx->next)
861 XVECEXP (return_rtx, i, j) = next_rtx->value;
862 }
863 /* close bracket gotten */
864 }
865 break;
866
867 case 'S':
868 /* 'S' is an optional string: if a closeparen follows,
869 just store NULL for this element. */
870 c = read_skip_spaces (infile);
871 ungetc (c, infile);
872 if (c == ')')
873 {
874 XSTR (return_rtx, i) = 0;
875 break;
876 }
877
878 case 's':
879 {
880 int saw_paren = 0;
881 register char *stringbuf;
6f29feb1
JW
882
883 c = read_skip_spaces (infile);
884 if (c == '(')
885 {
886 saw_paren = 1;
887 c = read_skip_spaces (infile);
888 }
889 if (c != '"')
890 dump_and_abort ('"', c, infile);
6f29feb1
JW
891
892 while (1)
893 {
2dcb563f
RS
894 c = getc (infile); /* Read the string */
895 if (c == '\\')
6f29feb1 896 {
2dcb563f 897 c = getc (infile); /* Read the string */
6f29feb1
JW
898 /* \; makes stuff for a C string constant containing
899 newline and tab. */
2dcb563f 900 if (c == ';')
81dd58a6
RS
901 {
902 obstack_grow (rtl_obstack, "\\n\\t", 4);
903 continue;
904 }
6f29feb1 905 }
2dcb563f 906 else if (c == '"')
6f29feb1 907 break;
2dcb563f
RS
908
909 obstack_1grow (rtl_obstack, c);
6f29feb1
JW
910 }
911
2dcb563f
RS
912 obstack_1grow (rtl_obstack, 0);
913 stringbuf = (char *) obstack_finish (rtl_obstack);
6f29feb1
JW
914
915 if (saw_paren)
916 {
917 c = read_skip_spaces (infile);
918 if (c != ')')
919 dump_and_abort (')', c, infile);
920 }
921 XSTR (return_rtx, i) = stringbuf;
922 }
923 break;
924
c166a311
CH
925 case 'w':
926 read_name (tmp_char, infile);
927#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
928 tmp_wide = atoi (tmp_char);
929#else
76d31c63 930#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
c166a311 931 tmp_wide = atol (tmp_char);
76d31c63 932#else
cbe36725
RH
933 /* Prefer atoll over atoq, since the former is in the ISO C9X draft.
934 But prefer not to use our hand-rolled function above either. */
935#if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ)
c5afbb49
JL
936 tmp_wide = atoll (tmp_char);
937#else
76d31c63
JL
938 tmp_wide = atoq (tmp_char);
939#endif
c5afbb49 940#endif
c166a311
CH
941#endif
942 XWINT (return_rtx, i) = tmp_wide;
943 break;
944
6f29feb1
JW
945 case 'i':
946 case 'n':
947 read_name (tmp_char, infile);
948 tmp_int = atoi (tmp_char);
949 XINT (return_rtx, i) = tmp_int;
950 break;
951
952 default:
953 fprintf (stderr,
954 "switch format wrong in rtl.read_rtx(). format was: %c.\n",
955 format_ptr[-1]);
956 fprintf (stderr, "\tfile position: %ld\n", ftell (infile));
957 abort ();
958 }
959
960 c = read_skip_spaces (infile);
961 if (c != ')')
962 dump_and_abort (')', c, infile);
963
964 return return_rtx;
965}
987009bf 966
b30bce6b 967#if defined ENABLE_CHECKING && HAVE_GCC_VERSION(2,7)
ef178af3
ZW
968void
969rtl_check_failed_bounds (r, n, file, line, func)
970 rtx r;
971 int n;
972 const char *file;
973 int line;
974 const char *func;
975{
976 error ("RTL check: access of elt %d of `%s' with last elt %d",
977 n, GET_RTX_NAME (GET_CODE (r)), GET_RTX_LENGTH (GET_CODE (r))-1);
978 fancy_abort (file, line, func);
979}
980
981void
982rtl_check_failed_type1 (r, n, c1, file, line, func)
983 rtx r;
984 int n;
985 int c1;
986 const char *file;
987 int line;
988 const char *func;
989{
990 error ("RTL check: expected elt %d type '%c', have '%c' (rtx %s)",
991 n, c1, GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE (r)));
992 fancy_abort (file, line, func);
993}
994
995void
996rtl_check_failed_type2 (r, n, c1, c2, file, line, func)
997 rtx r;
998 int n;
999 int c1;
1000 int c2;
1001 const char *file;
1002 int line;
1003 const char *func;
1004{
1005 error ("RTL check: expected elt %d type '%c' or '%c', have '%c' (rtx %s)",
1006 n, c1, c2,
1007 GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE(r)));
1008 fancy_abort (file, line, func);
1009}
1010
83ab3839
RH
1011void
1012rtl_check_failed_code1 (r, code, file, line, func)
1013 rtx r;
1014 enum rtx_code code;
1015 const char *file;
1016 int line;
1017 const char *func;
1018{
1019 error ("RTL check: expected code `%s', have `%s'",
1020 GET_RTX_NAME (code), GET_RTX_NAME (GET_CODE (r)));
1021 fancy_abort (file, line, func);
1022}
1023
1024void
1025rtl_check_failed_code2 (r, code1, code2, file, line, func)
1026 rtx r;
1027 enum rtx_code code1, code2;
1028 const char *file;
1029 int line;
1030 const char *func;
1031{
1032 error ("RTL check: expected code `%s' or `%s', have `%s'",
1033 GET_RTX_NAME (code1), GET_RTX_NAME (code2),
1034 GET_RTX_NAME (GET_CODE (r)));
1035 fancy_abort (file, line, func);
1036}
1037
ef178af3
ZW
1038/* XXX Maybe print the vector? */
1039void
1040rtvec_check_failed_bounds (r, n, file, line, func)
1041 rtvec r;
1042 int n;
1043 const char *file;
1044 int line;
1045 const char *func;
1046{
1047 error ("RTL check: access of elt %d of vector with last elt %d",
1048 n, GET_NUM_ELEM (r)-1);
1049 fancy_abort (file, line, func);
1050}
1051#endif /* ENABLE_CHECKING */
1052
987009bf
ZW
1053/* These are utility functions used by fatal-error functions all over the
1054 code. rtl.c happens to be linked by all the programs that need them,
1055 so these are here. In the future we want to break out all error handling
1056 to its own module. */
1057
1058/* Given a partial pathname as input, return another pathname that
1059 shares no directory elements with the pathname of __FILE__. This
1060 is used by fancy_abort() to print `Internal compiler error in expr.c'
1061 instead of `Internal compiler error in ../../egcs/gcc/expr.c'. */
1062static const char *
1063trim_filename (name)
1064 const char *name;
1065{
aa0b4465 1066 static const char this_file[] = __FILE__;
987009bf
ZW
1067 const char *p = name, *q = this_file;
1068
1069 while (*p == *q && *p != 0 && *q != 0) p++, q++;
1070 while (p > name && p[-1] != DIR_SEPARATOR
1071#ifdef DIR_SEPARATOR_2
1072 && p[-1] != DIR_SEPARATOR_2
1073#endif
1074 )
1075 p--;
1076
1077 return p;
1078}
1079
1080/* Report an internal compiler error in a friendly manner and without
ef178af3 1081 dumping core. */
987009bf
ZW
1082
1083extern void fatal PVPROTO ((const char *, ...))
ef178af3 1084 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
987009bf
ZW
1085
1086void
1087fancy_abort (file, line, function)
1088 const char *file;
1089 int line;
1090 const char *function;
1091{
1092 if (function == NULL)
1093 function = "?";
1094 fatal (
1095"Internal compiler error in `%s', at %s:%d\n\
1096Please submit a full bug report.\n\
1097See <URL:http://www.gnu.org/software/gcc/faq.html#bugreport> \
1098for instructions.",
1099 function, trim_filename (file), line);
1100}
This page took 1.107814 seconds and 5 git commands to generate.