|
|
1.1 root 1: /* Language-independent node constructors for parse phase of GNU compiler.
2: Copyright (C) 1987, 1988, 1992 Free Software Foundation, Inc.
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
18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19:
20:
21: /* This file contains the low level primitives for operating on tree nodes,
22: including allocation, list operations, interning of identifiers,
23: construction of data type nodes and statement nodes,
24: and construction of type conversion nodes. It also contains
25: tables index by tree code that describe how to take apart
26: nodes of that code.
27:
28: It is intended to be language-independent, but occasionally
29: calls language-dependent routines defined (for C) in typecheck.c.
30:
31: The low-level allocation routines oballoc and permalloc
32: are used also for allocating many other kinds of objects
33: by all passes of the compiler. */
34:
35: #include "config.h"
36: #include "flags.h"
37: #include "tree.h"
1.1.1.4 root 38: #include "function.h"
1.1 root 39: #include "obstack.h"
40: #include "gvarargs.h"
1.1.1.4 root 41: #include <stdio.h>
1.1 root 42:
43: #define obstack_chunk_alloc xmalloc
44: #define obstack_chunk_free free
45:
46: /* Tree nodes of permanent duration are allocated in this obstack.
47: They are the identifier nodes, and everything outside of
48: the bodies and parameters of function definitions. */
49:
50: struct obstack permanent_obstack;
51:
52: /* The initial RTL, and all ..._TYPE nodes, in a function
53: are allocated in this obstack. Usually they are freed at the
54: end of the function, but if the function is inline they are saved.
55: For top-level functions, this is maybepermanent_obstack.
56: Separate obstacks are made for nested functions. */
57:
58: struct obstack *function_maybepermanent_obstack;
59:
60: /* This is the function_maybepermanent_obstack for top-level functions. */
61:
62: struct obstack maybepermanent_obstack;
63:
64: /* The contents of the current function definition are allocated
65: in this obstack, and all are freed at the end of the function.
66: For top-level functions, this is temporary_obstack.
67: Separate obstacks are made for nested functions. */
68:
69: struct obstack *function_obstack;
70:
71: /* This is used for reading initializers of global variables. */
72:
73: struct obstack temporary_obstack;
74:
75: /* The tree nodes of an expression are allocated
76: in this obstack, and all are freed at the end of the expression. */
77:
78: struct obstack momentary_obstack;
79:
80: /* The tree nodes of a declarator are allocated
81: in this obstack, and all are freed when the declarator
82: has been parsed. */
83:
84: static struct obstack temp_decl_obstack;
85:
86: /* This points at either permanent_obstack
87: or the current function_maybepermanent_obstack. */
88:
89: struct obstack *saveable_obstack;
90:
91: /* This is same as saveable_obstack during parse and expansion phase;
92: it points to the current function's obstack during optimization.
93: This is the obstack to be used for creating rtl objects. */
94:
95: struct obstack *rtl_obstack;
96:
97: /* This points at either permanent_obstack or the current function_obstack. */
98:
99: struct obstack *current_obstack;
100:
101: /* This points at either permanent_obstack or the current function_obstack
102: or momentary_obstack. */
103:
104: struct obstack *expression_obstack;
105:
106: /* Stack of obstack selections for push_obstacks and pop_obstacks. */
107:
108: struct obstack_stack
109: {
110: struct obstack_stack *next;
111: struct obstack *current;
112: struct obstack *saveable;
113: struct obstack *expression;
114: struct obstack *rtl;
115: };
116:
117: struct obstack_stack *obstack_stack;
118:
119: /* Obstack for allocating struct obstack_stack entries. */
120:
121: static struct obstack obstack_stack_obstack;
122:
123: /* Addresses of first objects in some obstacks.
124: This is for freeing their entire contents. */
125: char *maybepermanent_firstobj;
126: char *temporary_firstobj;
127: char *momentary_firstobj;
128: char *temp_decl_firstobj;
129:
130: /* Nonzero means all ..._TYPE nodes should be allocated permanently. */
131:
132: int all_types_permanent;
133:
134: /* Stack of places to restore the momentary obstack back to. */
135:
136: struct momentary_level
137: {
138: /* Pointer back to previous such level. */
139: struct momentary_level *prev;
140: /* First object allocated within this level. */
141: char *base;
142: /* Value of expression_obstack saved at entry to this level. */
143: struct obstack *obstack;
144: };
145:
146: struct momentary_level *momentary_stack;
147:
148: /* Table indexed by tree code giving a string containing a character
149: classifying the tree code. Possibilities are
150: t, d, s, c, r, <, 1, 2 and e. See tree.def for details. */
151:
152: #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
153:
154: char *standard_tree_code_type[] = {
155: #include "tree.def"
156: };
157: #undef DEFTREECODE
158:
159: /* Table indexed by tree code giving number of expression
160: operands beyond the fixed part of the node structure.
161: Not used for types or decls. */
162:
163: #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
164:
165: int standard_tree_code_length[] = {
166: #include "tree.def"
167: };
168: #undef DEFTREECODE
169:
170: /* Names of tree components.
171: Used for printing out the tree and error messages. */
172: #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
173:
174: char *standard_tree_code_name[] = {
175: #include "tree.def"
176: };
177: #undef DEFTREECODE
178:
179: /* Table indexed by tree code giving a string containing a character
180: classifying the tree code. Possibilities are
181: t, d, s, c, r, e, <, 1 and 2. See tree.def for details. */
182:
183: char **tree_code_type;
184:
185: /* Table indexed by tree code giving number of expression
186: operands beyond the fixed part of the node structure.
187: Not used for types or decls. */
188:
189: int *tree_code_length;
190:
191: /* Table indexed by tree code giving name of tree code, as a string. */
192:
193: char **tree_code_name;
194:
195: /* Statistics-gathering stuff. */
196: typedef enum
197: {
1.1.1.4 root 198: d_kind,
199: t_kind,
200: b_kind,
201: s_kind,
202: r_kind,
203: e_kind,
204: c_kind,
205: id_kind,
206: op_id_kind,
207: perm_list_kind,
208: temp_list_kind,
209: vec_kind,
210: x_kind,
211: lang_decl,
212: lang_type,
213: all_kinds
1.1 root 214: } tree_node_kind;
1.1.1.4 root 215:
1.1 root 216: int tree_node_counts[(int)all_kinds];
217: int tree_node_sizes[(int)all_kinds];
218: int id_string_size = 0;
1.1.1.4 root 219:
220: char *tree_node_kind_names[] = {
221: "decls",
222: "types",
223: "blocks",
224: "stmts",
225: "refs",
226: "exprs",
227: "constants",
228: "identifiers",
229: "op_identifiers",
230: "perm_tree_lists",
231: "temp_tree_lists",
232: "vecs",
233: "random kinds",
234: "lang_decl kinds",
235: "lang_type kinds"
236: };
1.1 root 237:
238: /* Hash table for uniquizing IDENTIFIER_NODEs by name. */
239:
240: #define MAX_HASH_TABLE 1009
241: static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */
242:
243: /* 0 while creating built-in identifiers. */
244: static int do_identifier_warnings;
245:
1.1.1.4 root 246: /* Unique id for next decl created. */
247: static int next_decl_uid;
1.1.1.5 ! root 248: /* Unique id for next type created. */
! 249: static int next_type_uid = 1;
1.1.1.4 root 250:
1.1 root 251: extern char *mode_name[];
252:
253: void gcc_obstack_init ();
254: static tree stabilize_reference_1 ();
255:
256: /* Init the principal obstacks. */
257:
258: void
259: init_obstacks ()
260: {
261: gcc_obstack_init (&obstack_stack_obstack);
262: gcc_obstack_init (&permanent_obstack);
263:
264: gcc_obstack_init (&temporary_obstack);
265: temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
266: gcc_obstack_init (&momentary_obstack);
267: momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
268: gcc_obstack_init (&maybepermanent_obstack);
269: maybepermanent_firstobj
270: = (char *) obstack_alloc (&maybepermanent_obstack, 0);
271: gcc_obstack_init (&temp_decl_obstack);
272: temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
273:
274: function_obstack = &temporary_obstack;
275: function_maybepermanent_obstack = &maybepermanent_obstack;
276: current_obstack = &permanent_obstack;
277: expression_obstack = &permanent_obstack;
278: rtl_obstack = saveable_obstack = &permanent_obstack;
279:
280: /* Init the hash table of identifiers. */
281: bzero (hash_table, sizeof hash_table);
282: }
283:
284: void
285: gcc_obstack_init (obstack)
286: struct obstack *obstack;
287: {
288: /* Let particular systems override the size of a chunk. */
289: #ifndef OBSTACK_CHUNK_SIZE
290: #define OBSTACK_CHUNK_SIZE 0
291: #endif
292: /* Let them override the alloc and free routines too. */
293: #ifndef OBSTACK_CHUNK_ALLOC
294: #define OBSTACK_CHUNK_ALLOC xmalloc
295: #endif
296: #ifndef OBSTACK_CHUNK_FREE
297: #define OBSTACK_CHUNK_FREE free
298: #endif
299: _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
300: (void *(*) ()) OBSTACK_CHUNK_ALLOC,
301: (void (*) ()) OBSTACK_CHUNK_FREE);
302: }
303:
304: /* Save all variables describing the current status into the structure *P.
305: This is used before starting a nested function. */
306:
307: void
308: save_tree_status (p)
309: struct function *p;
310: {
311: p->all_types_permanent = all_types_permanent;
312: p->momentary_stack = momentary_stack;
313: p->maybepermanent_firstobj = maybepermanent_firstobj;
314: p->momentary_firstobj = momentary_firstobj;
315: p->function_obstack = function_obstack;
316: p->function_maybepermanent_obstack = function_maybepermanent_obstack;
317: p->current_obstack = current_obstack;
318: p->expression_obstack = expression_obstack;
319: p->saveable_obstack = saveable_obstack;
320: p->rtl_obstack = rtl_obstack;
321:
322: function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
323: gcc_obstack_init (function_obstack);
324:
325: function_maybepermanent_obstack
326: = (struct obstack *) xmalloc (sizeof (struct obstack));
327: gcc_obstack_init (function_maybepermanent_obstack);
328:
329: current_obstack = &permanent_obstack;
330: expression_obstack = &permanent_obstack;
331: rtl_obstack = saveable_obstack = &permanent_obstack;
332:
333: momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
334: maybepermanent_firstobj
335: = (char *) obstack_finish (function_maybepermanent_obstack);
336: }
337:
338: /* Restore all variables describing the current status from the structure *P.
339: This is used after a nested function. */
340:
341: void
342: restore_tree_status (p)
343: struct function *p;
344: {
345: all_types_permanent = p->all_types_permanent;
346: momentary_stack = p->momentary_stack;
347:
348: obstack_free (&momentary_obstack, momentary_firstobj);
349: obstack_free (function_obstack, 0);
350: obstack_free (function_maybepermanent_obstack, 0);
351: free (function_obstack);
352:
353: momentary_firstobj = p->momentary_firstobj;
354: maybepermanent_firstobj = p->maybepermanent_firstobj;
355: function_obstack = p->function_obstack;
356: function_maybepermanent_obstack = p->function_maybepermanent_obstack;
357: current_obstack = p->current_obstack;
358: expression_obstack = p->expression_obstack;
359: saveable_obstack = p->saveable_obstack;
360: rtl_obstack = p->rtl_obstack;
361: }
362:
363: /* Start allocating on the temporary (per function) obstack.
364: This is done in start_function before parsing the function body,
365: and before each initialization at top level, and to go back
366: to temporary allocation after doing end_temporary_allocation. */
367:
368: void
369: temporary_allocation ()
370: {
371: /* Note that function_obstack at top level points to temporary_obstack.
372: But within a nested function context, it is a separate obstack. */
373: current_obstack = function_obstack;
374: expression_obstack = function_obstack;
375: rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
376: momentary_stack = 0;
377: }
378:
379: /* Start allocating on the permanent obstack but don't
380: free the temporary data. After calling this, call
381: `permanent_allocation' to fully resume permanent allocation status. */
382:
383: void
384: end_temporary_allocation ()
385: {
386: current_obstack = &permanent_obstack;
387: expression_obstack = &permanent_obstack;
388: rtl_obstack = saveable_obstack = &permanent_obstack;
389: }
390:
391: /* Resume allocating on the temporary obstack, undoing
392: effects of `end_temporary_allocation'. */
393:
394: void
395: resume_temporary_allocation ()
396: {
397: current_obstack = function_obstack;
398: expression_obstack = function_obstack;
399: rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
400: }
401:
402: /* While doing temporary allocation, switch to allocating in such a
403: way as to save all nodes if the function is inlined. Call
404: resume_temporary_allocation to go back to ordinary temporary
405: allocation. */
406:
407: void
408: saveable_allocation ()
409: {
410: /* Note that function_obstack at top level points to temporary_obstack.
411: But within a nested function context, it is a separate obstack. */
412: expression_obstack = current_obstack = saveable_obstack;
413: }
414:
415: /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
416: recording the previously current obstacks on a stack.
417: This does not free any storage in any obstack. */
418:
419: void
420: push_obstacks (current, saveable)
421: struct obstack *current, *saveable;
422: {
423: struct obstack_stack *p
424: = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
425: (sizeof (struct obstack_stack)));
426:
427: p->current = current_obstack;
428: p->saveable = saveable_obstack;
429: p->expression = expression_obstack;
430: p->rtl = rtl_obstack;
431: p->next = obstack_stack;
432: obstack_stack = p;
433:
434: current_obstack = current;
435: expression_obstack = current;
436: rtl_obstack = saveable_obstack = saveable;
437: }
438:
439: /* Save the current set of obstacks, but don't change them. */
440:
441: void
442: push_obstacks_nochange ()
443: {
444: struct obstack_stack *p
445: = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
446: (sizeof (struct obstack_stack)));
447:
448: p->current = current_obstack;
449: p->saveable = saveable_obstack;
450: p->expression = expression_obstack;
451: p->rtl = rtl_obstack;
452: p->next = obstack_stack;
453: obstack_stack = p;
454: }
455:
456: /* Pop the obstack selection stack. */
457:
458: void
459: pop_obstacks ()
460: {
461: struct obstack_stack *p = obstack_stack;
462: obstack_stack = p->next;
463:
464: current_obstack = p->current;
465: saveable_obstack = p->saveable;
466: expression_obstack = p->expression;
467: rtl_obstack = p->rtl;
468:
469: obstack_free (&obstack_stack_obstack, p);
470: }
471:
472: /* Nonzero if temporary allocation is currently in effect.
473: Zero if currently doing permanent allocation. */
474:
475: int
476: allocation_temporary_p ()
477: {
478: return current_obstack != &permanent_obstack;
479: }
480:
481: /* Go back to allocating on the permanent obstack
482: and free everything in the temporary obstack.
483: This is done in finish_function after fully compiling a function. */
484:
485: void
486: permanent_allocation ()
487: {
488: /* Free up previous temporary obstack data */
489: obstack_free (&temporary_obstack, temporary_firstobj);
490: obstack_free (&momentary_obstack, momentary_firstobj);
491: obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
492: obstack_free (&temp_decl_obstack, temp_decl_firstobj);
493:
494: current_obstack = &permanent_obstack;
495: expression_obstack = &permanent_obstack;
496: rtl_obstack = saveable_obstack = &permanent_obstack;
497: }
498:
499: /* Save permanently everything on the maybepermanent_obstack. */
500:
501: void
502: preserve_data ()
503: {
504: maybepermanent_firstobj
505: = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
506: }
507:
508: void
509: preserve_initializer ()
510: {
511: temporary_firstobj
512: = (char *) obstack_alloc (&temporary_obstack, 0);
513: momentary_firstobj
514: = (char *) obstack_alloc (&momentary_obstack, 0);
515: maybepermanent_firstobj
516: = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
517: }
518:
519: /* Start allocating new rtl in current_obstack.
520: Use resume_temporary_allocation
521: to go back to allocating rtl in saveable_obstack. */
522:
523: void
524: rtl_in_current_obstack ()
525: {
526: rtl_obstack = current_obstack;
527: }
528:
1.1.1.5 ! root 529: /* Start allocating rtl from saveable_obstack. Intended to be used after
! 530: a call to push_obstacks_nochange. */
1.1 root 531:
1.1.1.5 ! root 532: void
1.1 root 533: rtl_in_saveable_obstack ()
534: {
1.1.1.5 ! root 535: rtl_obstack = saveable_obstack;
1.1 root 536: }
537:
538: /* Allocate SIZE bytes in the current obstack
539: and return a pointer to them.
540: In practice the current obstack is always the temporary one. */
541:
542: char *
543: oballoc (size)
544: int size;
545: {
546: return (char *) obstack_alloc (current_obstack, size);
547: }
548:
549: /* Free the object PTR in the current obstack
550: as well as everything allocated since PTR.
551: In practice the current obstack is always the temporary one. */
552:
553: void
554: obfree (ptr)
555: char *ptr;
556: {
557: obstack_free (current_obstack, ptr);
558: }
559:
560: /* Allocate SIZE bytes in the permanent obstack
561: and return a pointer to them. */
562:
563: char *
564: permalloc (size)
1.1.1.4 root 565: int size;
1.1 root 566: {
567: return (char *) obstack_alloc (&permanent_obstack, size);
568: }
569:
570: /* Allocate NELEM items of SIZE bytes in the permanent obstack
571: and return a pointer to them. The storage is cleared before
572: returning the value. */
573:
574: char *
575: perm_calloc (nelem, size)
576: int nelem;
577: long size;
578: {
579: char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
580: bzero (rval, nelem * size);
581: return rval;
582: }
583:
584: /* Allocate SIZE bytes in the saveable obstack
585: and return a pointer to them. */
586:
587: char *
588: savealloc (size)
589: int size;
590: {
591: return (char *) obstack_alloc (saveable_obstack, size);
592: }
593:
594: /* Print out which obstack an object is in. */
595:
596: void
597: debug_obstack (object)
598: char *object;
599: {
600: struct obstack *obstack = NULL;
601: char *obstack_name = NULL;
602: struct function *p;
603:
604: for (p = outer_function_chain; p; p = p->next)
605: {
606: if (_obstack_allocated_p (p->function_obstack, object))
607: {
608: obstack = p->function_obstack;
609: obstack_name = "containing function obstack";
610: }
611: if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
612: {
613: obstack = p->function_maybepermanent_obstack;
614: obstack_name = "containing function maybepermanent obstack";
615: }
616: }
617:
618: if (_obstack_allocated_p (&obstack_stack_obstack, object))
619: {
620: obstack = &obstack_stack_obstack;
621: obstack_name = "obstack_stack_obstack";
622: }
623: else if (_obstack_allocated_p (function_obstack, object))
624: {
625: obstack = function_obstack;
626: obstack_name = "function obstack";
627: }
628: else if (_obstack_allocated_p (&permanent_obstack, object))
629: {
630: obstack = &permanent_obstack;
631: obstack_name = "permanent_obstack";
632: }
633: else if (_obstack_allocated_p (&momentary_obstack, object))
634: {
635: obstack = &momentary_obstack;
636: obstack_name = "momentary_obstack";
637: }
638: else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
639: {
640: obstack = function_maybepermanent_obstack;
641: obstack_name = "function maybepermanent obstack";
642: }
643: else if (_obstack_allocated_p (&temp_decl_obstack, object))
644: {
645: obstack = &temp_decl_obstack;
646: obstack_name = "temp_decl_obstack";
647: }
648:
649: /* Check to see if the object is in the free area of the obstack. */
650: if (obstack != NULL)
651: {
652: if (object >= obstack->next_free
653: && object < obstack->chunk_limit)
654: fprintf (stderr, "object in free portion of obstack %s.\n",
655: obstack_name);
656: else
657: fprintf (stderr, "object allocated from %s.\n", obstack_name);
658: }
659: else
660: fprintf (stderr, "object not allocated from any obstack.\n");
661: }
662:
663: /* Return 1 if OBJ is in the permanent obstack.
664: This is slow, and should be used only for debugging.
665: Use TREE_PERMANENT for other purposes. */
666:
667: int
668: object_permanent_p (obj)
669: tree obj;
670: {
671: return _obstack_allocated_p (&permanent_obstack, obj);
672: }
673:
674: /* Start a level of momentary allocation.
675: In C, each compound statement has its own level
676: and that level is freed at the end of each statement.
677: All expression nodes are allocated in the momentary allocation level. */
678:
679: void
680: push_momentary ()
681: {
682: struct momentary_level *tem
683: = (struct momentary_level *) obstack_alloc (&momentary_obstack,
684: sizeof (struct momentary_level));
685: tem->prev = momentary_stack;
686: tem->base = (char *) obstack_base (&momentary_obstack);
687: tem->obstack = expression_obstack;
688: momentary_stack = tem;
689: expression_obstack = &momentary_obstack;
690: }
691:
692: /* Free all the storage in the current momentary-allocation level.
693: In C, this happens at the end of each statement. */
694:
695: void
696: clear_momentary ()
697: {
698: obstack_free (&momentary_obstack, momentary_stack->base);
699: }
700:
701: /* Discard a level of momentary allocation.
702: In C, this happens at the end of each compound statement.
703: Restore the status of expression node allocation
704: that was in effect before this level was created. */
705:
706: void
707: pop_momentary ()
708: {
709: struct momentary_level *tem = momentary_stack;
710: momentary_stack = tem->prev;
711: expression_obstack = tem->obstack;
712: obstack_free (&momentary_obstack, tem);
713: }
714:
715: /* Call when starting to parse a declaration:
716: make expressions in the declaration last the length of the function.
717: Returns an argument that should be passed to resume_momentary later. */
718:
719: int
720: suspend_momentary ()
721: {
722: register int tem = expression_obstack == &momentary_obstack;
723: expression_obstack = saveable_obstack;
724: return tem;
725: }
726:
727: /* Call when finished parsing a declaration:
728: restore the treatment of node-allocation that was
729: in effect before the suspension.
730: YES should be the value previously returned by suspend_momentary. */
731:
732: void
733: resume_momentary (yes)
734: int yes;
735: {
736: if (yes)
737: expression_obstack = &momentary_obstack;
738: }
739:
740: /* Init the tables indexed by tree code.
741: Note that languages can add to these tables to define their own codes. */
742:
743: void
744: init_tree_codes ()
745: {
746: tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
747: tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
748: tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
749: bcopy (standard_tree_code_type, tree_code_type,
750: sizeof (standard_tree_code_type));
751: bcopy (standard_tree_code_length, tree_code_length,
752: sizeof (standard_tree_code_length));
753: bcopy (standard_tree_code_name, tree_code_name,
754: sizeof (standard_tree_code_name));
755: }
756:
757: /* Return a newly allocated node of code CODE.
758: Initialize the node's unique id and its TREE_PERMANENT flag.
759: For decl and type nodes, some other fields are initialized.
760: The rest of the node is initialized to zero.
761:
762: Achoo! I got a code in the node. */
763:
764: tree
765: make_node (code)
766: enum tree_code code;
767: {
768: register tree t;
769: register int type = TREE_CODE_CLASS (code);
770: register int length;
771: register struct obstack *obstack = current_obstack;
772: register int i;
773: register tree_node_kind kind;
774:
775: switch (type)
776: {
777: case 'd': /* A decl node */
778: #ifdef GATHER_STATISTICS
779: kind = d_kind;
780: #endif
781: length = sizeof (struct tree_decl);
782: /* All decls in an inline function need to be saved. */
783: if (obstack != &permanent_obstack)
784: obstack = saveable_obstack;
785: /* PARM_DECLs always go on saveable_obstack, not permanent,
786: even though we may make them before the function turns
787: on temporary allocation. */
788: else if (code == PARM_DECL)
789: obstack = function_maybepermanent_obstack;
790: break;
791:
792: case 't': /* a type node */
793: #ifdef GATHER_STATISTICS
794: kind = t_kind;
795: #endif
796: length = sizeof (struct tree_type);
797: /* All data types are put where we can preserve them if nec. */
798: if (obstack != &permanent_obstack)
799: obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
800: break;
801:
1.1.1.4 root 802: case 'b': /* a lexical block */
803: #ifdef GATHER_STATISTICS
804: kind = b_kind;
805: #endif
806: length = sizeof (struct tree_block);
807: /* All BLOCK nodes are put where we can preserve them if nec. */
808: if (obstack != &permanent_obstack)
809: obstack = saveable_obstack;
810: break;
811:
1.1 root 812: case 's': /* an expression with side effects */
813: #ifdef GATHER_STATISTICS
814: kind = s_kind;
815: goto usual_kind;
816: #endif
817: case 'r': /* a reference */
818: #ifdef GATHER_STATISTICS
819: kind = r_kind;
820: goto usual_kind;
821: #endif
822: case 'e': /* an expression */
823: case '<': /* a comparison expression */
824: case '1': /* a unary arithmetic expression */
825: case '2': /* a binary arithmetic expression */
826: #ifdef GATHER_STATISTICS
827: kind = e_kind;
828: usual_kind:
829: #endif
830: obstack = expression_obstack;
1.1.1.4 root 831: /* All BIND_EXPR nodes are put where we can preserve them if nec. */
832: if (code == BIND_EXPR && obstack != &permanent_obstack)
1.1 root 833: obstack = saveable_obstack;
834: length = sizeof (struct tree_exp)
835: + (tree_code_length[(int) code] - 1) * sizeof (char *);
836: break;
837:
838: case 'c': /* a constant */
839: #ifdef GATHER_STATISTICS
840: kind = c_kind;
841: #endif
842: obstack = expression_obstack;
1.1.1.5 ! root 843:
! 844: /* We can't use tree_code_length for INTEGER_CST, since the number of
! 845: words is machine-dependent due to varying length of HOST_WIDE_INT,
! 846: which might be wider than a pointer (e.g., long long). Similarly
! 847: for REAL_CST, since the number of words is machine-dependent due
! 848: to varying size and alignment of `double'. */
! 849:
! 850: if (code == INTEGER_CST)
! 851: length = sizeof (struct tree_int_cst);
! 852: else if (code == REAL_CST)
! 853: length = sizeof (struct tree_real_cst);
! 854: else
! 855: length = sizeof (struct tree_common)
! 856: + tree_code_length[(int) code] * sizeof (char *);
! 857: break;
1.1 root 858:
859: case 'x': /* something random, like an identifier. */
860: #ifdef GATHER_STATISTICS
861: if (code == IDENTIFIER_NODE)
862: kind = id_kind;
863: else if (code == OP_IDENTIFIER)
864: kind = op_id_kind;
865: else if (code == TREE_VEC)
866: kind = vec_kind;
867: else
868: kind = x_kind;
869: #endif
870: length = sizeof (struct tree_common)
871: + tree_code_length[(int) code] * sizeof (char *);
872: /* Identifier nodes are always permanent since they are
873: unique in a compiler run. */
874: if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
875: }
876:
877: t = (tree) obstack_alloc (obstack, length);
878:
879: #ifdef GATHER_STATISTICS
880: tree_node_counts[(int)kind]++;
881: tree_node_sizes[(int)kind] += length;
882: #endif
883:
1.1.1.4 root 884: /* Clear a word at a time. */
885: for (i = (length / sizeof (int)) - 1; i >= 0; i--)
1.1 root 886: ((int *) t)[i] = 0;
1.1.1.4 root 887: /* Clear any extra bytes. */
888: for (i = length / sizeof (int) * sizeof (int); i < length; i++)
889: ((char *) t)[i] = 0;
1.1 root 890:
891: TREE_SET_CODE (t, code);
892: if (obstack == &permanent_obstack)
893: TREE_PERMANENT (t) = 1;
894:
895: switch (type)
896: {
897: case 's':
898: TREE_SIDE_EFFECTS (t) = 1;
899: TREE_TYPE (t) = void_type_node;
900: break;
901:
902: case 'd':
1.1.1.3 root 903: if (code != FUNCTION_DECL)
904: DECL_ALIGN (t) = 1;
1.1.1.4 root 905: DECL_IN_SYSTEM_HEADER (t)
906: = in_system_header && (obstack == &permanent_obstack);
1.1 root 907: DECL_SOURCE_LINE (t) = lineno;
908: DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
1.1.1.4 root 909: DECL_UID (t) = next_decl_uid++;
1.1 root 910: break;
911:
912: case 't':
1.1.1.5 ! root 913: TYPE_UID (t) = next_type_uid++;
1.1 root 914: TYPE_ALIGN (t) = 1;
915: TYPE_MAIN_VARIANT (t) = t;
916: break;
917:
918: case 'c':
919: TREE_CONSTANT (t) = 1;
920: break;
921: }
922:
923: return t;
924: }
925:
926: /* Return a new node with the same contents as NODE
927: except that its TREE_CHAIN is zero and it has a fresh uid. */
928:
929: tree
930: copy_node (node)
931: tree node;
932: {
933: register tree t;
934: register enum tree_code code = TREE_CODE (node);
935: register int length;
936: register int i;
937:
938: switch (TREE_CODE_CLASS (code))
939: {
940: case 'd': /* A decl node */
941: length = sizeof (struct tree_decl);
942: break;
943:
944: case 't': /* a type node */
945: length = sizeof (struct tree_type);
946: break;
947:
1.1.1.4 root 948: case 'b': /* a lexical block node */
949: length = sizeof (struct tree_block);
950: break;
951:
1.1 root 952: case 'r': /* a reference */
1.1.1.4 root 953: case 'e': /* an expression */
1.1 root 954: case 's': /* an expression with side effects */
955: case '<': /* a comparison expression */
956: case '1': /* a unary arithmetic expression */
957: case '2': /* a binary arithmetic expression */
958: length = sizeof (struct tree_exp)
959: + (tree_code_length[(int) code] - 1) * sizeof (char *);
960: break;
961:
962: case 'c': /* a constant */
963: /* We can't use tree_code_length for this, since the number of words
964: is machine-dependent due to varying alignment of `double'. */
965: if (code == REAL_CST)
966: {
967: length = sizeof (struct tree_real_cst);
968: break;
969: }
970:
971: case 'x': /* something random, like an identifier. */
972: length = sizeof (struct tree_common)
973: + tree_code_length[(int) code] * sizeof (char *);
974: if (code == TREE_VEC)
975: length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
976: }
977:
978: t = (tree) obstack_alloc (current_obstack, length);
979:
1.1.1.4 root 980: for (i = (length / sizeof (int)) - 1; i >= 0; i--)
1.1 root 981: ((int *) t)[i] = ((int *) node)[i];
1.1.1.4 root 982: /* Clear any extra bytes. */
983: for (i = length / sizeof (int) * sizeof (int); i < length; i++)
984: ((char *) t)[i] = ((char *) node)[i];
1.1 root 985:
986: TREE_CHAIN (t) = 0;
987:
1.1.1.5 ! root 988: if (TREE_CODE_CLASS (code) == 'd')
! 989: DECL_UID (t) = next_decl_uid++;
! 990: else if (TREE_CODE_CLASS (code) == 't')
! 991: TYPE_UID (t) = next_type_uid++;
! 992:
1.1 root 993: TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
994:
995: return t;
996: }
997:
998: /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
999: For example, this can copy a list made of TREE_LIST nodes. */
1000:
1001: tree
1002: copy_list (list)
1003: tree list;
1004: {
1005: tree head;
1006: register tree prev, next;
1007:
1008: if (list == 0)
1009: return 0;
1010:
1011: head = prev = copy_node (list);
1012: next = TREE_CHAIN (list);
1013: while (next)
1014: {
1015: TREE_CHAIN (prev) = copy_node (next);
1016: prev = TREE_CHAIN (prev);
1017: next = TREE_CHAIN (next);
1018: }
1019: return head;
1020: }
1021:
1022: #define HASHBITS 30
1023:
1024: /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
1025: If an identifier with that name has previously been referred to,
1026: the same node is returned this time. */
1027:
1028: tree
1029: get_identifier (text)
1030: register char *text;
1031: {
1032: register int hi;
1033: register int i;
1034: register tree idp;
1035: register int len, hash_len;
1036:
1037: /* Compute length of text in len. */
1038: for (len = 0; text[len]; len++);
1039:
1040: /* Decide how much of that length to hash on */
1041: hash_len = len;
1042: if (warn_id_clash && len > id_clash_len)
1043: hash_len = id_clash_len;
1044:
1045: /* Compute hash code */
1046: hi = hash_len * 613 + (unsigned)text[0];
1047: for (i = 1; i < hash_len; i += 2)
1048: hi = ((hi * 613) + (unsigned)(text[i]));
1049:
1050: hi &= (1 << HASHBITS) - 1;
1051: hi %= MAX_HASH_TABLE;
1052:
1053: /* Search table for identifier */
1054: for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1055: if (IDENTIFIER_LENGTH (idp) == len
1056: && IDENTIFIER_POINTER (idp)[0] == text[0]
1057: && !bcmp (IDENTIFIER_POINTER (idp), text, len))
1058: return idp; /* <-- return if found */
1059:
1060: /* Not found; optionally warn about a similar identifier */
1061: if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
1062: for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
1063: if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
1064: {
1065: warning ("`%s' and `%s' identical in first %d characters",
1066: IDENTIFIER_POINTER (idp), text, id_clash_len);
1067: break;
1068: }
1069:
1070: if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
1071: abort (); /* set_identifier_size hasn't been called. */
1072:
1073: /* Not found, create one, add to chain */
1074: idp = make_node (IDENTIFIER_NODE);
1075: IDENTIFIER_LENGTH (idp) = len;
1076: #ifdef GATHER_STATISTICS
1077: id_string_size += len;
1078: #endif
1079:
1080: IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
1081:
1082: TREE_CHAIN (idp) = hash_table[hi];
1083: hash_table[hi] = idp;
1084: return idp; /* <-- return if created */
1085: }
1086:
1087: /* Enable warnings on similar identifiers (if requested).
1088: Done after the built-in identifiers are created. */
1089:
1090: void
1091: start_identifier_warnings ()
1092: {
1093: do_identifier_warnings = 1;
1094: }
1095:
1096: /* Record the size of an identifier node for the language in use.
1097: SIZE is the total size in bytes.
1098: This is called by the language-specific files. This must be
1099: called before allocating any identifiers. */
1100:
1101: void
1102: set_identifier_size (size)
1103: int size;
1104: {
1105: tree_code_length[(int) IDENTIFIER_NODE]
1106: = (size - sizeof (struct tree_common)) / sizeof (tree);
1107: }
1108:
1109: /* Return a newly constructed INTEGER_CST node whose constant value
1110: is specified by the two ints LOW and HI.
1.1.1.4 root 1111: The TREE_TYPE is set to `int'.
1112:
1113: This function should be used via the `build_int_2' macro. */
1.1 root 1114:
1115: tree
1.1.1.4 root 1116: build_int_2_wide (low, hi)
1117: HOST_WIDE_INT low, hi;
1.1 root 1118: {
1119: register tree t = make_node (INTEGER_CST);
1120: TREE_INT_CST_LOW (t) = low;
1121: TREE_INT_CST_HIGH (t) = hi;
1122: TREE_TYPE (t) = integer_type_node;
1123: return t;
1124: }
1125:
1126: /* Return a new REAL_CST node whose type is TYPE and value is D. */
1127:
1128: tree
1129: build_real (type, d)
1130: tree type;
1131: REAL_VALUE_TYPE d;
1132: {
1133: tree v;
1134:
1135: /* Check for valid float value for this type on this target machine;
1136: if not, can print error message and store a valid value in D. */
1137: #ifdef CHECK_FLOAT_VALUE
1138: CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
1139: #endif
1140:
1141: v = make_node (REAL_CST);
1142: TREE_TYPE (v) = type;
1143: TREE_REAL_CST (v) = d;
1144: return v;
1145: }
1146:
1147: /* Return a new REAL_CST node whose type is TYPE
1148: and whose value is the integer value of the INTEGER_CST node I. */
1149:
1150: #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1151:
1152: REAL_VALUE_TYPE
1153: real_value_from_int_cst (i)
1154: tree i;
1155: {
1156: REAL_VALUE_TYPE d;
1.1.1.5 ! root 1157: REAL_VALUE_TYPE e;
! 1158: /* Some 386 compilers mishandle unsigned int to float conversions,
! 1159: so introduce a temporary variable E to avoid those bugs. */
! 1160:
1.1 root 1161: #ifdef REAL_ARITHMETIC
1.1.1.5 ! root 1162: if (! TREE_UNSIGNED (TREE_TYPE (i)))
! 1163: REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
! 1164: else
! 1165: REAL_VALUE_FROM_UNSIGNED_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
1.1 root 1166: #else /* not REAL_ARITHMETIC */
1.1.1.4 root 1167: if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i)))
1.1 root 1168: {
1169: d = (double) (~ TREE_INT_CST_HIGH (i));
1.1.1.5 ! root 1170: e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1.1.1.4 root 1171: * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1.1.1.5 ! root 1172: d *= e;
! 1173: e = (double) (unsigned HOST_WIDE_INT) (~ TREE_INT_CST_LOW (i));
! 1174: d += e;
1.1 root 1175: d = (- d - 1.0);
1176: }
1177: else
1178: {
1.1.1.4 root 1179: d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i);
1.1.1.5 ! root 1180: e = ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
1.1.1.4 root 1181: * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
1.1.1.5 ! root 1182: d *= e;
! 1183: e = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (i);
! 1184: d += e;
1.1 root 1185: }
1186: #endif /* not REAL_ARITHMETIC */
1187: return d;
1188: }
1189:
1190: /* This function can't be implemented if we can't do arithmetic
1191: on the float representation. */
1192:
1193: tree
1194: build_real_from_int_cst (type, i)
1195: tree type;
1196: tree i;
1197: {
1198: tree v;
1199: REAL_VALUE_TYPE d;
1200:
1201: v = make_node (REAL_CST);
1202: TREE_TYPE (v) = type;
1203:
1.1.1.4 root 1204: d = REAL_VALUE_TRUNCATE (TYPE_MODE (type), real_value_from_int_cst (i));
1.1 root 1205: /* Check for valid float value for this type on this target machine;
1206: if not, can print error message and store a valid value in D. */
1207: #ifdef CHECK_FLOAT_VALUE
1208: CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
1209: #endif
1210:
1211: TREE_REAL_CST (v) = d;
1212: return v;
1213: }
1214:
1215: #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
1216:
1217: /* Return a newly constructed STRING_CST node whose value is
1218: the LEN characters at STR.
1219: The TREE_TYPE is not initialized. */
1220:
1221: tree
1222: build_string (len, str)
1223: int len;
1224: char *str;
1225: {
1226: register tree s = make_node (STRING_CST);
1227: TREE_STRING_LENGTH (s) = len;
1228: TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
1229: return s;
1230: }
1231:
1232: /* Return a newly constructed COMPLEX_CST node whose value is
1233: specified by the real and imaginary parts REAL and IMAG.
1234: Both REAL and IMAG should be constant nodes.
1235: The TREE_TYPE is not initialized. */
1236:
1237: tree
1238: build_complex (real, imag)
1239: tree real, imag;
1240: {
1241: register tree t = make_node (COMPLEX_CST);
1242: TREE_REALPART (t) = real;
1243: TREE_IMAGPART (t) = imag;
1.1.1.5 ! root 1244: TREE_TYPE (t) = build_complex_type (TREE_TYPE (real));
1.1 root 1245: return t;
1246: }
1247:
1248: /* Build a newly constructed TREE_VEC node of length LEN. */
1249: tree
1250: make_tree_vec (len)
1251: int len;
1252: {
1253: register tree t;
1254: register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
1255: register struct obstack *obstack = current_obstack;
1256: register int i;
1257:
1258: #ifdef GATHER_STATISTICS
1259: tree_node_counts[(int)vec_kind]++;
1260: tree_node_sizes[(int)vec_kind] += length;
1261: #endif
1262:
1263: t = (tree) obstack_alloc (obstack, length);
1264:
1.1.1.4 root 1265: for (i = (length / sizeof (int)) - 1; i >= 0; i--)
1.1 root 1266: ((int *) t)[i] = 0;
1.1.1.4 root 1267:
1.1 root 1268: TREE_SET_CODE (t, TREE_VEC);
1269: TREE_VEC_LENGTH (t) = len;
1270: if (obstack == &permanent_obstack)
1271: TREE_PERMANENT (t) = 1;
1272:
1273: return t;
1274: }
1275:
1276: /* Return 1 if EXPR is the integer constant zero. */
1277:
1278: int
1279: integer_zerop (expr)
1280: tree expr;
1281: {
1.1.1.4 root 1282: STRIP_NOPS (expr);
1.1 root 1283:
1284: return (TREE_CODE (expr) == INTEGER_CST
1285: && TREE_INT_CST_LOW (expr) == 0
1286: && TREE_INT_CST_HIGH (expr) == 0);
1287: }
1288:
1289: /* Return 1 if EXPR is the integer constant one. */
1290:
1291: int
1292: integer_onep (expr)
1293: tree expr;
1294: {
1.1.1.4 root 1295: STRIP_NOPS (expr);
1.1 root 1296:
1297: return (TREE_CODE (expr) == INTEGER_CST
1298: && TREE_INT_CST_LOW (expr) == 1
1299: && TREE_INT_CST_HIGH (expr) == 0);
1300: }
1301:
1302: /* Return 1 if EXPR is an integer containing all 1's
1303: in as much precision as it contains. */
1304:
1305: int
1306: integer_all_onesp (expr)
1307: tree expr;
1308: {
1309: register int prec;
1310: register int uns;
1311:
1.1.1.4 root 1312: STRIP_NOPS (expr);
1.1 root 1313:
1314: if (TREE_CODE (expr) != INTEGER_CST)
1315: return 0;
1316:
1317: uns = TREE_UNSIGNED (TREE_TYPE (expr));
1318: if (!uns)
1319: return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
1320:
1321: prec = TYPE_PRECISION (TREE_TYPE (expr));
1.1.1.4 root 1322: if (prec >= HOST_BITS_PER_WIDE_INT)
1.1 root 1323: {
1324: int high_value, shift_amount;
1325:
1.1.1.4 root 1326: shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1.1 root 1327:
1.1.1.4 root 1328: if (shift_amount > HOST_BITS_PER_WIDE_INT)
1.1 root 1329: /* Can not handle precisions greater than twice the host int size. */
1330: abort ();
1.1.1.4 root 1331: else if (shift_amount == HOST_BITS_PER_WIDE_INT)
1.1 root 1332: /* Shifting by the host word size is undefined according to the ANSI
1333: standard, so we must handle this as a special case. */
1334: high_value = -1;
1335: else
1.1.1.4 root 1336: high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1.1 root 1337:
1338: return TREE_INT_CST_LOW (expr) == -1
1339: && TREE_INT_CST_HIGH (expr) == high_value;
1340: }
1341: else
1.1.1.4 root 1342: return TREE_INT_CST_LOW (expr) == ((HOST_WIDE_INT) 1 << prec) - 1;
1.1 root 1343: }
1344:
1345: /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1346: one bit on). */
1347:
1348: int
1349: integer_pow2p (expr)
1350: tree expr;
1351: {
1.1.1.4 root 1352: HOST_WIDE_INT high, low;
1.1 root 1353:
1.1.1.4 root 1354: STRIP_NOPS (expr);
1.1 root 1355:
1356: if (TREE_CODE (expr) != INTEGER_CST)
1357: return 0;
1358:
1359: high = TREE_INT_CST_HIGH (expr);
1360: low = TREE_INT_CST_LOW (expr);
1361:
1362: if (high == 0 && low == 0)
1363: return 0;
1364:
1365: return ((high == 0 && (low & (low - 1)) == 0)
1366: || (low == 0 && (high & (high - 1)) == 0));
1367: }
1368:
1369: /* Return 1 if EXPR is the real constant zero. */
1370:
1371: int
1372: real_zerop (expr)
1373: tree expr;
1374: {
1.1.1.4 root 1375: STRIP_NOPS (expr);
1.1 root 1376:
1377: return (TREE_CODE (expr) == REAL_CST
1378: && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0));
1379: }
1380:
1381: /* Return 1 if EXPR is the real constant one. */
1382:
1383: int
1384: real_onep (expr)
1385: tree expr;
1386: {
1.1.1.4 root 1387: STRIP_NOPS (expr);
1.1 root 1388:
1389: return (TREE_CODE (expr) == REAL_CST
1390: && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1));
1391: }
1392:
1393: /* Return 1 if EXPR is the real constant two. */
1394:
1395: int
1396: real_twop (expr)
1397: tree expr;
1398: {
1.1.1.4 root 1399: STRIP_NOPS (expr);
1.1 root 1400:
1401: return (TREE_CODE (expr) == REAL_CST
1402: && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2));
1403: }
1404:
1405: /* Nonzero if EXP is a constant or a cast of a constant. */
1406:
1407: int
1408: really_constant_p (exp)
1409: tree exp;
1410: {
1.1.1.4 root 1411: /* This is not quite the same as STRIP_NOPS. It does more. */
1.1 root 1412: while (TREE_CODE (exp) == NOP_EXPR
1413: || TREE_CODE (exp) == CONVERT_EXPR
1414: || TREE_CODE (exp) == NON_LVALUE_EXPR)
1415: exp = TREE_OPERAND (exp, 0);
1416: return TREE_CONSTANT (exp);
1417: }
1418:
1419: /* Return first list element whose TREE_VALUE is ELEM.
1420: Return 0 if ELEM is not it LIST. */
1421:
1422: tree
1423: value_member (elem, list)
1424: tree elem, list;
1425: {
1426: while (list)
1427: {
1428: if (elem == TREE_VALUE (list))
1429: return list;
1430: list = TREE_CHAIN (list);
1431: }
1432: return NULL_TREE;
1433: }
1434:
1435: /* Return first list element whose TREE_PURPOSE is ELEM.
1436: Return 0 if ELEM is not it LIST. */
1437:
1438: tree
1439: purpose_member (elem, list)
1440: tree elem, list;
1441: {
1442: while (list)
1443: {
1444: if (elem == TREE_PURPOSE (list))
1445: return list;
1446: list = TREE_CHAIN (list);
1447: }
1448: return NULL_TREE;
1449: }
1450:
1451: /* Return first list element whose BINFO_TYPE is ELEM.
1452: Return 0 if ELEM is not it LIST. */
1453:
1454: tree
1455: binfo_member (elem, list)
1456: tree elem, list;
1457: {
1458: while (list)
1459: {
1460: if (elem == BINFO_TYPE (list))
1461: return list;
1462: list = TREE_CHAIN (list);
1463: }
1464: return NULL_TREE;
1465: }
1466:
1467: /* Return nonzero if ELEM is part of the chain CHAIN. */
1468:
1469: int
1470: chain_member (elem, chain)
1471: tree elem, chain;
1472: {
1473: while (chain)
1474: {
1475: if (elem == chain)
1476: return 1;
1477: chain = TREE_CHAIN (chain);
1478: }
1479:
1480: return 0;
1481: }
1482:
1483: /* Return the length of a chain of nodes chained through TREE_CHAIN.
1484: We expect a null pointer to mark the end of the chain.
1485: This is the Lisp primitive `length'. */
1486:
1487: int
1488: list_length (t)
1489: tree t;
1490: {
1491: register tree tail;
1492: register int len = 0;
1493:
1494: for (tail = t; tail; tail = TREE_CHAIN (tail))
1495: len++;
1496:
1497: return len;
1498: }
1499:
1500: /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1501: by modifying the last node in chain 1 to point to chain 2.
1502: This is the Lisp primitive `nconc'. */
1503:
1504: tree
1505: chainon (op1, op2)
1506: tree op1, op2;
1507: {
1508: tree t;
1509:
1510: if (op1)
1511: {
1512: for (t = op1; TREE_CHAIN (t); t = TREE_CHAIN (t))
1513: if (t == op2) abort (); /* Circularity being created */
1.1.1.4 root 1514: if (t == op2) abort (); /* Circularity being created */
1.1 root 1515: TREE_CHAIN (t) = op2;
1516: return op1;
1517: }
1518: else return op2;
1519: }
1520:
1521: /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1522:
1523: tree
1524: tree_last (chain)
1525: register tree chain;
1526: {
1527: register tree next;
1528: if (chain)
1529: while (next = TREE_CHAIN (chain))
1530: chain = next;
1531: return chain;
1532: }
1533:
1534: /* Reverse the order of elements in the chain T,
1535: and return the new head of the chain (old last element). */
1536:
1537: tree
1538: nreverse (t)
1539: tree t;
1540: {
1541: register tree prev = 0, decl, next;
1542: for (decl = t; decl; decl = next)
1543: {
1544: next = TREE_CHAIN (decl);
1545: TREE_CHAIN (decl) = prev;
1546: prev = decl;
1547: }
1548: return prev;
1549: }
1550:
1551: /* Given a chain CHAIN of tree nodes,
1552: construct and return a list of those nodes. */
1553:
1554: tree
1555: listify (chain)
1556: tree chain;
1557: {
1558: tree result = NULL_TREE;
1559: tree in_tail = chain;
1560: tree out_tail = NULL_TREE;
1561:
1562: while (in_tail)
1563: {
1564: tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
1565: if (out_tail)
1566: TREE_CHAIN (out_tail) = next;
1567: else
1568: result = next;
1569: out_tail = next;
1570: in_tail = TREE_CHAIN (in_tail);
1571: }
1572:
1573: return result;
1574: }
1575:
1576: /* Return a newly created TREE_LIST node whose
1577: purpose and value fields are PARM and VALUE. */
1578:
1579: tree
1580: build_tree_list (parm, value)
1581: tree parm, value;
1582: {
1583: register tree t = make_node (TREE_LIST);
1584: TREE_PURPOSE (t) = parm;
1585: TREE_VALUE (t) = value;
1586: return t;
1587: }
1588:
1589: /* Similar, but build on the temp_decl_obstack. */
1590:
1591: tree
1592: build_decl_list (parm, value)
1593: tree parm, value;
1594: {
1595: register tree node;
1596: register struct obstack *ambient_obstack = current_obstack;
1597: current_obstack = &temp_decl_obstack;
1598: node = build_tree_list (parm, value);
1599: current_obstack = ambient_obstack;
1600: return node;
1601: }
1602:
1603: /* Return a newly created TREE_LIST node whose
1604: purpose and value fields are PARM and VALUE
1605: and whose TREE_CHAIN is CHAIN. */
1606:
1607: tree
1608: tree_cons (purpose, value, chain)
1609: tree purpose, value, chain;
1610: {
1611: #if 0
1612: register tree node = make_node (TREE_LIST);
1613: #else
1614: register int i;
1615: register tree node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
1616: #ifdef GATHER_STATISTICS
1617: tree_node_counts[(int)x_kind]++;
1618: tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
1619: #endif
1620:
1.1.1.4 root 1621: for (i = (sizeof (struct tree_common) / sizeof (int)) - 1; i >= 0; i--)
1622: ((int *) node)[i] = 0;
1623:
1.1 root 1624: TREE_SET_CODE (node, TREE_LIST);
1625: if (current_obstack == &permanent_obstack)
1626: TREE_PERMANENT (node) = 1;
1627: #endif
1628:
1629: TREE_CHAIN (node) = chain;
1630: TREE_PURPOSE (node) = purpose;
1631: TREE_VALUE (node) = value;
1632: return node;
1633: }
1634:
1635: /* Similar, but build on the temp_decl_obstack. */
1636:
1637: tree
1638: decl_tree_cons (purpose, value, chain)
1639: tree purpose, value, chain;
1640: {
1641: register tree node;
1642: register struct obstack *ambient_obstack = current_obstack;
1643: current_obstack = &temp_decl_obstack;
1644: node = tree_cons (purpose, value, chain);
1645: current_obstack = ambient_obstack;
1646: return node;
1647: }
1648:
1649: /* Same as `tree_cons' but make a permanent object. */
1650:
1651: tree
1652: perm_tree_cons (purpose, value, chain)
1653: tree purpose, value, chain;
1654: {
1655: register tree node;
1656: register struct obstack *ambient_obstack = current_obstack;
1657: current_obstack = &permanent_obstack;
1658:
1659: node = tree_cons (purpose, value, chain);
1660: current_obstack = ambient_obstack;
1661: return node;
1662: }
1663:
1664: /* Same as `tree_cons', but make this node temporary, regardless. */
1665:
1666: tree
1667: temp_tree_cons (purpose, value, chain)
1668: tree purpose, value, chain;
1669: {
1670: register tree node;
1671: register struct obstack *ambient_obstack = current_obstack;
1672: current_obstack = &temporary_obstack;
1673:
1674: node = tree_cons (purpose, value, chain);
1675: current_obstack = ambient_obstack;
1676: return node;
1677: }
1678:
1679: /* Same as `tree_cons', but save this node if the function's RTL is saved. */
1680:
1681: tree
1682: saveable_tree_cons (purpose, value, chain)
1683: tree purpose, value, chain;
1684: {
1685: register tree node;
1686: register struct obstack *ambient_obstack = current_obstack;
1687: current_obstack = saveable_obstack;
1688:
1689: node = tree_cons (purpose, value, chain);
1690: current_obstack = ambient_obstack;
1691: return node;
1692: }
1693:
1694: /* Return the size nominally occupied by an object of type TYPE
1695: when it resides in memory. The value is measured in units of bytes,
1696: and its data type is that normally used for type sizes
1697: (which is the first type created by make_signed_type or
1698: make_unsigned_type). */
1699:
1700: tree
1701: size_in_bytes (type)
1702: tree type;
1703: {
1.1.1.5 ! root 1704: tree t;
! 1705:
1.1 root 1706: if (type == error_mark_node)
1707: return integer_zero_node;
1708: type = TYPE_MAIN_VARIANT (type);
1709: if (TYPE_SIZE (type) == 0)
1710: {
1.1.1.4 root 1711: incomplete_type_error (NULL_TREE, type);
1.1 root 1712: return integer_zero_node;
1713: }
1.1.1.5 ! root 1714: t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
! 1715: size_int (BITS_PER_UNIT));
! 1716: if (TREE_CODE (t) == INTEGER_CST)
! 1717: force_fit_type (t, 0);
! 1718: return t;
1.1 root 1719: }
1720:
1721: /* Return the size of TYPE (in bytes) as an integer,
1722: or return -1 if the size can vary. */
1723:
1724: int
1725: int_size_in_bytes (type)
1726: tree type;
1727: {
1.1.1.5 ! root 1728: unsigned int size;
1.1 root 1729: if (type == error_mark_node)
1730: return 0;
1731: type = TYPE_MAIN_VARIANT (type);
1732: if (TYPE_SIZE (type) == 0)
1733: return -1;
1734: if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1735: return -1;
1.1.1.5 ! root 1736: if (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0)
! 1737: {
! 1738: tree t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
! 1739: size_int (BITS_PER_UNIT));
! 1740: return TREE_INT_CST_LOW (t);
! 1741: }
1.1 root 1742: size = TREE_INT_CST_LOW (TYPE_SIZE (type));
1743: return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
1744: }
1745:
1746: /* Return, as an INTEGER_CST node, the number of elements for
1.1.1.2 root 1747: TYPE (which is an ARRAY_TYPE) minus one.
1748: This counts only elements of the top array. */
1.1 root 1749:
1750: tree
1751: array_type_nelts (type)
1752: tree type;
1753: {
1754: tree index_type = TYPE_DOMAIN (type);
1755: return (tree_int_cst_equal (TYPE_MIN_VALUE (index_type), integer_zero_node)
1756: ? TYPE_MAX_VALUE (index_type)
1757: : fold (build (MINUS_EXPR, integer_type_node,
1758: TYPE_MAX_VALUE (index_type),
1759: TYPE_MIN_VALUE (index_type))));
1760: }
1761:
1762: /* Return nonzero if arg is static -- a reference to an object in
1763: static storage. This is not the same as the C meaning of `static'. */
1764:
1765: int
1766: staticp (arg)
1767: tree arg;
1768: {
1769: switch (TREE_CODE (arg))
1770: {
1771: case VAR_DECL:
1772: case FUNCTION_DECL:
1773: case CONSTRUCTOR:
1.1.1.4 root 1774: return TREE_STATIC (arg) || DECL_EXTERNAL (arg);
1.1 root 1775:
1776: case STRING_CST:
1777: return 1;
1778:
1779: case COMPONENT_REF:
1780: case BIT_FIELD_REF:
1781: return staticp (TREE_OPERAND (arg, 0));
1782:
1783: case INDIRECT_REF:
1784: return TREE_CONSTANT (TREE_OPERAND (arg, 0));
1785:
1786: case ARRAY_REF:
1787: if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
1788: && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
1789: return staticp (TREE_OPERAND (arg, 0));
1790: }
1791:
1792: return 0;
1793: }
1794:
1795: /* This should be applied to any node which may be used in more than one place,
1796: but must be evaluated only once. Normally, the code generator would
1797: reevaluate the node each time; this forces it to compute it once and save
1798: the result. This is done by encapsulating the node in a SAVE_EXPR. */
1799:
1800: tree
1801: save_expr (expr)
1802: tree expr;
1803: {
1804: register tree t = fold (expr);
1805:
1806: /* We don't care about whether this can be used as an lvalue in this
1807: context. */
1808: while (TREE_CODE (t) == NON_LVALUE_EXPR)
1809: t = TREE_OPERAND (t, 0);
1810:
1811: /* If the tree evaluates to a constant, then we don't want to hide that
1812: fact (i.e. this allows further folding, and direct checks for constants).
1.1.1.3 root 1813: However, a read-only object that has side effects cannot be bypassed.
1.1 root 1814: Since it is no problem to reevaluate literals, we just return the
1815: literal node. */
1816:
1.1.1.3 root 1817: if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
1818: || TREE_CODE (t) == SAVE_EXPR)
1.1 root 1819: return t;
1820:
1.1.1.4 root 1821: t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
1.1 root 1822:
1823: /* This expression might be placed ahead of a jump to ensure that the
1824: value was computed on both sides of the jump. So make sure it isn't
1825: eliminated as dead. */
1826: TREE_SIDE_EFFECTS (t) = 1;
1827: return t;
1828: }
1829:
1830: /* Stabilize a reference so that we can use it any number of times
1831: without causing its operands to be evaluated more than once.
1832: Returns the stabilized reference.
1833:
1834: Also allows conversion expressions whose operands are references.
1835: Any other kind of expression is returned unchanged. */
1836:
1837: tree
1838: stabilize_reference (ref)
1839: tree ref;
1840: {
1841: register tree result;
1842: register enum tree_code code = TREE_CODE (ref);
1843:
1844: switch (code)
1845: {
1846: case VAR_DECL:
1847: case PARM_DECL:
1848: case RESULT_DECL:
1849: /* No action is needed in this case. */
1850: return ref;
1851:
1852: case NOP_EXPR:
1853: case CONVERT_EXPR:
1854: case FLOAT_EXPR:
1855: case FIX_TRUNC_EXPR:
1856: case FIX_FLOOR_EXPR:
1857: case FIX_ROUND_EXPR:
1858: case FIX_CEIL_EXPR:
1859: result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
1860: break;
1861:
1862: case INDIRECT_REF:
1863: result = build_nt (INDIRECT_REF,
1864: stabilize_reference_1 (TREE_OPERAND (ref, 0)));
1865: break;
1866:
1867: case COMPONENT_REF:
1868: result = build_nt (COMPONENT_REF,
1869: stabilize_reference (TREE_OPERAND (ref, 0)),
1870: TREE_OPERAND (ref, 1));
1871: break;
1872:
1873: case BIT_FIELD_REF:
1874: result = build_nt (BIT_FIELD_REF,
1875: stabilize_reference (TREE_OPERAND (ref, 0)),
1876: stabilize_reference_1 (TREE_OPERAND (ref, 1)),
1877: stabilize_reference_1 (TREE_OPERAND (ref, 2)));
1878: break;
1879:
1880: case ARRAY_REF:
1881: result = build_nt (ARRAY_REF,
1882: stabilize_reference (TREE_OPERAND (ref, 0)),
1883: stabilize_reference_1 (TREE_OPERAND (ref, 1)));
1884: break;
1885:
1886: /* If arg isn't a kind of lvalue we recognize, make no change.
1887: Caller should recognize the error for an invalid lvalue. */
1888: default:
1889: return ref;
1890:
1891: case ERROR_MARK:
1892: return error_mark_node;
1893: }
1894:
1895: TREE_TYPE (result) = TREE_TYPE (ref);
1896: TREE_READONLY (result) = TREE_READONLY (ref);
1897: TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
1898: TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
1899: TREE_RAISES (result) = TREE_RAISES (ref);
1900:
1901: return result;
1902: }
1903:
1904: /* Subroutine of stabilize_reference; this is called for subtrees of
1905: references. Any expression with side-effects must be put in a SAVE_EXPR
1906: to ensure that it is only evaluated once.
1907:
1908: We don't put SAVE_EXPR nodes around everything, because assigning very
1909: simple expressions to temporaries causes us to miss good opportunities
1910: for optimizations. Among other things, the opportunity to fold in the
1911: addition of a constant into an addressing mode often gets lost, e.g.
1912: "y[i+1] += x;". In general, we take the approach that we should not make
1913: an assignment unless we are forced into it - i.e., that any non-side effect
1914: operator should be allowed, and that cse should take care of coalescing
1915: multiple utterances of the same expression should that prove fruitful. */
1916:
1917: static tree
1918: stabilize_reference_1 (e)
1919: tree e;
1920: {
1921: register tree result;
1922: register int length;
1923: register enum tree_code code = TREE_CODE (e);
1924:
1.1.1.3 root 1925: /* We cannot ignore const expressions because it might be a reference
1926: to a const array but whose index contains side-effects. But we can
1927: ignore things that are actual constant or that already have been
1928: handled by this function. */
1929:
1930: if (TREE_CONSTANT (e) || code == SAVE_EXPR)
1.1 root 1931: return e;
1932:
1933: switch (TREE_CODE_CLASS (code))
1934: {
1935: case 'x':
1936: case 't':
1937: case 'd':
1.1.1.4 root 1938: case 'b':
1.1 root 1939: case '<':
1940: case 's':
1941: case 'e':
1942: case 'r':
1943: /* If the expression has side-effects, then encase it in a SAVE_EXPR
1944: so that it will only be evaluated once. */
1945: /* The reference (r) and comparison (<) classes could be handled as
1946: below, but it is generally faster to only evaluate them once. */
1947: if (TREE_SIDE_EFFECTS (e))
1948: return save_expr (e);
1949: return e;
1950:
1951: case 'c':
1952: /* Constants need no processing. In fact, we should never reach
1953: here. */
1954: return e;
1955:
1956: case '2':
1.1.1.5 ! root 1957: /* Division is slow and tends to be compiled with jumps,
! 1958: especially the division by powers of 2 that is often
! 1959: found inside of an array reference. So do it just once. */
! 1960: if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
! 1961: || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
! 1962: || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
! 1963: || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
! 1964: return save_expr (e);
1.1 root 1965: /* Recursively stabilize each operand. */
1966: result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
1967: stabilize_reference_1 (TREE_OPERAND (e, 1)));
1968: break;
1969:
1970: case '1':
1971: /* Recursively stabilize each operand. */
1972: result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
1973: break;
1974: }
1975:
1976: TREE_TYPE (result) = TREE_TYPE (e);
1977: TREE_READONLY (result) = TREE_READONLY (e);
1978: TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
1979: TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
1980: TREE_RAISES (result) = TREE_RAISES (e);
1981:
1982: return result;
1983: }
1984:
1985: /* Low-level constructors for expressions. */
1986:
1987: /* Build an expression of code CODE, data type TYPE,
1988: and operands as specified by the arguments ARG1 and following arguments.
1989: Expressions and reference nodes can be created this way.
1990: Constants, decls, types and misc nodes cannot be. */
1991:
1992: tree
1993: build (va_alist)
1994: va_dcl
1995: {
1996: va_list p;
1997: enum tree_code code;
1998: register tree t;
1999: register int length;
2000: register int i;
2001:
2002: va_start (p);
2003:
2004: code = va_arg (p, enum tree_code);
2005: t = make_node (code);
2006: length = tree_code_length[(int) code];
2007: TREE_TYPE (t) = va_arg (p, tree);
2008:
2009: if (length == 2)
2010: {
2011: /* This is equivalent to the loop below, but faster. */
2012: register tree arg0 = va_arg (p, tree);
2013: register tree arg1 = va_arg (p, tree);
2014: TREE_OPERAND (t, 0) = arg0;
2015: TREE_OPERAND (t, 1) = arg1;
2016: if ((arg0 && TREE_SIDE_EFFECTS (arg0))
2017: || (arg1 && TREE_SIDE_EFFECTS (arg1)))
2018: TREE_SIDE_EFFECTS (t) = 1;
2019: TREE_RAISES (t)
2020: = (arg0 && TREE_RAISES (arg0)) || (arg1 && TREE_RAISES (arg1));
2021: }
2022: else if (length == 1)
2023: {
2024: register tree arg0 = va_arg (p, tree);
2025:
2026: /* Call build1 for this! */
2027: if (TREE_CODE_CLASS (code) != 's')
2028: abort ();
2029: TREE_OPERAND (t, 0) = arg0;
2030: if (arg0 && TREE_SIDE_EFFECTS (arg0))
2031: TREE_SIDE_EFFECTS (t) = 1;
2032: TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
2033: }
2034: else
2035: {
2036: for (i = 0; i < length; i++)
2037: {
2038: register tree operand = va_arg (p, tree);
2039: TREE_OPERAND (t, i) = operand;
2040: if (operand)
2041: {
2042: if (TREE_SIDE_EFFECTS (operand))
2043: TREE_SIDE_EFFECTS (t) = 1;
2044: if (TREE_RAISES (operand))
2045: TREE_RAISES (t) = 1;
2046: }
2047: }
2048: }
2049: va_end (p);
2050: return t;
2051: }
2052:
2053: /* Same as above, but only builds for unary operators.
2054: Saves lions share of calls to `build'; cuts down use
2055: of varargs, which is expensive for RISC machines. */
2056: tree
2057: build1 (code, type, node)
2058: enum tree_code code;
2059: tree type;
2060: tree node;
2061: {
2062: register struct obstack *obstack = current_obstack;
2063: register int i, length;
2064: register tree_node_kind kind;
2065: register tree t;
2066:
2067: #ifdef GATHER_STATISTICS
2068: if (TREE_CODE_CLASS (code) == 'r')
2069: kind = r_kind;
2070: else
2071: kind = e_kind;
2072: #endif
2073:
2074: obstack = expression_obstack;
2075: length = sizeof (struct tree_exp);
2076:
2077: t = (tree) obstack_alloc (obstack, length);
2078:
2079: #ifdef GATHER_STATISTICS
2080: tree_node_counts[(int)kind]++;
2081: tree_node_sizes[(int)kind] += length;
2082: #endif
2083:
1.1.1.4 root 2084: for (i = (length / sizeof (int)) - 1; i >= 0; i--)
1.1 root 2085: ((int *) t)[i] = 0;
1.1.1.4 root 2086:
2087: TREE_TYPE (t) = type;
1.1 root 2088: TREE_SET_CODE (t, code);
2089:
2090: if (obstack == &permanent_obstack)
2091: TREE_PERMANENT (t) = 1;
2092:
2093: TREE_OPERAND (t, 0) = node;
2094: if (node)
2095: {
2096: if (TREE_SIDE_EFFECTS (node))
2097: TREE_SIDE_EFFECTS (t) = 1;
2098: if (TREE_RAISES (node))
2099: TREE_RAISES (t) = 1;
2100: }
2101:
2102: return t;
2103: }
2104:
2105: /* Similar except don't specify the TREE_TYPE
2106: and leave the TREE_SIDE_EFFECTS as 0.
2107: It is permissible for arguments to be null,
2108: or even garbage if their values do not matter. */
2109:
2110: tree
2111: build_nt (va_alist)
2112: va_dcl
2113: {
2114: va_list p;
2115: register enum tree_code code;
2116: register tree t;
2117: register int length;
2118: register int i;
2119:
2120: va_start (p);
2121:
2122: code = va_arg (p, enum tree_code);
2123: t = make_node (code);
2124: length = tree_code_length[(int) code];
2125:
2126: for (i = 0; i < length; i++)
2127: TREE_OPERAND (t, i) = va_arg (p, tree);
2128:
2129: va_end (p);
2130: return t;
2131: }
2132:
2133: /* Similar to `build_nt', except we build
2134: on the temp_decl_obstack, regardless. */
2135:
2136: tree
2137: build_parse_node (va_alist)
2138: va_dcl
2139: {
2140: register struct obstack *ambient_obstack = expression_obstack;
2141: va_list p;
2142: register enum tree_code code;
2143: register tree t;
2144: register int length;
2145: register int i;
2146:
2147: expression_obstack = &temp_decl_obstack;
2148:
2149: va_start (p);
2150:
2151: code = va_arg (p, enum tree_code);
2152: t = make_node (code);
2153: length = tree_code_length[(int) code];
2154:
2155: for (i = 0; i < length; i++)
2156: TREE_OPERAND (t, i) = va_arg (p, tree);
2157:
2158: va_end (p);
2159: expression_obstack = ambient_obstack;
2160: return t;
2161: }
2162:
2163: #if 0
2164: /* Commented out because this wants to be done very
2165: differently. See cp-lex.c. */
2166: tree
2167: build_op_identifier (op1, op2)
2168: tree op1, op2;
2169: {
2170: register tree t = make_node (OP_IDENTIFIER);
2171: TREE_PURPOSE (t) = op1;
2172: TREE_VALUE (t) = op2;
2173: return t;
2174: }
2175: #endif
2176:
2177: /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
2178: We do NOT enter this node in any sort of symbol table.
2179:
2180: layout_decl is used to set up the decl's storage layout.
2181: Other slots are initialized to 0 or null pointers. */
2182:
2183: tree
2184: build_decl (code, name, type)
2185: enum tree_code code;
2186: tree name, type;
2187: {
2188: register tree t;
2189:
2190: t = make_node (code);
2191:
2192: /* if (type == error_mark_node)
2193: type = integer_type_node; */
2194: /* That is not done, deliberately, so that having error_mark_node
2195: as the type can suppress useless errors in the use of this variable. */
2196:
2197: DECL_NAME (t) = name;
2198: DECL_ASSEMBLER_NAME (t) = name;
2199: TREE_TYPE (t) = type;
2200:
2201: if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
2202: layout_decl (t, 0);
2203: else if (code == FUNCTION_DECL)
2204: DECL_MODE (t) = FUNCTION_MODE;
2205:
2206: return t;
2207: }
2208:
2209: /* BLOCK nodes are used to represent the structure of binding contours
2210: and declarations, once those contours have been exited and their contents
1.1.1.4 root 2211: compiled. This information is used for outputting debugging info. */
1.1 root 2212:
2213: tree
2214: build_block (vars, tags, subblocks, supercontext, chain)
2215: tree vars, tags, subblocks, supercontext, chain;
2216: {
2217: register tree block = make_node (BLOCK);
2218: BLOCK_VARS (block) = vars;
2219: BLOCK_TYPE_TAGS (block) = tags;
2220: BLOCK_SUBBLOCKS (block) = subblocks;
2221: BLOCK_SUPERCONTEXT (block) = supercontext;
2222: BLOCK_CHAIN (block) = chain;
2223: return block;
2224: }
2225:
2226: /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
2227: and its TYPE_VOLATILE is VOLATILEP.
2228:
2229: Such variant types already made are recorded so that duplicates
2230: are not made.
2231:
2232: A variant types should never be used as the type of an expression.
2233: Always copy the variant information into the TREE_READONLY
2234: and TREE_THIS_VOLATILE of the expression, and then give the expression
2235: as its type the "main variant", the variant whose TYPE_READONLY
2236: and TYPE_VOLATILE are zero. Use TYPE_MAIN_VARIANT to find the
2237: main variant. */
2238:
2239: tree
2240: build_type_variant (type, constp, volatilep)
2241: tree type;
2242: int constp, volatilep;
2243: {
2244: register tree t, m = TYPE_MAIN_VARIANT (type);
2245: register struct obstack *ambient_obstack = current_obstack;
2246:
2247: /* Treat any nonzero argument as 1. */
2248: constp = !!constp;
2249: volatilep = !!volatilep;
2250:
1.1.1.2 root 2251: /* If not generating auxiliary info, search the chain of variants to see
1.1 root 2252: if there is already one there just like the one we need to have. If so,
2253: use that existing one.
2254:
2255: We don't do this in the case where we are generating aux info because
2256: in that case we want each typedef names to get it's own distinct type
2257: node, even if the type of this new typedef is the same as some other
2258: (existing) type. */
2259:
2260: if (!flag_gen_aux_info)
2261: for (t = m; t; t = TYPE_NEXT_VARIANT (t))
2262: if (constp == TYPE_READONLY (t) && volatilep == TYPE_VOLATILE (t))
2263: return t;
2264:
2265: /* We need a new one. */
2266: current_obstack
2267: = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
2268:
2269: t = copy_node (type);
2270: TYPE_READONLY (t) = constp;
2271: TYPE_VOLATILE (t) = volatilep;
2272: TYPE_POINTER_TO (t) = 0;
2273: TYPE_REFERENCE_TO (t) = 0;
2274:
2275: /* Add this type to the chain of variants of TYPE. */
2276: TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
2277: TYPE_NEXT_VARIANT (m) = t;
2278:
2279: current_obstack = ambient_obstack;
2280: return t;
2281: }
1.1.1.2 root 2282:
1.1.1.5 ! root 2283: /* Give TYPE a new main variant: NEW_MAIN.
! 2284: This is the right thing to do only when something else
! 2285: about TYPE is modified in place. */
! 2286:
! 2287: tree
! 2288: change_main_variant (type, new_main)
! 2289: tree type, new_main;
! 2290: {
! 2291: tree t;
! 2292: tree omain = TYPE_MAIN_VARIANT (type);
! 2293:
! 2294: /* Remove TYPE from the TYPE_NEXT_VARIANT chain of its main variant. */
! 2295: if (TYPE_NEXT_VARIANT (omain) == type)
! 2296: TYPE_NEXT_VARIANT (omain) = TYPE_NEXT_VARIANT (type);
! 2297: else
! 2298: for (t = TYPE_NEXT_VARIANT (omain); t && TYPE_NEXT_VARIANT (t);
! 2299: t = TYPE_NEXT_VARIANT (t))
! 2300: if (TYPE_NEXT_VARIANT (t) == type)
! 2301: {
! 2302: TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (type);
! 2303: break;
! 2304: }
! 2305:
! 2306: TYPE_MAIN_VARIANT (type) = new_main;
! 2307: TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (new_main);
! 2308: TYPE_NEXT_VARIANT (new_main) = type;
! 2309: }
! 2310:
1.1.1.2 root 2311: /* Create a new variant of TYPE, equivalent but distinct.
2312: This is so the caller can modify it. */
2313:
2314: tree
2315: build_type_copy (type)
2316: tree type;
2317: {
2318: register tree t, m = TYPE_MAIN_VARIANT (type);
2319: register struct obstack *ambient_obstack = current_obstack;
2320:
2321: current_obstack
2322: = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
2323:
2324: t = copy_node (type);
2325: TYPE_POINTER_TO (t) = 0;
2326: TYPE_REFERENCE_TO (t) = 0;
2327:
2328: /* Add this type to the chain of variants of TYPE. */
2329: TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
2330: TYPE_NEXT_VARIANT (m) = t;
2331:
2332: current_obstack = ambient_obstack;
2333: return t;
2334: }
1.1 root 2335:
2336: /* Hashing of types so that we don't make duplicates.
2337: The entry point is `type_hash_canon'. */
2338:
2339: /* Each hash table slot is a bucket containing a chain
2340: of these structures. */
2341:
2342: struct type_hash
2343: {
2344: struct type_hash *next; /* Next structure in the bucket. */
2345: int hashcode; /* Hash code of this type. */
2346: tree type; /* The type recorded here. */
2347: };
2348:
2349: /* Now here is the hash table. When recording a type, it is added
2350: to the slot whose index is the hash code mod the table size.
2351: Note that the hash table is used for several kinds of types
2352: (function types, array types and array index range types, for now).
2353: While all these live in the same table, they are completely independent,
2354: and the hash code is computed differently for each of these. */
2355:
2356: #define TYPE_HASH_SIZE 59
2357: struct type_hash *type_hash_table[TYPE_HASH_SIZE];
2358:
2359: /* Here is how primitive or already-canonicalized types' hash
2360: codes are made. */
1.1.1.4 root 2361: #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
1.1 root 2362:
2363: /* Compute a hash code for a list of types (chain of TREE_LIST nodes
2364: with types in the TREE_VALUE slots), by adding the hash codes
2365: of the individual types. */
2366:
2367: int
2368: type_hash_list (list)
2369: tree list;
2370: {
2371: register int hashcode;
2372: register tree tail;
2373: for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
2374: hashcode += TYPE_HASH (TREE_VALUE (tail));
2375: return hashcode;
2376: }
2377:
2378: /* Look in the type hash table for a type isomorphic to TYPE.
2379: If one is found, return it. Otherwise return 0. */
2380:
2381: tree
2382: type_hash_lookup (hashcode, type)
2383: int hashcode;
2384: tree type;
2385: {
2386: register struct type_hash *h;
2387: for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
2388: if (h->hashcode == hashcode
2389: && TREE_CODE (h->type) == TREE_CODE (type)
2390: && TREE_TYPE (h->type) == TREE_TYPE (type)
2391: && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
2392: || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
2393: TYPE_MAX_VALUE (type)))
2394: && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
2395: || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
2396: TYPE_MIN_VALUE (type)))
2397: && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
2398: || (TYPE_DOMAIN (h->type)
2399: && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
2400: && TYPE_DOMAIN (type)
2401: && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
2402: && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
2403: return h->type;
2404: return 0;
2405: }
2406:
2407: /* Add an entry to the type-hash-table
2408: for a type TYPE whose hash code is HASHCODE. */
2409:
2410: void
2411: type_hash_add (hashcode, type)
2412: int hashcode;
2413: tree type;
2414: {
2415: register struct type_hash *h;
2416:
2417: h = (struct type_hash *) oballoc (sizeof (struct type_hash));
2418: h->hashcode = hashcode;
2419: h->type = type;
2420: h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
2421: type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
2422: }
2423:
2424: /* Given TYPE, and HASHCODE its hash code, return the canonical
2425: object for an identical type if one already exists.
2426: Otherwise, return TYPE, and record it as the canonical object
2427: if it is a permanent object.
2428:
2429: To use this function, first create a type of the sort you want.
2430: Then compute its hash code from the fields of the type that
2431: make it different from other similar types.
2432: Then call this function and use the value.
2433: This function frees the type you pass in if it is a duplicate. */
2434:
2435: /* Set to 1 to debug without canonicalization. Never set by program. */
2436: int debug_no_type_hash = 0;
2437:
2438: tree
2439: type_hash_canon (hashcode, type)
2440: int hashcode;
2441: tree type;
2442: {
2443: tree t1;
2444:
2445: if (debug_no_type_hash)
2446: return type;
2447:
2448: t1 = type_hash_lookup (hashcode, type);
2449: if (t1 != 0)
2450: {
2451: struct obstack *o
2452: = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
2453: obstack_free (o, type);
2454: #ifdef GATHER_STATISTICS
2455: tree_node_counts[(int)t_kind]--;
2456: tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
2457: #endif
2458: return t1;
2459: }
2460:
2461: /* If this is a new type, record it for later reuse. */
2462: if (current_obstack == &permanent_obstack)
2463: type_hash_add (hashcode, type);
2464:
2465: return type;
2466: }
2467:
2468: /* Given two lists of types
2469: (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
2470: return 1 if the lists contain the same types in the same order.
2471: Also, the TREE_PURPOSEs must match. */
2472:
2473: int
2474: type_list_equal (l1, l2)
2475: tree l1, l2;
2476: {
2477: register tree t1, t2;
2478: for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
2479: {
2480: if (TREE_VALUE (t1) != TREE_VALUE (t2))
2481: return 0;
2482: if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2))
2483: {
2484: int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
2485: if (cmp < 0)
2486: abort ();
2487: if (cmp == 0)
2488: return 0;
2489: }
2490: }
2491:
2492: return t1 == t2;
2493: }
2494:
2495: /* Nonzero if integer constants T1 and T2
2496: represent the same constant value. */
2497:
2498: int
2499: tree_int_cst_equal (t1, t2)
2500: tree t1, t2;
2501: {
2502: if (t1 == t2)
2503: return 1;
2504: if (t1 == 0 || t2 == 0)
2505: return 0;
2506: if (TREE_CODE (t1) == INTEGER_CST
2507: && TREE_CODE (t2) == INTEGER_CST
2508: && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
2509: && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
2510: return 1;
2511: return 0;
2512: }
2513:
2514: /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
2515: The precise way of comparison depends on their data type. */
2516:
2517: int
2518: tree_int_cst_lt (t1, t2)
2519: tree t1, t2;
2520: {
2521: if (t1 == t2)
2522: return 0;
2523:
2524: if (!TREE_UNSIGNED (TREE_TYPE (t1)))
2525: return INT_CST_LT (t1, t2);
2526: return INT_CST_LT_UNSIGNED (t1, t2);
2527: }
2528:
2529: /* Compare two constructor-element-type constants. */
2530: int
2531: simple_cst_list_equal (l1, l2)
2532: tree l1, l2;
2533: {
2534: while (l1 != NULL_TREE && l2 != NULL_TREE)
2535: {
2536: int cmp = simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2));
2537: if (cmp < 0)
2538: abort ();
2539: if (cmp == 0)
2540: return 0;
2541: l1 = TREE_CHAIN (l1);
2542: l2 = TREE_CHAIN (l2);
2543: }
2544: return (l1 == l2);
2545: }
2546:
2547: /* Return truthvalue of whether T1 is the same tree structure as T2.
2548: Return 1 if they are the same.
2549: Return 0 if they are understandably different.
2550: Return -1 if either contains tree structure not understood by
2551: this function. */
2552:
2553: int
2554: simple_cst_equal (t1, t2)
2555: tree t1, t2;
2556: {
2557: register enum tree_code code1, code2;
2558: int cmp;
2559:
2560: if (t1 == t2)
2561: return 1;
2562: if (t1 == 0 || t2 == 0)
2563: return 0;
2564:
2565: code1 = TREE_CODE (t1);
2566: code2 = TREE_CODE (t2);
2567:
2568: if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
2569: if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
2570: return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2571: else
2572: return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
2573: else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
2574: || code2 == NON_LVALUE_EXPR)
2575: return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
2576:
2577: if (code1 != code2)
2578: return 0;
2579:
2580: switch (code1)
2581: {
2582: case INTEGER_CST:
2583: return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
2584: && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
2585:
2586: case REAL_CST:
2587: return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2588:
2589: case STRING_CST:
2590: return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2591: && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2592: TREE_STRING_LENGTH (t1));
2593:
2594: case CONSTRUCTOR:
2595: abort ();
2596:
2597: case SAVE_EXPR:
2598: return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2599:
2600: case CALL_EXPR:
2601: cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2602: if (cmp <= 0)
2603: return cmp;
2604: return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2605:
2606: case TARGET_EXPR:
2607: /* Special case: if either target is an unallocated VAR_DECL,
2608: it means that it's going to be unified with whatever the
2609: TARGET_EXPR is really supposed to initialize, so treat it
2610: as being equivalent to anything. */
2611: if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
2612: && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
2613: && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
2614: || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
2615: && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
2616: && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
2617: cmp = 1;
2618: else
2619: cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2620: if (cmp <= 0)
2621: return cmp;
2622: return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
2623:
2624: case WITH_CLEANUP_EXPR:
2625: cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2626: if (cmp <= 0)
2627: return cmp;
2628: return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
2629:
2630: case COMPONENT_REF:
2631: if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
2632: return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2633: return 0;
2634:
2635: case VAR_DECL:
2636: case PARM_DECL:
2637: case CONST_DECL:
2638: case FUNCTION_DECL:
2639: return 0;
1.1.1.5 ! root 2640: }
1.1 root 2641:
1.1.1.5 ! root 2642: /* This general rule works for most tree codes.
! 2643: All exceptions should be handled above. */
1.1 root 2644:
1.1.1.5 ! root 2645: switch (TREE_CODE_CLASS (code1))
! 2646: {
! 2647: int i;
! 2648: case '1':
! 2649: case '2':
! 2650: case '<':
! 2651: case 'e':
! 2652: case 'r':
! 2653: case 's':
! 2654: cmp = 1;
! 2655: for (i=0; i<tree_code_length[(int) code1]; ++i)
! 2656: {
! 2657: cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
! 2658: if (cmp <= 0)
! 2659: return cmp;
! 2660: }
! 2661: return cmp;
1.1 root 2662: }
1.1.1.5 ! root 2663:
! 2664: return -1;
1.1 root 2665: }
2666:
2667: /* Constructors for pointer, array and function types.
2668: (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
2669: constructed by language-dependent code, not here.) */
2670:
2671: /* Construct, lay out and return the type of pointers to TO_TYPE.
2672: If such a type has already been constructed, reuse it. */
2673:
2674: tree
2675: build_pointer_type (to_type)
2676: tree to_type;
2677: {
2678: register tree t = TYPE_POINTER_TO (to_type);
2679: register struct obstack *ambient_obstack = current_obstack;
2680: register struct obstack *ambient_saveable_obstack = saveable_obstack;
2681:
2682: /* First, if we already have a type for pointers to TO_TYPE, use it. */
2683:
2684: if (t)
2685: return t;
2686:
2687: /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
2688: if (TREE_PERMANENT (to_type))
2689: {
2690: current_obstack = &permanent_obstack;
2691: saveable_obstack = &permanent_obstack;
2692: }
2693:
2694: t = make_node (POINTER_TYPE);
2695: TREE_TYPE (t) = to_type;
2696:
2697: /* Record this type as the pointer to TO_TYPE. */
2698: TYPE_POINTER_TO (to_type) = t;
2699:
2700: /* Lay out the type. This function has many callers that are concerned
2701: with expression-construction, and this simplifies them all.
2702: Also, it guarantees the TYPE_SIZE is permanent if the type is. */
2703: layout_type (t);
2704:
2705: current_obstack = ambient_obstack;
2706: saveable_obstack = ambient_saveable_obstack;
2707: return t;
2708: }
2709:
2710: /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
2711: MAXVAL should be the maximum value in the domain
2712: (one less than the length of the array). */
2713:
2714: tree
2715: build_index_type (maxval)
2716: tree maxval;
2717: {
2718: register tree itype = make_node (INTEGER_TYPE);
2719: TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
2720: TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
2721: TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
2722: TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
2723: TYPE_MODE (itype) = TYPE_MODE (sizetype);
2724: TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
2725: TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
2726: if (TREE_CODE (maxval) == INTEGER_CST)
2727: {
1.1.1.4 root 2728: int maxint = (int) TREE_INT_CST_LOW (maxval);
1.1.1.5 ! root 2729: /* If the domain should be empty, make sure the maxval
! 2730: remains -1 and is not spoiled by truncation. */
! 2731: if (INT_CST_LT (maxval, integer_zero_node))
! 2732: {
! 2733: TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1);
! 2734: TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype;
! 2735: }
1.1.1.4 root 2736: return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
1.1 root 2737: }
2738: else
2739: return itype;
2740: }
2741:
1.1.1.5 ! root 2742: /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
! 2743: ENUMERAL_TYPE, BOOLEAN_TYPE, or CHAR_TYPE), with
! 2744: low bound LOWVAL and high bound HIGHVAL.
! 2745: if TYPE==NULL_TREE, sizetype is used. */
1.1 root 2746:
2747: tree
1.1.1.5 ! root 2748: build_range_type (type, lowval, highval)
! 2749: tree type, lowval, highval;
1.1 root 2750: {
2751: register tree itype = make_node (INTEGER_TYPE);
1.1.1.5 ! root 2752: TREE_TYPE (itype) = type;
! 2753: if (type == NULL_TREE)
! 2754: type = sizetype;
! 2755: TYPE_PRECISION (itype) = TYPE_PRECISION (type);
! 2756: TYPE_MIN_VALUE (itype) = convert (type, lowval);
! 2757: TYPE_MAX_VALUE (itype) = convert (type, highval);
! 2758: TYPE_MODE (itype) = TYPE_MODE (type);
! 2759: TYPE_SIZE (itype) = TYPE_SIZE (type);
! 2760: TYPE_ALIGN (itype) = TYPE_ALIGN (type);
1.1 root 2761: if ((TREE_CODE (lowval) == INTEGER_CST)
2762: && (TREE_CODE (highval) == INTEGER_CST))
2763: {
1.1.1.4 root 2764: HOST_WIDE_INT highint = TREE_INT_CST_LOW (highval);
2765: HOST_WIDE_INT lowint = TREE_INT_CST_LOW (lowval);
2766: int maxint = (int) (highint - lowint);
2767: return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
1.1 root 2768: }
2769: else
2770: return itype;
2771: }
2772:
1.1.1.5 ! root 2773: /* Just like build_index_type, but takes lowval and highval instead
! 2774: of just highval (maxval). */
! 2775:
! 2776: tree
! 2777: build_index_2_type (lowval,highval)
! 2778: tree lowval, highval;
! 2779: {
! 2780: return build_range_type (NULL_TREE, lowval, highval);
! 2781: }
! 2782:
1.1 root 2783: /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
2784: Needed because when index types are not hashed, equal index types
2785: built at different times appear distinct, even though structurally,
2786: they are not. */
2787:
2788: int
2789: index_type_equal (itype1, itype2)
2790: tree itype1, itype2;
2791: {
2792: if (TREE_CODE (itype1) != TREE_CODE (itype2))
2793: return 0;
2794: if (TREE_CODE (itype1) == INTEGER_TYPE)
2795: {
2796: if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
2797: || TYPE_MODE (itype1) != TYPE_MODE (itype2)
2798: || ! simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2))
2799: || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
2800: return 0;
2801: if (simple_cst_equal (TYPE_MIN_VALUE (itype1), TYPE_MIN_VALUE (itype2))
2802: && simple_cst_equal (TYPE_MAX_VALUE (itype1), TYPE_MAX_VALUE (itype2)))
2803: return 1;
2804: }
2805: return 0;
2806: }
2807:
2808: /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
2809: and number of elements specified by the range of values of INDEX_TYPE.
2810: If such a type has already been constructed, reuse it. */
2811:
2812: tree
2813: build_array_type (elt_type, index_type)
2814: tree elt_type, index_type;
2815: {
2816: register tree t;
2817: int hashcode;
2818:
2819: if (TREE_CODE (elt_type) == FUNCTION_TYPE)
2820: {
2821: error ("arrays of functions are not meaningful");
2822: elt_type = integer_type_node;
2823: }
2824:
2825: /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
2826: build_pointer_type (elt_type);
2827:
2828: /* Allocate the array after the pointer type,
2829: in case we free it in type_hash_canon. */
2830: t = make_node (ARRAY_TYPE);
2831: TREE_TYPE (t) = elt_type;
2832: TYPE_DOMAIN (t) = index_type;
2833:
2834: if (index_type == 0)
1.1.1.5 ! root 2835: {
! 2836: return t;
! 2837: }
1.1 root 2838:
2839: hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
2840: t = type_hash_canon (hashcode, t);
2841:
1.1.1.5 ! root 2842: #if 0 /* This led to crashes, because it could put a temporary node
! 2843: on the TYPE_NEXT_VARIANT chain of a permanent one. */
! 2844: /* The main variant of an array type should always
! 2845: be an array whose element type is the main variant. */
! 2846: if (elt_type != TYPE_MAIN_VARIANT (elt_type))
! 2847: change_main_variant (t, build_array_type (TYPE_MAIN_VARIANT (elt_type),
! 2848: index_type));
! 2849: #endif
! 2850:
1.1 root 2851: if (TYPE_SIZE (t) == 0)
2852: layout_type (t);
2853: return t;
2854: }
2855:
2856: /* Construct, lay out and return
2857: the type of functions returning type VALUE_TYPE
2858: given arguments of types ARG_TYPES.
2859: ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
2860: are data type nodes for the arguments of the function.
2861: If such a type has already been constructed, reuse it. */
2862:
2863: tree
2864: build_function_type (value_type, arg_types)
2865: tree value_type, arg_types;
2866: {
2867: register tree t;
2868: int hashcode;
2869:
2870: if (TREE_CODE (value_type) == FUNCTION_TYPE
2871: || TREE_CODE (value_type) == ARRAY_TYPE)
2872: {
2873: error ("function return type cannot be function or array");
2874: value_type = integer_type_node;
2875: }
2876:
2877: /* Make a node of the sort we want. */
2878: t = make_node (FUNCTION_TYPE);
2879: TREE_TYPE (t) = value_type;
2880: TYPE_ARG_TYPES (t) = arg_types;
2881:
2882: /* If we already have such a type, use the old one and free this one. */
2883: hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
2884: t = type_hash_canon (hashcode, t);
2885:
2886: if (TYPE_SIZE (t) == 0)
2887: layout_type (t);
2888: return t;
2889: }
2890:
2891: /* Build the node for the type of references-to-TO_TYPE. */
2892:
2893: tree
2894: build_reference_type (to_type)
2895: tree to_type;
2896: {
2897: register tree t = TYPE_REFERENCE_TO (to_type);
2898: register struct obstack *ambient_obstack = current_obstack;
2899: register struct obstack *ambient_saveable_obstack = saveable_obstack;
2900:
2901: /* First, if we already have a type for pointers to TO_TYPE, use it. */
2902:
2903: if (t)
2904: return t;
2905:
2906: /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
2907: if (TREE_PERMANENT (to_type))
2908: {
2909: current_obstack = &permanent_obstack;
2910: saveable_obstack = &permanent_obstack;
2911: }
2912:
2913: t = make_node (REFERENCE_TYPE);
2914: TREE_TYPE (t) = to_type;
2915:
2916: /* Record this type as the pointer to TO_TYPE. */
2917: TYPE_REFERENCE_TO (to_type) = t;
2918:
2919: layout_type (t);
2920:
2921: current_obstack = ambient_obstack;
2922: saveable_obstack = ambient_saveable_obstack;
2923: return t;
2924: }
2925:
2926: /* Construct, lay out and return the type of methods belonging to class
2927: BASETYPE and whose arguments and values are described by TYPE.
2928: If that type exists already, reuse it.
2929: TYPE must be a FUNCTION_TYPE node. */
2930:
2931: tree
2932: build_method_type (basetype, type)
2933: tree basetype, type;
2934: {
2935: register tree t;
2936: int hashcode;
2937:
2938: /* Make a node of the sort we want. */
2939: t = make_node (METHOD_TYPE);
2940:
2941: if (TREE_CODE (type) != FUNCTION_TYPE)
2942: abort ();
2943:
2944: TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
2945: TREE_TYPE (t) = TREE_TYPE (type);
2946:
2947: /* The actual arglist for this function includes a "hidden" argument
2948: which is "this". Put it into the list of argument types. */
2949:
2950: TYPE_ARG_TYPES (t)
1.1.1.4 root 2951: = tree_cons (NULL_TREE,
2952: build_pointer_type (basetype), TYPE_ARG_TYPES (type));
1.1 root 2953:
2954: /* If we already have such a type, use the old one and free this one. */
2955: hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
2956: t = type_hash_canon (hashcode, t);
2957:
2958: if (TYPE_SIZE (t) == 0)
2959: layout_type (t);
2960:
2961: return t;
2962: }
2963:
1.1.1.5 ! root 2964: /* Construct, lay out and return the type of offsets to a value
! 2965: of type TYPE, within an object of type BASETYPE.
! 2966: If a suitable offset type exists already, reuse it. */
1.1 root 2967:
2968: tree
2969: build_offset_type (basetype, type)
2970: tree basetype, type;
2971: {
2972: register tree t;
2973: int hashcode;
2974:
2975: /* Make a node of the sort we want. */
2976: t = make_node (OFFSET_TYPE);
2977:
2978: TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
2979: TREE_TYPE (t) = type;
2980:
2981: /* If we already have such a type, use the old one and free this one. */
2982: hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
2983: t = type_hash_canon (hashcode, t);
2984:
2985: if (TYPE_SIZE (t) == 0)
2986: layout_type (t);
2987:
2988: return t;
2989: }
2990:
2991: /* Create a complex type whose components are COMPONENT_TYPE. */
2992:
2993: tree
2994: build_complex_type (component_type)
2995: tree component_type;
2996: {
2997: register tree t;
2998: int hashcode;
2999:
3000: /* Make a node of the sort we want. */
3001: t = make_node (COMPLEX_TYPE);
3002:
3003: TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
3004: TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);
3005: TYPE_READONLY (t) = TYPE_READONLY (component_type);
3006:
3007: /* If we already have such a type, use the old one and free this one. */
3008: hashcode = TYPE_HASH (component_type);
3009: t = type_hash_canon (hashcode, t);
3010:
3011: if (TYPE_SIZE (t) == 0)
3012: layout_type (t);
3013:
3014: return t;
3015: }
3016:
3017: /* Return OP, stripped of any conversions to wider types as much as is safe.
3018: Converting the value back to OP's type makes a value equivalent to OP.
3019:
3020: If FOR_TYPE is nonzero, we return a value which, if converted to
3021: type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
3022:
3023: If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
3024: narrowest type that can hold the value, even if they don't exactly fit.
3025: Otherwise, bit-field references are changed to a narrower type
3026: only if they can be fetched directly from memory in that type.
3027:
3028: OP must have integer, real or enumeral type. Pointers are not allowed!
3029:
3030: There are some cases where the obvious value we could return
3031: would regenerate to OP if converted to OP's type,
3032: but would not extend like OP to wider types.
3033: If FOR_TYPE indicates such extension is contemplated, we eschew such values.
3034: For example, if OP is (unsigned short)(signed char)-1,
3035: we avoid returning (signed char)-1 if FOR_TYPE is int,
3036: even though extending that to an unsigned short would regenerate OP,
3037: since the result of extending (signed char)-1 to (int)
3038: is different from (int) OP. */
3039:
3040: tree
3041: get_unwidened (op, for_type)
3042: register tree op;
3043: tree for_type;
3044: {
3045: /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
3046: /* TYPE_PRECISION is safe in place of type_precision since
3047: pointer types are not allowed. */
3048: register tree type = TREE_TYPE (op);
3049: register unsigned final_prec
3050: = TYPE_PRECISION (for_type != 0 ? for_type : type);
3051: register int uns
3052: = (for_type != 0 && for_type != type
3053: && final_prec > TYPE_PRECISION (type)
3054: && TREE_UNSIGNED (type));
3055: register tree win = op;
3056:
3057: while (TREE_CODE (op) == NOP_EXPR)
3058: {
3059: register int bitschange
3060: = TYPE_PRECISION (TREE_TYPE (op))
3061: - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
3062:
3063: /* Truncations are many-one so cannot be removed.
3064: Unless we are later going to truncate down even farther. */
3065: if (bitschange < 0
3066: && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
3067: break;
3068:
3069: /* See what's inside this conversion. If we decide to strip it,
3070: we will set WIN. */
3071: op = TREE_OPERAND (op, 0);
3072:
3073: /* If we have not stripped any zero-extensions (uns is 0),
3074: we can strip any kind of extension.
3075: If we have previously stripped a zero-extension,
3076: only zero-extensions can safely be stripped.
3077: Any extension can be stripped if the bits it would produce
3078: are all going to be discarded later by truncating to FOR_TYPE. */
3079:
3080: if (bitschange > 0)
3081: {
3082: if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
3083: win = op;
3084: /* TREE_UNSIGNED says whether this is a zero-extension.
3085: Let's avoid computing it if it does not affect WIN
3086: and if UNS will not be needed again. */
3087: if ((uns || TREE_CODE (op) == NOP_EXPR)
3088: && TREE_UNSIGNED (TREE_TYPE (op)))
3089: {
3090: uns = 1;
3091: win = op;
3092: }
3093: }
3094: }
3095:
3096: if (TREE_CODE (op) == COMPONENT_REF
3097: /* Since type_for_size always gives an integer type. */
3098: && TREE_CODE (type) != REAL_TYPE)
3099: {
3100: unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
3101: type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
3102:
3103: /* We can get this structure field in the narrowest type it fits in.
3104: If FOR_TYPE is 0, do this only for a field that matches the
3105: narrower type exactly and is aligned for it
3106: The resulting extension to its nominal type (a fullword type)
3107: must fit the same conditions as for other extensions. */
3108:
3109: if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
3110: && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
3111: && (! uns || final_prec <= innerprec
3112: || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
3113: && type != 0)
3114: {
3115: win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
3116: TREE_OPERAND (op, 1));
3117: TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
3118: TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
3119: TREE_RAISES (win) = TREE_RAISES (op);
3120: }
3121: }
3122: return win;
3123: }
3124:
3125: /* Return OP or a simpler expression for a narrower value
3126: which can be sign-extended or zero-extended to give back OP.
3127: Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
3128: or 0 if the value should be sign-extended. */
3129:
3130: tree
3131: get_narrower (op, unsignedp_ptr)
3132: register tree op;
3133: int *unsignedp_ptr;
3134: {
3135: register int uns = 0;
3136: int first = 1;
3137: register tree win = op;
3138:
3139: while (TREE_CODE (op) == NOP_EXPR)
3140: {
3141: register int bitschange
3142: = TYPE_PRECISION (TREE_TYPE (op))
3143: - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
3144:
3145: /* Truncations are many-one so cannot be removed. */
3146: if (bitschange < 0)
3147: break;
3148:
3149: /* See what's inside this conversion. If we decide to strip it,
3150: we will set WIN. */
3151: op = TREE_OPERAND (op, 0);
3152:
3153: if (bitschange > 0)
3154: {
3155: /* An extension: the outermost one can be stripped,
3156: but remember whether it is zero or sign extension. */
3157: if (first)
3158: uns = TREE_UNSIGNED (TREE_TYPE (op));
3159: /* Otherwise, if a sign extension has been stripped,
3160: only sign extensions can now be stripped;
3161: if a zero extension has been stripped, only zero-extensions. */
3162: else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
3163: break;
3164: first = 0;
3165: }
3166: /* A change in nominal type can always be stripped. */
3167:
3168: win = op;
3169: }
3170:
3171: if (TREE_CODE (op) == COMPONENT_REF
3172: /* Since type_for_size always gives an integer type. */
3173: && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
3174: {
3175: unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
3176: tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
3177:
3178: /* We can get this structure field in a narrower type that fits it,
3179: but the resulting extension to its nominal type (a fullword type)
3180: must satisfy the same conditions as for other extensions.
3181:
3182: Do this only for fields that are aligned (not bit-fields),
3183: because when bit-field insns will be used there is no
3184: advantage in doing this. */
3185:
3186: if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
3187: && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
3188: && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
3189: && type != 0)
3190: {
3191: if (first)
3192: uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
3193: win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
3194: TREE_OPERAND (op, 1));
3195: TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
3196: TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
3197: TREE_RAISES (win) = TREE_RAISES (op);
3198: }
3199: }
3200: *unsignedp_ptr = uns;
3201: return win;
3202: }
3203:
3204: /* Return the precision of a type, for arithmetic purposes.
3205: Supports all types on which arithmetic is possible
3206: (including pointer types).
3207: It's not clear yet what will be right for complex types. */
3208:
3209: int
3210: type_precision (type)
3211: register tree type;
3212: {
3213: return ((TREE_CODE (type) == INTEGER_TYPE
3214: || TREE_CODE (type) == ENUMERAL_TYPE
3215: || TREE_CODE (type) == REAL_TYPE)
3216: ? TYPE_PRECISION (type) : POINTER_SIZE);
3217: }
3218:
3219: /* Nonzero if integer constant C has a value that is permissible
3220: for type TYPE (an INTEGER_TYPE). */
3221:
3222: int
3223: int_fits_type_p (c, type)
3224: tree c, type;
3225: {
3226: if (TREE_UNSIGNED (type))
3227: return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
1.1.1.4 root 3228: && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))
3229: && (TREE_INT_CST_HIGH (c) >= 0 || TREE_UNSIGNED (TREE_TYPE (c))));
1.1 root 3230: else
3231: return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)
1.1.1.4 root 3232: && !INT_CST_LT (c, TYPE_MIN_VALUE (type))
3233: && (TREE_INT_CST_HIGH (c) >= 0 || !TREE_UNSIGNED (TREE_TYPE (c))));
1.1 root 3234: }
3235:
1.1.1.3 root 3236: /* Return the innermost context enclosing DECL that is
1.1 root 3237: a FUNCTION_DECL, or zero if none. */
3238:
3239: tree
1.1.1.3 root 3240: decl_function_context (decl)
3241: tree decl;
1.1 root 3242: {
3243: tree context;
3244:
1.1.1.3 root 3245: if (TREE_CODE (decl) == ERROR_MARK)
1.1 root 3246: return 0;
3247:
1.1.1.3 root 3248: if (TREE_CODE (decl) == SAVE_EXPR)
3249: context = SAVE_EXPR_CONTEXT (decl);
1.1 root 3250: else
1.1.1.3 root 3251: context = DECL_CONTEXT (decl);
1.1 root 3252:
3253: while (context && TREE_CODE (context) != FUNCTION_DECL)
3254: {
3255: if (TREE_CODE (context) == RECORD_TYPE
3256: || TREE_CODE (context) == UNION_TYPE)
3257: context = TYPE_CONTEXT (context);
3258: else if (TREE_CODE (context) == TYPE_DECL)
3259: context = DECL_CONTEXT (context);
3260: else if (TREE_CODE (context) == BLOCK)
3261: context = BLOCK_SUPERCONTEXT (context);
3262: else
3263: /* Unhandled CONTEXT !? */
3264: abort ();
3265: }
3266:
3267: return context;
3268: }
3269:
1.1.1.3 root 3270: /* Return the innermost context enclosing DECL that is
1.1 root 3271: a RECORD_TYPE or UNION_TYPE, or zero if none.
3272: TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
3273:
3274: tree
1.1.1.3 root 3275: decl_type_context (decl)
3276: tree decl;
1.1 root 3277: {
1.1.1.3 root 3278: tree context = DECL_CONTEXT (decl);
1.1 root 3279:
3280: while (context)
3281: {
3282: if (TREE_CODE (context) == RECORD_TYPE
3283: || TREE_CODE (context) == UNION_TYPE)
3284: return context;
3285: if (TREE_CODE (context) == TYPE_DECL
3286: || TREE_CODE (context) == FUNCTION_DECL)
3287: context = DECL_CONTEXT (context);
3288: else if (TREE_CODE (context) == BLOCK)
3289: context = BLOCK_SUPERCONTEXT (context);
3290: else
3291: /* Unhandled CONTEXT!? */
3292: abort ();
3293: }
3294: return NULL_TREE;
3295: }
3296:
3297: void
3298: print_obstack_statistics (str, o)
3299: char *str;
3300: struct obstack *o;
3301: {
3302: struct _obstack_chunk *chunk = o->chunk;
3303: int n_chunks = 0;
3304: int n_alloc = 0;
3305:
3306: while (chunk)
3307: {
3308: n_chunks += 1;
3309: n_alloc += chunk->limit - &chunk->contents[0];
3310: chunk = chunk->prev;
3311: }
3312: fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",
3313: str, n_alloc, n_chunks);
3314: }
3315: void
3316: dump_tree_statistics ()
3317: {
3318: int i;
3319: int total_nodes, total_bytes;
3320:
3321: fprintf (stderr, "\n??? tree nodes created\n\n");
3322: #ifdef GATHER_STATISTICS
3323: fprintf (stderr, "Kind Nodes Bytes\n");
3324: fprintf (stderr, "-------------------------------------\n");
3325: total_nodes = total_bytes = 0;
3326: for (i = 0; i < (int) all_kinds; i++)
3327: {
3328: fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
3329: tree_node_counts[i], tree_node_sizes[i]);
3330: total_nodes += tree_node_counts[i];
3331: total_bytes += tree_node_sizes[i];
3332: }
3333: fprintf (stderr, "%-20s %9d\n", "identifier names", id_string_size);
3334: fprintf (stderr, "-------------------------------------\n");
3335: fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
3336: fprintf (stderr, "-------------------------------------\n");
3337: #else
3338: fprintf (stderr, "(No per-node statistics)\n");
3339: #endif
3340: print_lang_statistics ();
3341: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.