Annotation of gcc/tree.c, revision 1.1.1.4

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.