|
|
1.1 root 1: /* Language-indepednent node constructors for parse phase of GNU compiler.
1.1.1.2 root 2: Copyright (C) 1987, 1988 Free Software Foundation, Inc.
1.1 root 3:
4: This file is part of GNU CC.
5:
6: GNU CC is distributed in the hope that it will be useful,
7: but WITHOUT ANY WARRANTY. No author or distributor
8: accepts responsibility to anyone for the consequences of using it
9: or for whether it serves any particular purpose or works at all,
10: unless he says so in writing. Refer to the GNU CC General Public
11: License for full details.
12:
13: Everyone is granted permission to copy, modify and redistribute
14: GNU CC, but only under the conditions described in the
15: GNU CC General Public License. A copy of this license is
16: supposed to have been given to you along with GNU CC so you
17: can know your rights and responsibilities. It should be in a
18: file named COPYING. Among other things, the copyright notice
19: and this notice must be preserved on all copies. */
20:
21:
22: /* This file contains the low level primitives for operating on tree nodes,
23: including allocation, list operations, interning of identifiers,
24: construction of data type nodes and statement nodes,
25: and construction of type conversion nodes. It also contains
26: tables index by tree code that describe how to take apart
27: nodes of that code.
28:
29: It is intended to be language-independent, but occasionally
30: calls language-dependent routines defined (for C) in typecheck.c.
31:
32: The low-level allocation routines oballoc and permalloc
33: are used also for allocating many other kinds of objects
34: by all passes of the compiler. */
35:
36: #include "config.h"
37: #include <stdio.h>
38: #include "tree.h"
39: #include "obstack.h"
1.1.1.2 root 40: #include "varargs.h"
1.1 root 41:
42: #define obstack_chunk_alloc xmalloc
43: #define obstack_chunk_free free
44:
45: extern int xmalloc ();
46: extern void free ();
47:
48: /* Tree nodes of permanent duration are allocated in this obstack.
49: They are the identifier nodes, and everything outside of
50: the bodies and parameters of function definitions. */
51:
52: struct obstack permanent_obstack;
53:
1.1.1.2 root 54: /* The initial RTL, and all ..._TYPE nodes, in a function
55: are allocated in this obstack. Usually they are freed at the
56: end of the function, but if the function is inline they are saved. */
57:
58: struct obstack maybepermanent_obstack;
59:
1.1 root 60: /* The contents of the current function definition are allocated
61: in this obstack, and all are freed at the end of the function. */
62:
63: struct obstack temporary_obstack;
64:
1.1.1.2 root 65: /* The tree nodes of an expression are allocated
66: in this obstack, and all are freed at the end of the expression. */
67:
68: struct obstack momentary_obstack;
69:
70: /* This points at either permanent_obstack or maybepermanent_obstack. */
71:
72: struct obstack *saveable_obstack;
73:
74: /* This is same as saveable_obstack during parse and expansion phase;
75: it points to temporary_obstack during optimization.
76: This is the obstack to be used for creating rtl objects. */
77:
78: struct obstack *rtl_obstack;
79:
1.1 root 80: /* This points at either permanent_obstack or temporary_obstack. */
81:
82: struct obstack *current_obstack;
83:
1.1.1.2 root 84: /* This points at either permanent_obstack or temporary_obstack
85: or momentary_obstack. */
86:
87: struct obstack *expression_obstack;
88:
89: /* Addresses of first objects in some obstacks.
90: This is for freeing their entire contents. */
91: char *maybepermanent_firstobj;
92: char *temporary_firstobj;
93: char *momentary_firstobj;
94:
1.1.1.5 root 95: /* Nonzero means all ..._TYPE nodes should be allocated permanently. */
96:
97: int all_types_permanent;
98:
1.1.1.2 root 99: /* Stack of places to restore the momentary obstack back to. */
100:
101: struct momentary_level
102: {
103: /* Pointer back to previous such level. */
104: struct momentary_level *prev;
105: /* First object allocated within this level. */
106: char *base;
107: /* Value of expression_obstack saved at entry to this level. */
108: struct obstack *obstack;
109: };
110:
111: struct momentary_level *momentary_stack;
112:
1.1 root 113: /* Table indexed by tree code giving a string containing a character
114: classifying the tree code. Possibilities are
115: t, d, s, c, r and e. See tree.def for details. */
116:
117: #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
118:
119: char *tree_code_type[] = {
120: #include "tree.def"
121: };
122: #undef DEFTREECODE
123:
124: /* Table indexed by tree code giving number of expression
125: operands beyond the fixed part of the node structure.
126: Not used for types or decls. */
127:
128: #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
129:
130: int tree_code_length[] = {
131: #include "tree.def"
132: };
133: #undef DEFTREECODE
134:
135: /* Counter for assigning unique ids to all tree nodes. */
136:
137: int tree_node_counter = 0;
138:
139: /* Hash table for uniquizing IDENTIFIER_NODEs by name. */
140:
1.1.1.2 root 141: #define MAX_HASH_TABLE 1009
1.1 root 142: static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */
143:
144: /* Init data for node creation, at the beginning of compilation. */
145:
146: void
147: init_tree ()
148: {
149: obstack_init (&permanent_obstack);
1.1.1.2 root 150:
151: obstack_init (&temporary_obstack);
152: temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
153: obstack_init (&momentary_obstack);
154: momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
155: obstack_init (&maybepermanent_obstack);
156: maybepermanent_firstobj
157: = (char *) obstack_alloc (&maybepermanent_obstack, 0);
158:
1.1 root 159: current_obstack = &permanent_obstack;
1.1.1.2 root 160: expression_obstack = &permanent_obstack;
161: rtl_obstack = saveable_obstack = &permanent_obstack;
1.1 root 162: tree_node_counter = 1;
163: bzero (hash_table, sizeof hash_table);
164: }
165:
166: /* Start allocating on the temporary (per function) obstack.
1.1.1.2 root 167: This is done in start_function before parsing the function body,
168: and before each initialization at top level, and to go back
169: to temporary allocation after doing end_temporary_allocation. */
1.1 root 170:
1.1.1.2 root 171: void
1.1 root 172: temporary_allocation ()
173: {
174: current_obstack = &temporary_obstack;
1.1.1.2 root 175: expression_obstack = &temporary_obstack;
176: rtl_obstack = saveable_obstack = &maybepermanent_obstack;
177: momentary_stack = 0;
178: }
179:
180: /* Start allocating on the permanent obstack but don't
181: free the temporary data. After calling this, call
182: `permanent_allocation' to fully resume permanent allocation status. */
183:
184: void
185: end_temporary_allocation ()
186: {
187: current_obstack = &permanent_obstack;
188: expression_obstack = &permanent_obstack;
189: rtl_obstack = saveable_obstack = &permanent_obstack;
1.1 root 190: }
191:
1.1.1.4 root 192: /* Resume allocating on the temporary obstack, undoing
193: effects of `end_temporary_allocation'. */
194:
195: void
196: resume_temporary_allocation ()
197: {
198: current_obstack = &temporary_obstack;
199: expression_obstack = &temporary_obstack;
200: rtl_obstack = saveable_obstack = &maybepermanent_obstack;
201: }
202:
1.1.1.5 root 203: /* Nonzero if temporary allocation is currently in effect.
204: Zero if currently doing permanent allocation. */
205:
206: int
207: allocation_temporary_p ()
208: {
209: return current_obstack == &temporary_obstack;
210: }
211:
1.1 root 212: /* Go back to allocating on the permanent obstack
213: and free everything in the temporary obstack.
214: This is done in finish_function after fully compiling a function. */
215:
1.1.1.2 root 216: void
1.1 root 217: permanent_allocation ()
218: {
219: /* Free up previous temporary obstack data */
1.1.1.2 root 220: obstack_free (&temporary_obstack, temporary_firstobj);
221: obstack_free (&momentary_obstack, momentary_firstobj);
222: obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
1.1 root 223:
224: current_obstack = &permanent_obstack;
1.1.1.2 root 225: expression_obstack = &permanent_obstack;
226: rtl_obstack = saveable_obstack = &permanent_obstack;
1.1 root 227: }
228:
1.1.1.2 root 229: /* Save permanently everything on the maybepermanent_obstack. */
230:
231: void
232: preserve_data ()
233: {
234: maybepermanent_firstobj
235: = (char *) obstack_alloc (&maybepermanent_obstack, 0);
236: }
237:
1.1 root 238: /* Allocate SIZE bytes in the current obstack
239: and return a pointer to them.
240: In practice the current obstack is always the temporary one. */
241:
242: char *
243: oballoc (size)
244: int size;
245: {
246: return (char *) obstack_alloc (current_obstack, size);
247: }
248:
249: /* Free the object PTR in the current obstack
250: as well as everything allocated since PTR.
251: In practice the current obstack is always the temporary one. */
252:
253: void
254: obfree (ptr)
255: char *ptr;
256: {
257: obstack_free (current_obstack, ptr);
258: }
259:
260: /* Allocate SIZE bytes in the permanent obstack
261: and return a pointer to them. */
262:
263: char *
264: permalloc (size)
265: long size;
266: {
267: return (char *) obstack_alloc (&permanent_obstack, size);
268: }
269:
1.1.1.2 root 270: /* Start a level of momentary allocation.
271: In C, each compound statement has its own level
272: and that level is freed at the end of each statement.
273: All expression nodes are allocated in the momentary allocation level. */
274:
275: void
276: push_momentary ()
277: {
278: struct momentary_level *tem
279: = (struct momentary_level *) obstack_alloc (&momentary_obstack,
280: sizeof (struct momentary_level));
281: tem->prev = momentary_stack;
282: tem->base = (char *) obstack_base (&momentary_obstack);
283: tem->obstack = expression_obstack;
284: momentary_stack = tem;
285: expression_obstack = &momentary_obstack;
286: }
287:
288: /* Free all the storage in the current momentary-allocation level.
289: In C, this happens at the end of each statement. */
290:
291: void
292: clear_momentary ()
293: {
294: obstack_free (&momentary_obstack, momentary_stack->base);
295: }
296:
297: /* Discard a level of momentary allocation.
298: In C, this happens at the end of each compound statement.
299: Restore the status of expression node allocation
300: that was in effect before this level was created. */
301:
302: void
303: pop_momentary ()
304: {
305: struct momentary_level *tem = momentary_stack;
306: momentary_stack = tem->prev;
307: obstack_free (&momentary_obstack, tem);
308: expression_obstack = tem->obstack;
309: }
310:
311: /* Call when starting to parse a declaration:
312: make expressions in the declaration last the length of the function.
313: Returns an argument that should be passed to resume_momentary later. */
314:
315: int
316: suspend_momentary ()
317: {
318: register int tem = expression_obstack == &momentary_obstack;
1.1.1.4 root 319: expression_obstack = saveable_obstack;
1.1.1.2 root 320: return tem;
321: }
322:
323: /* Call when finished parsing a declaration:
324: restore the treatment of node-allocation that was
325: in effect before the suspension.
326: YES should be the value previously returned by suspend_momentary. */
327:
328: void
329: resume_momentary (yes)
330: int yes;
331: {
332: if (yes)
333: expression_obstack = &momentary_obstack;
334: }
335:
1.1 root 336: /* Return a newly allocated node of code CODE.
337: Initialize the node's unique id and its TREE_PERMANENT flag.
338: For decl and type nodes, some other fields are initialized.
339: The rest of the node is initialized to zero.
340:
341: Achoo! I got a code in the node. */
342:
343: tree
344: make_node (code)
345: enum tree_code code;
346: {
347: register tree t;
348: register int type = *tree_code_type[(int) code];
349: register int length;
1.1.1.2 root 350: register struct obstack *obstack = current_obstack;
1.1 root 351: register int i;
352:
353: switch (type)
354: {
355: case 'd': /* A decl node */
356: length = sizeof (struct tree_decl);
1.1.1.2 root 357: /* All decls in an inline function need to be saved. */
358: if (obstack != &permanent_obstack)
359: obstack = saveable_obstack;
1.1 root 360: break;
361:
362: case 't': /* a type node */
363: length = sizeof (struct tree_type);
1.1.1.2 root 364: /* All data types are put where we can preserve them if nec. */
365: if (obstack != &permanent_obstack)
1.1.1.5 root 366: obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
1.1 root 367: break;
368:
369: case 's': /* a stmt node */
1.1.1.2 root 370: length = sizeof (struct tree_common)
1.1 root 371: + 2 * sizeof (int)
372: + tree_code_length[(int) code] * sizeof (char *);
1.1.1.2 root 373: /* All stmts are put where we can preserve them if nec. */
374: if (obstack != &permanent_obstack)
375: obstack = saveable_obstack;
1.1 root 376: break;
377:
1.1.1.2 root 378: case 'r': /* a reference */
379: case 'e': /* an expression */
380: obstack = expression_obstack;
381: length = sizeof (struct tree_exp)
382: + (tree_code_length[(int) code] - 1) * sizeof (char *);
383: break;
384:
385: case 'c': /* a constant */
386: obstack = expression_obstack;
387: /* We can't use tree_code_length for this, since the number of words
388: is machine-dependent due to varying alignment of `double'. */
389: if (code == REAL_CST)
390: {
391: length = sizeof (struct tree_real_cst);
392: break;
393: }
394:
395: case 'x': /* something random, like an identifier. */
396: length = sizeof (struct tree_common)
1.1 root 397: + tree_code_length[(int) code] * sizeof (char *);
1.1.1.2 root 398: /* Identifier nodes are always permanent since they are
399: unique in a compiler run. */
400: if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
1.1 root 401: }
402:
403: t = (tree) obstack_alloc (obstack, length);
404:
405: TREE_UID (t) = tree_node_counter++;
406: TREE_TYPE (t) = 0;
407: TREE_CHAIN (t) = 0;
408: for (i = (length / sizeof (int)) - 1;
1.1.1.2 root 409: i >= sizeof (struct tree_common) / sizeof (int) - 1;
1.1 root 410: i--)
411: ((int *) t)[i] = 0;
412:
413: TREE_SET_CODE (t, code);
414: if (obstack == &permanent_obstack)
415: TREE_PERMANENT (t) = 1;
416:
417: if (type == 'd')
418: {
419: extern int lineno;
420:
421: DECL_ALIGN (t) = 1;
422: DECL_SIZE_UNIT (t) = 1;
423: DECL_VOFFSET_UNIT (t) = 1;
424: DECL_SOURCE_LINE (t) = lineno;
425: DECL_SOURCE_FILE (t) = input_filename;
426: }
427:
428: if (type == 't')
429: {
430: TYPE_ALIGN (t) = 1;
431: TYPE_SIZE_UNIT (t) = 1;
432: TYPE_MAIN_VARIANT (t) = t;
433: }
434:
435: if (type == 'c')
436: {
437: TREE_LITERAL (t) = 1;
438: }
439:
440: return t;
441: }
442:
443: /* Return a new node with the same contents as NODE
444: except that its TREE_CHAIN is zero and it has a fresh uid. */
445:
446: tree
447: copy_node (node)
448: tree node;
449: {
450: register tree t;
451: register enum tree_code code = TREE_CODE (node);
452: register int length;
453: register int i;
454:
455: switch (*tree_code_type[(int) code])
456: {
457: case 'd': /* A decl node */
458: length = sizeof (struct tree_decl);
459: break;
460:
461: case 't': /* a type node */
462: length = sizeof (struct tree_type);
463: break;
464:
465: case 's':
1.1.1.2 root 466: length = sizeof (struct tree_common)
1.1 root 467: + 2 * sizeof (int)
468: + tree_code_length[(int) code] * sizeof (char *);
469: break;
470:
1.1.1.2 root 471: case 'r': /* a reference */
472: case 'e': /* a expression */
473: length = sizeof (struct tree_exp)
474: + (tree_code_length[(int) code] - 1) * sizeof (char *);
475: break;
476:
477: case 'c': /* a constant */
478: /* We can't use tree_code_length for this, since the number of words
479: is machine-dependent due to varying alignment of `double'. */
480: if (code == REAL_CST)
481: {
482: length = sizeof (struct tree_real_cst);
483: break;
484: }
485:
486: case 'x': /* something random, like an identifier. */
487: length = sizeof (struct tree_common)
1.1 root 488: + tree_code_length[(int) code] * sizeof (char *);
489: }
490:
491: t = (tree) obstack_alloc (current_obstack, length);
492:
1.1.1.5 root 493: for (i = ((length + sizeof (int) - 1) / sizeof (int)) - 1;
1.1 root 494: i >= 0;
495: i--)
496: ((int *) t)[i] = ((int *) node)[i];
497:
498: TREE_UID (t) = tree_node_counter++;
499: TREE_CHAIN (t) = 0;
500:
501: TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
502:
503: return t;
504: }
505:
506: #define HASHBITS 30
507:
508: /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
509: If an identifier with that name has previously been referred to,
510: the same node is returned this time. */
511:
512: tree
513: get_identifier (text)
514: register char *text;
515: {
516: register int hi;
517: register int i;
518: register tree idp;
519: register int len;
520:
521: /* Compute length of text in len. */
522: for (len = 0; text[len]; len++);
523:
524: /* Compute hash code */
525: hi = len;
526: for (i = 0; i < len; i++)
527: hi = ((hi * 613) + (unsigned)(text[i]));
528:
529: hi &= (1 << HASHBITS) - 1;
530: hi %= MAX_HASH_TABLE;
531:
532: /* Search table for identifier */
533: for (idp = hash_table[hi]; idp!=NULL; idp = TREE_CHAIN (idp))
534: if (IDENTIFIER_LENGTH (idp) == len &&
535: !strcmp (IDENTIFIER_POINTER (idp), text))
536: return idp; /* <-- return if found */
537:
538: /* Not found, create one, add to chain */
539: idp = make_node (IDENTIFIER_NODE);
540: IDENTIFIER_LENGTH (idp) = len;
541:
542: IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
543:
544: TREE_CHAIN (idp) = hash_table[hi];
545: hash_table[hi] = idp;
546: return idp; /* <-- return if created */
547: }
548:
549: /* Return a newly constructed INTEGER_CST node whose constant value
550: is specified by the two ints LOW and HI.
1.1.1.2 root 551: The TREE_TYPE is set to `int'. */
1.1 root 552:
553: tree
554: build_int_2 (low, hi)
555: int low, hi;
556: {
557: register tree t = make_node (INTEGER_CST);
558: TREE_INT_CST_LOW (t) = low;
559: TREE_INT_CST_HIGH (t) = hi;
560: TREE_TYPE (t) = integer_type_node;
561: return t;
562: }
563:
1.1.1.4 root 564: /* Return a new REAL_CST node whose type is TYPE and value is D. */
1.1 root 565:
566: tree
1.1.1.4 root 567: build_real (type, d)
568: tree type;
1.1 root 569: double d;
570: {
571: tree v;
572:
1.1.1.4 root 573: /* Check for valid float value for this type on this target machine;
574: if not, can print error message and store a valid value in D. */
575: #ifdef CHECK_FLOAT_VALUE
576: CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
577: #endif
578:
1.1 root 579: v = make_node (REAL_CST);
1.1.1.4 root 580: TREE_TYPE (v) = type;
1.1 root 581: TREE_REAL_CST (v) = d;
582: return v;
583: }
584:
1.1.1.4 root 585: /* Return a new REAL_CST node whose type is TYPE
586: and whose value is the integer value of the INTEGER_CST node I. */
1.1 root 587:
588: tree
1.1.1.4 root 589: build_real_from_int_cst (type, i)
590: tree type;
1.1 root 591: tree i;
592: {
593: tree v;
1.1.1.2 root 594: double d;
1.1 root 595:
596: v = make_node (REAL_CST);
1.1.1.4 root 597: TREE_TYPE (v) = type;
1.1.1.2 root 598:
599: if (TREE_INT_CST_HIGH (i) < 0)
600: {
601: d = (double) (~ TREE_INT_CST_HIGH (i));
602: d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
603: * (double) (1 << (HOST_BITS_PER_INT / 2)));
604: d += (double) (unsigned) (~ TREE_INT_CST_LOW (i));
605: d = (- d - 1.0);
606: }
607: else
608: {
609: d = (double) TREE_INT_CST_HIGH (i);
610: d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
611: * (double) (1 << (HOST_BITS_PER_INT / 2)));
612: d += (double) (unsigned) TREE_INT_CST_LOW (i);
613: }
614:
1.1.1.6 root 615: /* Check for valid float value for this type on this target machine;
616: if not, can print error message and store a valid value in D. */
617: #ifdef CHECK_FLOAT_VALUE
618: CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
619: #endif
620:
1.1.1.2 root 621: TREE_REAL_CST (v) = d;
1.1 root 622: return v;
623: }
624:
625: /* Return a newly constructed STRING_CST node whose value is
626: the LEN characters at STR.
627: The TREE_TYPE is not initialized. */
628:
629: tree
630: build_string (len, str)
631: int len;
632: char *str;
633: {
634: register tree s = make_node (STRING_CST);
635: TREE_STRING_LENGTH (s) = len;
1.1.1.2 root 636: TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
1.1 root 637: return s;
638: }
639:
640: /* Return a newly constructed COMPLEX_CST node whose value is
641: specified by the real and imaginary parts REAL and IMAG.
642: Both REAL and IMAG should be constant nodes.
643: The TREE_TYPE is not initialized. */
644:
645: tree
646: build_complex (real, imag)
647: tree real, imag;
648: {
649: register tree t = make_node (COMPLEX_CST);
650: TREE_REALPART (t) = real;
651: TREE_IMAGPART (t) = imag;
652: return t;
653: }
654:
655: /* Return 1 if EXPR is the integer constant zero. */
656:
657: int
658: integer_zerop (expr)
659: tree expr;
660: {
1.1.1.2 root 661: return (TREE_CODE (expr) == INTEGER_CST
662: && TREE_INT_CST_LOW (expr) == 0
663: && TREE_INT_CST_HIGH (expr) == 0);
1.1 root 664: }
665:
666: /* Return 1 if EXPR is the integer constant one. */
667:
668: int
669: integer_onep (expr)
670: tree expr;
671: {
1.1.1.2 root 672: return (TREE_CODE (expr) == INTEGER_CST
673: && TREE_INT_CST_LOW (expr) == 1
674: && TREE_INT_CST_HIGH (expr) == 0);
1.1 root 675: }
676:
677: /* Return 1 if EXPR is an integer containing all 1's
678: in as much precision as it contains. */
679:
680: int
681: integer_all_onesp (expr)
682: tree expr;
683: {
684: register int prec;
685: register int uns;
686:
687: if (TREE_CODE (expr) != INTEGER_CST)
688: return 0;
689:
1.1.1.2 root 690: uns = TREE_UNSIGNED (TREE_TYPE (expr));
1.1 root 691: if (!uns)
692: return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
693:
694: prec = TYPE_PRECISION (TREE_TYPE (expr));
695: if (prec >= HOST_BITS_PER_INT)
696: return TREE_INT_CST_LOW (expr) == -1
697: && TREE_INT_CST_HIGH (expr) == (1 << (prec - HOST_BITS_PER_INT)) - 1;
698: else
699: return TREE_INT_CST_LOW (expr) == (1 << prec) - 1;
700: }
701:
702: /* Return the length of a chain of nodes chained through TREE_CHAIN.
703: We expect a null pointer to mark the end of the chain.
704: This is the Lisp primitive `length'. */
705:
706: int
707: list_length (t)
708: tree t;
709: {
710: register tree tail;
711: register int len = 0;
712:
713: for (tail = t; tail; tail = TREE_CHAIN (tail))
714: len++;
715:
716: return len;
717: }
718:
719: /* Concatenate two chains of nodes (chained through TREE_CHAIN)
720: by modifying the last node in chain 1 to point to chain 2.
721: This is the Lisp primitive `nconc'. */
722:
723: tree
724: chainon (op1, op2)
725: tree op1, op2;
726: {
727: tree t;
728:
729: if (op1)
730: {
731: for (t = op1; TREE_CHAIN (t); t = TREE_CHAIN (t))
732: if (t == op2) abort (); /* Circularity being created */
733: TREE_CHAIN (t) = op2;
734: return op1;
735: }
736: else return op2;
737: }
738:
739: /* Return a newly created TREE_LIST node whose
740: purpose and value fields are PARM and VALUE. */
741:
742: tree
743: build_tree_list (parm, value)
744: tree parm, value;
745: {
746: register tree t = make_node (TREE_LIST);
747: TREE_PURPOSE (t) = parm;
748: TREE_VALUE (t) = value;
749: return t;
750: }
751:
752: /* Return a newly created TREE_LIST node whose
753: purpose and value fields are PARM and VALUE
754: and whose TREE_CHAIN is CHAIN. */
755:
756: tree
757: tree_cons (purpose, value, chain)
758: tree purpose, value, chain;
759: {
760: register tree node = make_node (TREE_LIST);
761: TREE_CHAIN (node) = chain;
762: TREE_PURPOSE (node) = purpose;
763: TREE_VALUE (node) = value;
764: return node;
765: }
766:
1.1.1.2 root 767: /* Same as `tree_cons' but make a permanent object. */
768:
769: tree
770: perm_tree_cons (purpose, value, chain)
771: tree purpose, value, chain;
772: {
773: register tree node;
774: register struct obstack *ambient_obstack = current_obstack;
775: current_obstack = &permanent_obstack;
776:
777: node = make_node (TREE_LIST);
778: TREE_CHAIN (node) = chain;
779: TREE_PURPOSE (node) = purpose;
780: TREE_VALUE (node) = value;
781:
782: current_obstack = ambient_obstack;
783: return node;
784: }
785:
1.1.1.7 root 786: /* Same as `tree_cons', but make this node temporary, regardless. */
787:
788: tree
789: temp_tree_cons (purpose, value, chain)
790: tree purpose, value, chain;
791: {
792: register tree node;
793: register struct obstack *ambient_obstack = current_obstack;
794: current_obstack = &temporary_obstack;
795:
796: node = make_node (TREE_LIST);
797: TREE_CHAIN (node) = chain;
798: TREE_PURPOSE (node) = purpose;
799: TREE_VALUE (node) = value;
800:
801: current_obstack = ambient_obstack;
802: return node;
803: }
804:
1.1.1.9 root 805: /* Same as `tree_cons', but save this node if the function's RTL is saved. */
806:
807: tree
808: saveable_tree_cons (purpose, value, chain)
809: tree purpose, value, chain;
810: {
811: register tree node;
812: register struct obstack *ambient_obstack = current_obstack;
813: current_obstack = saveable_obstack;
814:
815: node = make_node (TREE_LIST);
816: TREE_CHAIN (node) = chain;
817: TREE_PURPOSE (node) = purpose;
818: TREE_VALUE (node) = value;
819:
820: current_obstack = ambient_obstack;
821: return node;
822: }
823:
1.1 root 824: /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
825:
826: tree
827: tree_last (chain)
828: register tree chain;
829: {
830: register tree next;
831: if (chain)
832: while (next = TREE_CHAIN (chain))
833: chain = next;
834: return chain;
835: }
836:
837: /* Reverse the order of elements in the chain T,
838: and return the new head of the chain (old last element). */
839:
840: tree
841: nreverse (t)
842: tree t;
843: {
844: register tree prev = 0, decl, next;
845: for (decl = t; decl; decl = next)
846: {
847: next = TREE_CHAIN (decl);
848: TREE_CHAIN (decl) = prev;
849: prev = decl;
850: }
851: return prev;
852: }
853:
854: /* Return the size nominally occupied by an object of type TYPE
855: when it resides in memory. The value is measured in units of bytes,
856: and its data type is that normally used for type sizes
857: (which is the first type created by make_signed_type or
858: make_unsigned_type). */
859:
860: tree
861: size_in_bytes (type)
862: tree type;
863: {
864: if (type == error_mark_node)
865: return integer_zero_node;
1.1.1.2 root 866: if (TYPE_SIZE (type) == 0)
867: {
868: incomplete_type_error (0, type);
869: return integer_zero_node;
870: }
1.1 root 871: return convert_units (TYPE_SIZE (type), TYPE_SIZE_UNIT (type),
872: BITS_PER_UNIT);
873: }
874:
1.1.1.2 root 875: /* Return the size of TYPE (in bytes) as an integer,
876: or return -1 if the size can vary. */
877:
878: int
879: int_size_in_bytes (type)
880: tree type;
881: {
882: int size;
883: if (type == error_mark_node)
884: return 0;
885: if (TYPE_SIZE (type) == 0)
886: return -1;
887: if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
888: return -1;
889: size = TREE_INT_CST_LOW (TYPE_SIZE (type)) * TYPE_SIZE_UNIT (type);
890: return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
891: }
892:
1.1.1.7 root 893: /* Return, as an INTEGER_CST node, the number of elements for
894: TYPE (which is an ARRAY_TYPE). */
895:
896: tree
897: array_type_nelts (type)
898: tree type;
899: {
900: tree index_type = TYPE_DOMAIN (type);
901: return (tree_int_cst_equal (TYPE_MIN_VALUE (index_type), integer_zero_node)
902: ? TYPE_MAX_VALUE (index_type)
903: : fold (build (MINUS_EXPR, integer_type_node,
904: TYPE_MAX_VALUE (index_type),
905: TYPE_MIN_VALUE (index_type))));
906: }
907:
1.1 root 908: /* Return nonzero if arg is static -- a reference to an object in
909: static storage. This is not the same as the C meaning of `static'. */
910:
911: int
912: staticp (arg)
913: tree arg;
914: {
915: register enum tree_code code = TREE_CODE (arg);
916:
1.1.1.2 root 917: if ((code == VAR_DECL || code == FUNCTION_DECL || code == CONSTRUCTOR)
1.1 root 918: && (TREE_STATIC (arg) || TREE_EXTERNAL (arg)))
919: return 1;
920:
1.1.1.2 root 921: if (code == STRING_CST)
922: return 1;
923:
1.1 root 924: if (code == COMPONENT_REF)
1.1.1.10! root 925: return (DECL_VOFFSET (TREE_OPERAND (arg, 1)) == 0
! 926: && staticp (TREE_OPERAND (arg, 0)));
! 927:
! 928: if (code == INDIRECT_REF)
! 929: return TREE_LITERAL (TREE_OPERAND (arg, 0));
1.1 root 930:
1.1.1.2 root 931: if (code == ARRAY_REF)
932: {
933: if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
934: && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
935: return staticp (TREE_OPERAND (arg, 0));
936: }
937:
1.1 root 938: return 0;
939: }
940:
1.1.1.2 root 941: /* Return nonzero if REF is an lvalue valid for this language.
942: Lvalues can be assigned, unless they have TREE_READONLY.
943: Lvalues can have their address taken, unless they have TREE_REGDECL. */
1.1 root 944:
945: int
1.1.1.2 root 946: lvalue_p (ref)
1.1 root 947: tree ref;
948: {
949: register enum tree_code code = TREE_CODE (ref);
950:
1.1.1.2 root 951: if (language_lvalue_valid (ref))
952: switch (code)
953: {
954: case COMPONENT_REF:
955: return lvalue_p (TREE_OPERAND (ref, 0));
956:
957: case STRING_CST:
958: return 1;
959:
960: case INDIRECT_REF:
961: case ARRAY_REF:
962: case VAR_DECL:
963: case PARM_DECL:
964: case RESULT_DECL:
965: case ERROR_MARK:
966: if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE)
967: return 1;
1.1.1.7 root 968: break;
969:
970: case CALL_EXPR:
971: if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
972: return 1;
1.1.1.2 root 973: }
1.1 root 974: return 0;
975: }
1.1.1.2 root 976:
977: /* Return nonzero if REF is an lvalue valid for this language;
978: otherwise, print an error message and return zero. */
979:
980: int
981: lvalue_or_else (ref, string)
982: tree ref;
983: char *string;
984: {
985: int win = lvalue_p (ref);
986: if (! win)
987: error ("invalid lvalue in %s", string);
988: return win;
989: }
1.1 root 990:
991: /* This should be applied to any node which may be used in more than one place,
992: but must be evaluated only once. Normally, the code generator would
993: reevaluate the node each time; this forces it to compute it once and save
994: the result. This is done by encapsulating the node in a SAVE_EXPR. */
995:
996: tree
997: save_expr (expr)
998: tree expr;
999: {
1000: register tree t = fold (expr);
1001:
1.1.1.2 root 1002: /* If the tree evaluates to a constant, then we don't want to hide that
1.1 root 1003: fact (i.e. this allows further folding, and direct checks for constants).
1004: Since it is no problem to reevaluate literals, we just return the
1005: literal node. */
1006:
1007: if (TREE_LITERAL (t) || TREE_READONLY (t) || TREE_CODE (t) == SAVE_EXPR)
1008: return t;
1009:
1.1.1.2 root 1010: return build (SAVE_EXPR, TREE_TYPE (expr), t, NULL);
1.1 root 1011: }
1012:
1013: /* Stabilize a reference so that we can use it any number of times
1014: without causing its operands to be evaluated more than once.
1.1.1.2 root 1015: Returns the stabilized reference.
1016:
1017: Also allows conversion expressions whose operands are references.
1018: Any other kind of expression is returned unchanged. */
1.1 root 1019:
1020: tree
1021: stabilize_reference (ref)
1022: tree ref;
1023: {
1024: register tree result;
1025: register enum tree_code code = TREE_CODE (ref);
1026:
1.1.1.2 root 1027: switch (code)
1.1 root 1028: {
1.1.1.2 root 1029: case VAR_DECL:
1030: case PARM_DECL:
1031: case RESULT_DECL:
1.1 root 1032: result = ref;
1.1.1.2 root 1033: break;
1034:
1035: case NOP_EXPR:
1036: case CONVERT_EXPR:
1037: case FLOAT_EXPR:
1038: case FIX_TRUNC_EXPR:
1039: case FIX_FLOOR_EXPR:
1040: case FIX_ROUND_EXPR:
1041: case FIX_CEIL_EXPR:
1042: result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
1043: break;
1044:
1045: case INDIRECT_REF:
1046: result = build_nt (INDIRECT_REF, save_expr (TREE_OPERAND (ref, 0)));
1047: break;
1048:
1049: case COMPONENT_REF:
1050: result = build_nt (COMPONENT_REF,
1051: stabilize_reference (TREE_OPERAND (ref, 0)),
1052: TREE_OPERAND (ref, 1));
1053: break;
1054:
1055: case ARRAY_REF:
1056: result = build_nt (ARRAY_REF, stabilize_reference (TREE_OPERAND (ref, 0)),
1057: save_expr (TREE_OPERAND (ref, 1)));
1058: break;
1059:
1060: /* If arg isn't a kind of lvalue we recognize, make no change.
1061: Caller should recognize the error for an invalid lvalue. */
1062: default:
1063: return ref;
1064:
1065: case ERROR_MARK:
1.1 root 1066: return error_mark_node;
1067: }
1068:
1069: TREE_TYPE (result) = TREE_TYPE (ref);
1.1.1.2 root 1070: TREE_READONLY (result) = TREE_READONLY (ref);
1.1 root 1071: TREE_VOLATILE (result) = TREE_VOLATILE (ref);
1.1.1.2 root 1072: TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
1.1 root 1073:
1074: return result;
1075: }
1076:
1077: /* Low-level constructors for expressions. */
1078:
1.1.1.2 root 1079: /* Build an expression of code CODE, data type TYPE,
1080: and operands as specified by the arguments ARG1 and following arguments.
1081: Expressions and reference nodes can be created this way.
1082: Constants, decls, types and misc nodes cannot be. */
1.1 root 1083:
1084: tree
1.1.1.2 root 1085: build (va_alist)
1086: va_dcl
1.1 root 1087: {
1.1.1.2 root 1088: register va_list p;
1089: enum tree_code code;
1090: register tree t;
1091: register int length;
1092: register int i;
1093:
1094: va_start (p);
1.1 root 1095:
1.1.1.2 root 1096: code = va_arg (p, enum tree_code);
1097: t = make_node (code);
1098: length = tree_code_length[(int) code];
1099: TREE_TYPE (t) = va_arg (p, tree);
1100:
1101: if (length == 2)
1102: {
1103: /* This is equivalent to the loop below, but faster. */
1104: register tree arg0 = va_arg (p, tree);
1105: register tree arg1 = va_arg (p, tree);
1106: TREE_OPERAND (t, 0) = arg0;
1107: TREE_OPERAND (t, 1) = arg1;
1108: TREE_VOLATILE (t)
1109: = (arg0 && TREE_VOLATILE (arg0)) || (arg1 && TREE_VOLATILE (arg1));
1110: }
1111: else
1112: {
1113: for (i = 0; i < length; i++)
1114: {
1115: register tree operand = va_arg (p, tree);
1116: TREE_OPERAND (t, i) = operand;
1117: if (operand && TREE_VOLATILE (operand))
1118: TREE_VOLATILE (t) = 1;
1119: }
1120: }
1121: va_end (p);
1.1 root 1122: return t;
1123: }
1124:
1.1.1.2 root 1125: /* Similar except don't specify the TREE_TYPE
1126: and leave the TREE_VOLATILE as 0.
1127: It is permissible for arguments to be null,
1128: or even garbage if their values do not matter. */
1.1 root 1129:
1130: tree
1.1.1.2 root 1131: build_nt (va_alist)
1132: va_dcl
1.1 root 1133: {
1.1.1.2 root 1134: register va_list p;
1135: register enum tree_code code;
1136: register tree t;
1137: register int length;
1138: register int i;
1139:
1140: va_start (p);
1.1 root 1141:
1.1.1.2 root 1142: code = va_arg (p, enum tree_code);
1143: t = make_node (code);
1144: length = tree_code_length[(int) code];
1145:
1146: for (i = 0; i < length; i++)
1147: TREE_OPERAND (t, i) = va_arg (p, tree);
1148:
1149: va_end (p);
1.1 root 1150: return t;
1151: }
1.1.1.2 root 1152:
1153: /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
1154: We do NOT enter this node in any sort of symbol table.
1.1 root 1155:
1.1.1.2 root 1156: layout_decl is used to set up the decl's storage layout.
1157: Other slots are initialized to 0 or null pointers. */
1.1 root 1158:
1159: tree
1.1.1.2 root 1160: build_decl (code, name, type)
1161: enum tree_code code;
1162: tree name, type;
1163: {
1164: register tree t;
1165:
1166: t = make_node (code);
1167:
1168: /* if (type == error_mark_node)
1169: type = integer_type_node; */
1170: /* That is not done, deliberately, so that having error_mark_node
1171: as the type can suppress useless errors in the use of this variable. */
1172:
1173: DECL_NAME (t) = name;
1174: TREE_TYPE (t) = type;
1175: DECL_ARGUMENTS (t) = NULL_TREE;
1176: DECL_INITIAL (t) = NULL_TREE;
1177:
1178: if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
1179: layout_decl (t, 0);
1180: else if (code == FUNCTION_DECL)
1181: DECL_MODE (t) = FUNCTION_MODE;
1182:
1.1 root 1183: return t;
1184: }
1185:
1.1.1.7 root 1186: #if 0
1.1 root 1187: /* Low-level constructors for statements.
1188: These constructors all expect source file name and line number
1189: as arguments, as well as enough arguments to fill in the data
1190: in the statement node. */
1191:
1192: tree
1193: build_goto (filename, line, label)
1194: char *filename;
1195: int line;
1196: tree label;
1197: {
1198: register tree t = make_node (GOTO_STMT);
1199: STMT_SOURCE_FILE (t) = filename;
1200: STMT_SOURCE_LINE (t) = line;
1201: STMT_BODY (t) = label;
1202: return t;
1203: }
1204:
1205: tree
1206: build_return (filename, line, arg)
1207: char *filename;
1208: int line;
1209: tree arg;
1210: {
1211: register tree t = make_node (RETURN_STMT);
1212:
1213: STMT_SOURCE_FILE (t) = filename;
1214: STMT_SOURCE_LINE (t) = line;
1215: STMT_BODY (t) = arg;
1216: return t;
1217: }
1218:
1219: tree
1220: build_expr_stmt (filename, line, expr)
1221: char *filename;
1222: int line;
1223: tree expr;
1224: {
1225: register tree t = make_node (EXPR_STMT);
1226:
1227: STMT_SOURCE_FILE (t) = filename;
1228: STMT_SOURCE_LINE (t) = line;
1229: STMT_BODY (t) = expr;
1230: return t;
1231: }
1232:
1233: tree
1234: build_if (filename, line, cond, thenclause, elseclause)
1235: char *filename;
1236: int line;
1237: tree cond, thenclause, elseclause;
1238: {
1239: register tree t = make_node (IF_STMT);
1240:
1241: STMT_SOURCE_FILE (t) = filename;
1242: STMT_SOURCE_LINE (t) = line;
1243: STMT_COND (t) = cond;
1244: STMT_THEN (t) = thenclause;
1245: STMT_ELSE (t) = elseclause;
1246: return t;
1247: }
1248:
1249: tree
1250: build_exit (filename, line, cond)
1251: char *filename;
1252: int line;
1253: tree cond;
1254: {
1255: register tree t = make_node (EXIT_STMT);
1256: STMT_SOURCE_FILE (t) = filename;
1257: STMT_SOURCE_LINE (t) = line;
1258: STMT_BODY (t) = cond;
1259: return t;
1260: }
1261:
1262: tree
1263: build_asm_stmt (filename, line, asmcode)
1264: char *filename;
1265: int line;
1266: tree asmcode;
1267: {
1268: register tree t = make_node (ASM_STMT);
1269: STMT_SOURCE_FILE (t) = filename;
1270: STMT_SOURCE_LINE (t) = line;
1271: STMT_BODY (t) = asmcode;
1272: return t;
1273: }
1274:
1275: tree
1276: build_case (filename, line, object, cases)
1277: char *filename;
1278: int line;
1279: tree object, cases;
1280: {
1281: register tree t = make_node (CASE_STMT);
1282: STMT_SOURCE_FILE (t) = filename;
1283: STMT_SOURCE_LINE (t) = line;
1284: STMT_CASE_INDEX (t) = object;
1285: STMT_CASE_LIST (t) = cases;
1286: return t;
1287: }
1288:
1289: tree
1.1.1.7 root 1290: build_loop (filename, line, body)
1.1 root 1291: char *filename;
1292: int line;
1.1.1.7 root 1293: tree body;
1.1 root 1294: {
1.1.1.7 root 1295: register tree t = make_node (LOOP_STMT);
1.1 root 1296: STMT_SOURCE_FILE (t) = filename;
1297: STMT_SOURCE_LINE (t) = line;
1298: STMT_BODY (t) = body;
1299: return t;
1300: }
1301:
1302: tree
1.1.1.7 root 1303: build_compound (filename, line, body)
1.1 root 1304: char *filename;
1305: int line;
1306: tree body;
1307: {
1.1.1.7 root 1308: register tree t = make_node (COMPOUND_STMT);
1.1 root 1309: STMT_SOURCE_FILE (t) = filename;
1310: STMT_SOURCE_LINE (t) = line;
1311: STMT_BODY (t) = body;
1312: return t;
1313: }
1314:
1.1.1.7 root 1315: #endif /* 0 */
1316:
1317: /* LET_STMT nodes are used to represent the structure of binding contours
1318: and declarations, once those contours have been exited and their contents
1319: compiled. This information is used for outputting debugging info. */
1320:
1.1 root 1321: tree
1.1.1.7 root 1322: build_let (filename, line, vars, body, supercontext, tags)
1.1 root 1323: char *filename;
1324: int line;
1.1.1.7 root 1325: tree vars, body, supercontext, tags;
1.1 root 1326: {
1.1.1.7 root 1327: register tree t = make_node (LET_STMT);
1.1 root 1328: STMT_SOURCE_FILE (t) = filename;
1329: STMT_SOURCE_LINE (t) = line;
1.1.1.7 root 1330: STMT_VARS (t) = vars;
1.1 root 1331: STMT_BODY (t) = body;
1.1.1.7 root 1332: STMT_SUPERCONTEXT (t) = supercontext;
1333: STMT_BIND_SIZE (t) = 0;
1334: STMT_TYPE_TAGS (t) = tags;
1.1 root 1335: return t;
1336: }
1337:
1338: /* Return a type like TYPE except that its TREE_READONLY is CONSTP
1339: and its TREE_VOLATILE is VOLATILEP.
1340:
1341: Such variant types already made are recorded so that duplicates
1342: are not made.
1343:
1344: A variant types should never be used as the type of an expression.
1345: Always copy the variant information into the TREE_READONLY
1346: and TREE_VOLATILE of the expression, and then give the expression
1347: as its type the "main variant", the variant whose TREE_READONLY
1348: and TREE_VOLATILE are zero. Use TYPE_MAIN_VARIANT to find the
1349: main variant. */
1350:
1351: tree
1352: build_type_variant (type, constp, volatilep)
1353: tree type;
1354: int constp, volatilep;
1355: {
1356: register tree t, m = TYPE_MAIN_VARIANT (type);
1357: register struct obstack *ambient_obstack = current_obstack;
1358:
1359: /* Treat any nonzero argument as 1. */
1360: constp = !!constp;
1361: volatilep = !!volatilep;
1362:
1363: /* First search the chain variants for one that is what we want. */
1364:
1365: for (t = m; t; t = TYPE_NEXT_VARIANT (t))
1366: if (constp == TREE_READONLY (t)
1367: && volatilep == TREE_VOLATILE (t))
1368: return t;
1369:
1370: /* We need a new one. */
1.1.1.2 root 1371: current_obstack
1372: = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
1.1 root 1373:
1374: t = copy_node (type);
1375: TREE_READONLY (t) = constp;
1376: TREE_VOLATILE (t) = volatilep;
1377: TYPE_POINTER_TO (t) = 0;
1.1.1.7 root 1378: TYPE_REFERENCE_TO (t) = 0;
1.1 root 1379:
1380: /* Add this type to the chain of variants of TYPE. */
1381: TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
1382: TYPE_NEXT_VARIANT (m) = t;
1383:
1384: current_obstack = ambient_obstack;
1385: return t;
1386: }
1387:
1.1.1.2 root 1388: /* Hashing of types so that we don't make duplicates.
1389: The entry point is `type_hash_canon'. */
1390:
1391: /* Each hash table slot is a bucket containing a chain
1392: of these structures. */
1393:
1394: struct type_hash
1395: {
1396: struct type_hash *next; /* Next structure in the bucket. */
1397: int hashcode; /* Hash code of this type. */
1398: tree type; /* The type recorded here. */
1399: };
1400:
1401: /* Now here is the hash table. When recording a type, it is added
1402: to the slot whose index is the hash code mod the table size.
1403: Note that the hash table is used for several kinds of types
1404: (function types, array types and array index range types, for now).
1405: While all these live in the same table, they are completely independent,
1406: and the hash code is computed differently for each of these. */
1407:
1.1.1.7 root 1408: #define TYPE_HASH_SIZE 59
1.1.1.2 root 1409: struct type_hash *type_hash_table[TYPE_HASH_SIZE];
1410:
1411: /* Here is how primitive or already-canonicalized types' hash
1412: codes are made. */
1413: #define TYPE_HASH(TYPE) TREE_UID (TYPE)
1414:
1415: /* Compute a hash code for a list of types (chain of TREE_LIST nodes
1416: with types in the TREE_VALUE slots), by adding the hash codes
1417: of the individual types. */
1418:
1419: int
1420: type_hash_list (list)
1421: tree list;
1422: {
1423: register int hashcode;
1424: register tree tail;
1425: for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
1426: hashcode += TYPE_HASH (TREE_VALUE (tail));
1427: return hashcode;
1428: }
1429:
1430: /* Look in the type hash table for a type isomorphic to TYPE.
1431: If one is found, return it. Otherwise return 0. */
1432:
1433: tree
1434: type_hash_lookup (hashcode, type)
1435: int hashcode;
1436: tree type;
1437: {
1438: register struct type_hash *h;
1439: for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
1440: if (h->hashcode == hashcode
1441: && TREE_CODE (h->type) == TREE_CODE (type)
1442: && TREE_TYPE (h->type) == TREE_TYPE (type)
1443: && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
1444: || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
1445: TYPE_MAX_VALUE (type)))
1446: && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
1447: || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
1448: TYPE_MIN_VALUE (type)))
1449: && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
1450: || (TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
1451: && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
1452: && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
1453: return h->type;
1454: return 0;
1455: }
1456:
1457: /* Add an entry to the type-hash-table
1458: for a type TYPE whose hash code is HASHCODE. */
1459:
1460: void
1461: type_hash_add (hashcode, type)
1462: int hashcode;
1463: tree type;
1464: {
1465: register struct type_hash *h;
1466:
1467: h = (struct type_hash *) oballoc (sizeof (struct type_hash));
1468: h->hashcode = hashcode;
1469: h->type = type;
1470: h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
1471: type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
1472: }
1473:
1474: /* Given TYPE, and HASHCODE its hash code, return the canonical
1475: object for an identical type if one already exists.
1476: Otherwise, return TYPE, and record it as the canonical object
1477: if it is a permanent object.
1478:
1479: To use this function, first create a type of the sort you want.
1480: Then compute its hash code from the fields of the type that
1481: make it different from other similar types.
1482: Then call this function and use the value.
1483: This function frees the type you pass in if it is a duplicate. */
1484:
1485: /* Set to 1 to debug without canonicalization. Never set by program. */
1486: int debug_no_type_hash = 0;
1487:
1488: tree
1489: type_hash_canon (hashcode, type)
1490: int hashcode;
1491: tree type;
1492: {
1493: tree t1;
1494:
1495: if (debug_no_type_hash)
1496: return type;
1497:
1498: t1 = type_hash_lookup (hashcode, type);
1499: if (t1 != 0)
1500: {
1501: struct obstack *o
1502: = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
1503: obstack_free (o, type);
1504: return t1;
1505: }
1506:
1507: /* If this is a new type, record it for later reuse. */
1508: if (current_obstack == &permanent_obstack)
1509: type_hash_add (hashcode, type);
1510:
1511: return type;
1512: }
1513:
1514: /* Given two lists of types
1515: (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
1.1.1.7 root 1516: return 1 if the lists contain the same types in the same order.
1517: Also, the TREE_PURPOSEs must match. */
1.1.1.2 root 1518:
1519: int
1520: type_list_equal (l1, l2)
1521: tree l1, l2;
1522: {
1523: register tree t1, t2;
1524: for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1.1.1.7 root 1525: {
1526: if (TREE_VALUE (t1) != TREE_VALUE (t2))
1527: return 0;
1528: if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
1529: && !simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
1530: return 0;
1531: }
1.1.1.2 root 1532:
1533: return t1 == t2;
1534: }
1535:
1536: /* Nonzero if integer constants T1 and T2
1537: represent the same constant value. */
1538:
1539: int
1540: tree_int_cst_equal (t1, t2)
1541: tree t1, t2;
1542: {
1543: if (t1 == t2)
1544: return 1;
1545: if (t1 == 0 || t2 == 0)
1546: return 0;
1547: if (TREE_CODE (t1) == INTEGER_CST
1548: && TREE_CODE (t2) == INTEGER_CST
1549: && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1550: && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
1551: return 1;
1552: return 0;
1553: }
1554:
1555: /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
1556: The precise way of comparison depends on their data type. */
1557:
1558: int
1559: tree_int_cst_lt (t1, t2)
1560: tree t1, t2;
1561: {
1562: if (t1 == t2)
1563: return 0;
1564:
1565: if (!TREE_UNSIGNED (TREE_TYPE (t1)))
1566: return INT_CST_LT (t1, t2);
1567: return INT_CST_LT_UNSIGNED (t1, t2);
1568: }
1.1.1.7 root 1569:
1570: /* Compare two constructor-element-type constants. */
1571:
1572: int
1573: simple_cst_equal (t1, t2)
1574: tree t1, t2;
1575: {
1576: register enum tree_code code1, code2;
1577:
1578: if (t1 == t2)
1579: return 1;
1580: if (t1 == 0 || t2 == 0)
1581: return 0;
1582:
1583: code1 = TREE_CODE (t1);
1584: code2 = TREE_CODE (t2);
1585:
1586: if (code1 == NOP_EXPR || code1 == CONVERT_EXPR)
1587: if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
1588: return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1589: else
1590: return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
1591: else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
1592: return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
1593:
1594: if (code1 != code2)
1595: return 0;
1596:
1597: switch (code1)
1598: {
1599: case INTEGER_CST:
1600: return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
1601: && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
1602:
1603: case REAL_CST:
1604: return TREE_REAL_CST (t1) == TREE_REAL_CST (t2);
1605:
1606: case STRING_CST:
1607: return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
1608: && !strcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2));
1609:
1610: case CONSTRUCTOR:
1611: abort ();
1612:
1613: case VAR_DECL:
1614: case PARM_DECL:
1615: case CONST_DECL:
1616: return 0;
1617:
1618: case PLUS_EXPR:
1619: case MINUS_EXPR:
1620: case MULT_EXPR:
1621: case TRUNC_DIV_EXPR:
1622: case TRUNC_MOD_EXPR:
1623: case LSHIFT_EXPR:
1624: case RSHIFT_EXPR:
1625: return (simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
1626: && simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
1627:
1628: case NEGATE_EXPR:
1629: case ADDR_EXPR:
1630: case REFERENCE_EXPR:
1631: return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
1632:
1633: default:
1634: abort ();
1635: }
1636: }
1.1.1.2 root 1637:
1.1 root 1638: /* Constructors for pointer, array and function types.
1639: (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
1640: constructed by language-dependent code, not here.) */
1641:
1.1.1.2 root 1642: /* Construct, lay out and return the type of pointers to TO_TYPE.
1643: If such a type has already been constructed, reuse it. */
1644:
1.1 root 1645: tree
1646: build_pointer_type (to_type)
1647: tree to_type;
1648: {
1649: register tree t = TYPE_POINTER_TO (to_type);
1650: register struct obstack *ambient_obstack = current_obstack;
1.1.1.4 root 1651: register struct obstack *ambient_saveable_obstack = saveable_obstack;
1.1 root 1652:
1653: /* First, if we already have a type for pointers to TO_TYPE, use it. */
1654:
1655: if (t)
1656: return t;
1657:
1658: /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
1.1.1.4 root 1659: if (TREE_PERMANENT (to_type))
1660: {
1661: current_obstack = &permanent_obstack;
1662: saveable_obstack = &permanent_obstack;
1663: }
1.1 root 1664:
1665: t = make_node (POINTER_TYPE);
1666: TREE_TYPE (t) = to_type;
1667:
1668: /* Record this type as the pointer to TO_TYPE. */
1669: TYPE_POINTER_TO (to_type) = t;
1670:
1.1.1.2 root 1671: /* Lay out the type. This function has many callers that are concerned
1672: with expression-construction, and this simplifies them all.
1673: Also, it guarantees the TYPE_SIZE is permanent if the type is. */
1674: layout_type (t);
1.1 root 1675:
1676: current_obstack = ambient_obstack;
1.1.1.4 root 1677: saveable_obstack = ambient_saveable_obstack;
1.1 root 1678: return t;
1679: }
1680:
1.1.1.8 root 1681: /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
1682: MAXVAL should be the maximum value in the domain
1683: (one less than the length of the array). */
1684:
1685: tree
1686: build_index_type (maxval)
1687: tree maxval;
1688: {
1689: register tree itype = make_node (INTEGER_TYPE);
1690: int maxint = TREE_INT_CST_LOW (maxval);
1691: TYPE_PRECISION (itype) = BITS_PER_WORD;
1692: TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
1693: TREE_TYPE (TYPE_MIN_VALUE (itype)) = itype;
1694: TYPE_MAX_VALUE (itype) = maxval;
1695: TREE_TYPE (maxval) = itype;
1696: TYPE_MODE (itype) = SImode;
1697: TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
1698: TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
1699: TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
1700: return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);
1701: }
1702:
1.1.1.2 root 1703: /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
1704: and number of elements specified by the range of values of INDEX_TYPE.
1705: If such a type has already been constructed, reuse it. */
1706:
1.1 root 1707: tree
1708: build_array_type (elt_type, index_type)
1709: tree elt_type, index_type;
1710: {
1711: register tree t = make_node (ARRAY_TYPE);
1.1.1.2 root 1712: int hashcode;
1.1 root 1713:
1714: if (TREE_CODE (elt_type) == FUNCTION_TYPE)
1715: {
1.1.1.2 root 1716: error ("arrays of functions are not meaningful");
1.1 root 1717: elt_type = integer_type_node;
1718: }
1719:
1720: TREE_TYPE (t) = elt_type;
1721: TYPE_DOMAIN (t) = index_type;
1.1.1.2 root 1722:
1.1 root 1723: /* Make sure TYPE_POINTER_TO (elt_type) is filled in. */
1724: build_pointer_type (elt_type);
1.1.1.2 root 1725:
1726: if (index_type == 0)
1727: return t;
1728:
1729: hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
1730: t = type_hash_canon (hashcode, t);
1731:
1732: if (TYPE_SIZE (t) == 0)
1733: layout_type (t);
1.1 root 1734: return t;
1735: }
1736:
1.1.1.2 root 1737: /* Construct, lay out and return
1738: the type of functions returning type VALUE_TYPE
1739: given arguments of types ARG_TYPES.
1740: ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
1741: are data type nodes for the arguments of the function.
1742: If such a type has already been constructed, reuse it. */
1.1 root 1743:
1744: tree
1745: build_function_type (value_type, arg_types)
1746: tree value_type, arg_types;
1747: {
1748: register tree t;
1.1.1.2 root 1749: int hashcode;
1.1 root 1750:
1.1.1.2 root 1751: if (TREE_CODE (value_type) == FUNCTION_TYPE
1.1 root 1752: || TREE_CODE (value_type) == ARRAY_TYPE)
1753: {
1.1.1.2 root 1754: error ("function return type cannot be function or array");
1.1 root 1755: value_type = integer_type_node;
1756: }
1757:
1.1.1.2 root 1758: /* Make a node of the sort we want. */
1.1 root 1759: t = make_node (FUNCTION_TYPE);
1760: TREE_TYPE (t) = value_type;
1761: TYPE_ARG_TYPES (t) = arg_types;
1.1.1.2 root 1762:
1763: /* If we already have such a type, use the old one and free this one. */
1764: hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
1765: t = type_hash_canon (hashcode, t);
1766:
1767: if (TYPE_SIZE (t) == 0)
1768: layout_type (t);
1.1 root 1769: return t;
1770: }
1.1.1.7 root 1771:
1772: /* Build the node for the type of references-to-TO_TYPE. */
1773:
1774: tree
1775: build_reference_type (to_type)
1776: tree to_type;
1777: {
1778: register tree t = TYPE_REFERENCE_TO (to_type);
1779: register struct obstack *ambient_obstack = current_obstack;
1780: register struct obstack *ambient_saveable_obstack = saveable_obstack;
1781:
1782: /* First, if we already have a type for pointers to TO_TYPE, use it. */
1783:
1784: if (t)
1785: return t;
1786:
1787: /* We need a new one. If TO_TYPE is permanent, make this permanent too. */
1788: if (TREE_PERMANENT (to_type))
1789: {
1790: current_obstack = &permanent_obstack;
1791: saveable_obstack = &permanent_obstack;
1792: }
1793:
1794: t = make_node (REFERENCE_TYPE);
1795: TREE_TYPE (t) = to_type;
1796:
1797: /* Record this type as the pointer to TO_TYPE. */
1798: TYPE_REFERENCE_TO (to_type) = t;
1799:
1800: layout_type (t);
1801:
1802: current_obstack = ambient_obstack;
1803: saveable_obstack = ambient_saveable_obstack;
1804: return t;
1805: }
1806:
1807: /* Construct, lay out and return the type of methods belonging to class
1808: BASETYPE and whose arguments and values are described by TYPE.
1809: If that type exists already, reuse it.
1810: TYPE must be a FUNCTION_TYPE node. */
1811:
1812: tree
1813: build_method_type (basetype, type)
1814: tree basetype, type;
1815: {
1816: register tree t;
1817: int hashcode;
1818:
1819: /* Make a node of the sort we want. */
1820: t = make_node (METHOD_TYPE);
1821:
1822: if (TREE_CODE (type) != FUNCTION_TYPE)
1823: abort ();
1824:
1825: TYPE_METHOD_CLASS (t) == basetype;
1826: TREE_TYPE (t) = type;
1827:
1828: /* The actual arglist for this function includes a "hidden" argument
1829: which is "this". Put it into the list of argument types. */
1830:
1831: TYPE_ARG_TYPES (t)
1832: = tree_cons (NULL, build_pointer_type (basetype), TYPE_ARG_TYPES (type));
1833:
1834: /* If we already have such a type, use the old one and free this one. */
1835: hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
1836: t = type_hash_canon (hashcode, t);
1837:
1838: if (TYPE_SIZE (t) == 0)
1839: layout_type (t);
1840:
1841: return t;
1842: }
1.1 root 1843:
1844: /* Return OP, stripped of any conversions to wider types as much as is safe.
1845: Converting the value back to OP's type makes a value equivalent to OP.
1846:
1847: If FOR_TYPE is nonzero, we return a value which, if converted to
1848: type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
1849:
1.1.1.2 root 1850: If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
1851: narrowest type that can hold the value, even if they don't exactly fit.
1852: Otherwise, bit-field references are changed to a narrower type
1853: only if they can be fetched directly from memory in that type.
1854:
1.1 root 1855: OP must have integer, real or enumeral type. Pointers are not allowed!
1856:
1857: There are some cases where the obvious value we could return
1858: would regenerate to OP if converted to OP's type,
1859: but would not extend like OP to wider types.
1860: If FOR_TYPE indicates such extension is contemplated, we eschew such values.
1861: For example, if OP is (unsigned short)(signed char)-1,
1862: we avoid returning (signed char)-1 if FOR_TYPE is int,
1863: even though extending that to an unsigned short would regenerate OP,
1864: since the result of extending (signed char)-1 to (int)
1865: is different from (int) OP. */
1866:
1867: tree
1868: get_unwidened (op, for_type)
1869: register tree op;
1870: tree for_type;
1871: {
1872: /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
1873: /* TYPE_PRECISION is safe in place of type_precision since
1874: pointer types are not allowed. */
1875: register tree type = TREE_TYPE (op);
1876: register int final_prec = TYPE_PRECISION (for_type != 0 ? for_type : type);
1877: register int uns
1878: = (for_type != 0 && for_type != type
1879: && final_prec > TYPE_PRECISION (type)
1.1.1.2 root 1880: && TREE_UNSIGNED (type));
1.1 root 1881: register tree win = op;
1882:
1883: while (TREE_CODE (op) == NOP_EXPR)
1884: {
1885: register int bitschange
1886: = TYPE_PRECISION (TREE_TYPE (op))
1887: - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
1888:
1889: /* Truncations are many-one so cannot be removed.
1890: Unless we are later going to truncate down even farther. */
1891: if (bitschange < 0
1892: && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
1893: break;
1894:
1895: /* See what's inside this conversion. If we decide to strip it,
1896: we will set WIN. */
1897: op = TREE_OPERAND (op, 0);
1898:
1899: /* If we have not stripped any zero-extensions (uns is 0),
1900: we can strip any kind of extension.
1901: If we have previously stripped a zero-extension,
1902: only zero-extensions can safely be stripped.
1903: Any extension can be stripped if the bits it would produce
1904: are all going to be discarded later by truncating to FOR_TYPE. */
1905:
1906: if (bitschange > 0)
1907: {
1908: if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
1909: win = op;
1.1.1.2 root 1910: /* TREE_UNSIGNED says whether this is a zero-extension.
1.1 root 1911: Let's avoid computing it if it does not affect WIN
1912: and if UNS will not be needed again. */
1913: if ((uns || TREE_CODE (op) == NOP_EXPR)
1.1.1.2 root 1914: && TREE_UNSIGNED (TREE_TYPE (op)))
1.1 root 1915: {
1916: uns = 1;
1917: win = op;
1918: }
1919: }
1920: }
1921:
1.1.1.2 root 1922: if (TREE_CODE (op) == COMPONENT_REF
1923: /* Since type_for_size always gives an integer type. */
1924: && TREE_CODE (type) != REAL_TYPE)
1925: {
1926: int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
1927: * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
1928: type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
1929:
1930: /* We can get this structure field in the narrowest type it fits in.
1931: If FOR_TYPE is 0, do this only for a field that matches the
1932: narrower type exactly and is aligned for it (i.e. mode isn't BI).
1933: The resulting extension to its nominal type (a fullword type)
1934: must fit the same conditions as for other extensions. */
1935:
1.1.1.3 root 1936: if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
1.1.1.2 root 1937: && (for_type || DECL_MODE (TREE_OPERAND (op, 1)) != BImode)
1938: && (! uns || final_prec <= innerprec
1939: || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
1940: && type != 0)
1941: {
1942: win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
1943: TREE_OPERAND (op, 1));
1944: TREE_VOLATILE (win) = TREE_VOLATILE (op);
1945: TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
1946: }
1947: }
1.1 root 1948: return win;
1949: }
1950:
1951: /* Return OP or a simpler expression for a narrower value
1952: which can be sign-extended or zero-extended to give back OP.
1953: Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
1954: or 0 if the value should be sign-extended. */
1955:
1956: tree
1957: get_narrower (op, unsignedp_ptr)
1958: register tree op;
1959: int *unsignedp_ptr;
1960: {
1961: register int uns = 0;
1962: int first = 1;
1963: register tree win = op;
1964:
1965: while (TREE_CODE (op) == NOP_EXPR)
1966: {
1967: register int bitschange
1968: = TYPE_PRECISION (TREE_TYPE (op))
1969: - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
1970:
1971: /* Truncations are many-one so cannot be removed. */
1972: if (bitschange < 0)
1973: break;
1974:
1975: /* See what's inside this conversion. If we decide to strip it,
1976: we will set WIN. */
1977: op = TREE_OPERAND (op, 0);
1978:
1979: if (bitschange > 0)
1980: {
1981: /* An extension: the outermost one can be stripped,
1982: but remember whether it is zero or sign extension. */
1983: if (first)
1.1.1.2 root 1984: uns = TREE_UNSIGNED (TREE_TYPE (op));
1.1 root 1985: /* Otherwise, if a sign extension has been stripped,
1986: only sign extensions can now be stripped;
1987: if a zero extension has been stripped, only zero-extensions. */
1.1.1.2 root 1988: else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
1.1 root 1989: break;
1990: first = 0;
1991: }
1992: /* A change in nominal type can always be stripped. */
1993:
1994: win = op;
1995: }
1996:
1.1.1.2 root 1997: if (TREE_CODE (op) == COMPONENT_REF
1998: /* Since type_for_size always gives an integer type. */
1999: && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
1.1 root 2000: {
2001: int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
2002: * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
1.1.1.2 root 2003: tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
1.1 root 2004:
2005: /* We can get this structure field in a narrower type that fits it,
2006: but the resulting extension to its nominal type (a fullword type)
1.1.1.2 root 2007: must satisfy the same conditions as for other extensions.
2008:
2009: Do this only for fields that are aligned (not BImode),
2010: because when bit-field insns will be used there is no
2011: advantage in doing this. */
1.1 root 2012:
2013: if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
1.1.1.2 root 2014: && DECL_MODE (TREE_OPERAND (op, 1)) != BImode
2015: && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
1.1 root 2016: && type != 0)
2017: {
1.1.1.2 root 2018: if (first)
2019: uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
2020: win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
2021: TREE_OPERAND (op, 1));
2022: TREE_VOLATILE (win) = TREE_VOLATILE (op);
2023: TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
1.1 root 2024: }
2025: }
2026: *unsignedp_ptr = uns;
2027: return win;
2028: }
2029:
2030: /* Return the precision of a type, for arithmetic purposes.
2031: Supports all types on which arithmetic is possible
2032: (including pointer types).
2033: It's not clear yet what will be right for complex types. */
2034:
2035: int
2036: type_precision (type)
2037: register tree type;
2038: {
2039: return ((TREE_CODE (type) == INTEGER_TYPE
2040: || TREE_CODE (type) == ENUMERAL_TYPE
2041: || TREE_CODE (type) == REAL_TYPE)
1.1.1.2 root 2042: ? TYPE_PRECISION (type) : POINTER_SIZE);
1.1 root 2043: }
2044:
2045: /* Nonzero if integer constant C has a value that is permissible
2046: for type TYPE (an INTEGER_TYPE). */
2047:
2048: int
2049: int_fits_type_p (c, type)
2050: tree c, type;
2051: {
1.1.1.2 root 2052: if (TREE_UNSIGNED (type))
1.1 root 2053: return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
2054: && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type)));
2055: else
2056: return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)
2057: && !INT_CST_LT (c, TYPE_MIN_VALUE (type)));
2058: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.