home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 321 / compsrc3 / stor-lay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  23.5 KB  |  805 lines

  1. /* C-compiler utilities for types and variables storage layout
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  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. #include "config.h"
  23. #include <stdio.h>
  24.  
  25. #include "tree.h"
  26. #include "rtl.h"   /* For GET_MODE_SIZE */
  27.  
  28. #define MAX(x,y) ((x) > (y) ? (x) : (y))
  29. #define MIN(x,y) ((x) < (y) ? (x) : (y))
  30. #define CEIL(x,y) (((x) + (y) - 1) / (y))
  31.  
  32. /* Data type for the expressions representing sizes of data types.
  33.    It is the first integer type laid out.
  34.    In C, this is int.  */
  35.  
  36. tree sizetype;
  37.  
  38. /* An integer constant with value 0 whose type is sizetype.  */
  39.  
  40. tree size_zero_node;
  41.  
  42. /* An integer constant with value 1 whose type is sizetype.  */
  43.  
  44. tree size_one_node;
  45.  
  46. #define GET_MODE_ALIGNMENT(MODE)   \
  47.   MIN (BIGGEST_ALIGNMENT,        \
  48.        MAX (1, (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT)))
  49.  
  50. /* Chain of all permanent types we have allocated since last
  51.    call to get_permanent_types.  */
  52.  
  53. tree permanent_type_chain;
  54.  
  55. /* Chain of all temporary types we have allocated in this function.  */
  56.  
  57. tree temporary_type_chain;
  58.  
  59. /* When the chains is not null, these point at the last
  60.    types on the two chains.  These help us tell whether a type
  61.    is already on a chain.  */
  62. tree permanent_type_end;
  63. tree temporary_type_end;
  64.  
  65. /* Put the newly-made type T
  66.    on either permanent_type_chain or temporary_type_chain.
  67.    Types that are const or volatile variants of other types
  68.    are not put on any chain, since in the gdb symbol segment
  69.    we do not make those distinctions.
  70.  
  71.    If T is already on the chain, we do nothing.  */
  72.  
  73. void
  74. chain_type (t)
  75.      tree t;
  76. {
  77.   if (TYPE_MAIN_VARIANT (t) != t)
  78.     return;
  79.   if (TREE_CHAIN (t) != 0)
  80.     return;
  81.   if (TREE_PERMANENT (t))
  82.     {
  83.       /* If T is on the chain at the end, don't chain it to itself!  */
  84.       if (t == permanent_type_end)
  85.     return;
  86.       /* Add T to the end of the chain.  */
  87.       if (permanent_type_chain == 0)
  88.     permanent_type_chain = t;
  89.       else
  90.     TREE_CHAIN (permanent_type_end) = t;
  91.       permanent_type_end = t;
  92.     }
  93.   else
  94.     {
  95.       if (t == temporary_type_end)
  96.     return;
  97.       if (temporary_type_chain == 0)
  98.     temporary_type_chain = t;
  99.       else
  100.     TREE_CHAIN (temporary_type_end) = t;
  101.       temporary_type_end = t;
  102.     }
  103. }
  104.  
  105. /* Get a chain of all permanent types made since this function
  106.    was last called.  */
  107.  
  108. tree
  109. get_permanent_types ()
  110. {
  111.   register tree tem = permanent_type_chain;
  112.   permanent_type_chain = 0;
  113.   permanent_type_end = 0;
  114.   return tem;
  115. }
  116.  
  117. /* Get a chain of all temporary types made since this function
  118.    was last called.  */
  119.  
  120. tree
  121. get_temporary_types ()
  122. {
  123.   register tree tem = temporary_type_chain;
  124.   temporary_type_chain = 0;
  125.   temporary_type_end = 0;
  126.   return tem;
  127. }
  128.  
  129. /* SAVE_EXPRs for sizes of types and decls, waiting to be expanded.  */
  130.  
  131. static tree pending_sizes;
  132.  
  133. /* Nonzero means cannot safely call expand_expr now,
  134.    so put variable sizes onto `pending_sizes' instead.  */
  135.  
  136. int immediate_size_expand;
  137.  
  138. tree
  139. get_pending_sizes ()
  140. {
  141.   tree chain = pending_sizes;
  142.   pending_sizes = 0;
  143.   return chain;
  144. }
  145.  
  146. /* Given a size SIZE that isn't constant, return a SAVE_EXPR
  147.    to serve as the actual size-expression for a type or decl.  */
  148.  
  149. static tree
  150. variable_size (size)
  151.      tree size;
  152. {
  153.   size = save_expr (size);
  154.  
  155.   if (global_bindings_p ())
  156.     {
  157.       error ("variable-size type declared outside of any function");
  158.       return build_int (1);
  159.     }
  160.  
  161.   if (immediate_size_expand)
  162.     expand_expr (size, 0, VOIDmode, 0);
  163.   else
  164.     pending_sizes = tree_cons (0, size, pending_sizes);
  165.  
  166.   return size;
  167. }
  168.  
  169. /* Return the machine mode to use for an aggregate of SIZE bits.
  170.  
  171.    Note!!!  We only use a non-BLKmode mode if the size matches exactly.
  172.    There used to be the idea of using DImode for anything whose
  173.    size was less than DImode but more than SImode.  This does not work
  174.    because DImode moves cannot be used to store such objects in memory.  */
  175.  
  176. static
  177. enum machine_mode
  178. agg_mode (size)
  179.      unsigned int size;
  180. {
  181.   register int units = size / BITS_PER_UNIT;
  182.   register enum machine_mode t;
  183.  
  184.   if (size % BITS_PER_UNIT != 0)
  185.     return BLKmode;
  186.  
  187.   for (t = QImode; (int) t <= (int) DImode;
  188.        t = (enum machine_mode) ((int) t + 1))
  189.     if (GET_MODE_SIZE (t) == units)
  190.       return t;
  191.  
  192.   return BLKmode;
  193. }
  194.  
  195. /* Return an INTEGER_CST with value V and type from `sizetype'.  */
  196.  
  197. tree
  198. build_int (v)
  199.      int v;
  200. {
  201.   register tree t;
  202.  
  203.   t = build_int_2 (v, 0);
  204.   TREE_TYPE (t) = sizetype;
  205.   return t;
  206. }
  207.  
  208. /* Combine operands OP1 and OP2 with arithmetic operation OPC.
  209.    OPC is a tree code.  Data type is taken from `sizetype',
  210.    If the operands are constant, so is the result.  */
  211.  
  212. tree
  213. genop (opc, op1, op2)
  214.      enum tree_code opc;
  215.      tree op1, op2;
  216. {
  217.   if (TREE_LITERAL (op1) && TREE_LITERAL (op2))
  218.     return combine (opc, op1, op2);
  219.  
  220.   if (op1 == error_mark_node || op2 == error_mark_node)
  221.     return error_mark_node;
  222.  
  223.   return fold (build (opc, sizetype, op1, op2));
  224. }
  225.  
  226. /* Convert a size which is SIZE when expressed in unit INUNITS
  227.    into the units OUTUNITS.  Rounds up if conversion is not exact.
  228.    If SIZE is constant, so is the result.  */
  229.  
  230. tree
  231. convert_units (size, inunits, outunits)
  232.    tree size;
  233.    register int inunits, outunits;
  234. {
  235.   register tree t;
  236.  
  237.   if (inunits == outunits)
  238.     return size;
  239.   /* Check for inunits divisible by outunits.
  240.      In that case, just multiply by their ratio.  */
  241.   if (0 == (inunits % outunits))
  242.     return genop (MULT_EXPR, size, build_int (inunits / outunits));
  243.   /* The inverse case.  */
  244.   if (0 == (outunits % inunits))
  245.     {
  246.       /* Discard anything in SIZE to round it up to a multiple
  247.      of a number N that divides our current divisor.  */
  248.       if (TREE_CODE (size) == MULT_EXPR
  249.       && TREE_CODE (TREE_OPERAND (size, 1)) == INTEGER_CST
  250.       && 0 == (outunits / inunits) % TREE_INT_CST_LOW (TREE_OPERAND (size, 1))
  251.       && TREE_CODE (TREE_OPERAND (size, 0)) == CEIL_DIV_EXPR
  252.       && tree_int_cst_equal (TREE_OPERAND (size, 1),
  253.                  TREE_OPERAND (TREE_OPERAND (size, 0), 1)))
  254.     size = TREE_OPERAND (TREE_OPERAND (size, 0), 0);
  255.       return genop (CEIL_DIV_EXPR, size, build_int (outunits / inunits));
  256.     }
  257.   /* The general case.  */
  258.   t = genop (MULT_EXPR, size,
  259.          build_int (inunits)); /* convert to bits */
  260.   return genop (CEIL_DIV_EXPR, t,
  261.         build_int (outunits)); /* then to outunits */
  262. }
  263.  
  264. /* Set the size, mode and alignment of a ..._DECL node.
  265.    Note that LABEL_DECL, TYPE_DECL and CONST_DECL nodes do not need this,
  266.    and FUNCTION_DECL nodes have them set up in a special (and simple) way.
  267.    Don't call layout_decl for them.
  268.  
  269.    KNOWN_ALIGN is the amount of alignment we can assume this
  270.    decl has with no special effort.  It is relevant only for FIELD_DECLs
  271.    and depends on the previous fields.
  272.    All that matters about KNOWN_ALIGN is which powers of 2 divide it.
  273.    If KNOWN_ALIGN is 0, it means, "as much alignment as you like":
  274.    the record will be aligned to suit.  */
  275.  
  276. void
  277. layout_decl (decl, known_align)
  278.      tree decl;
  279.      unsigned known_align;
  280. {
  281.   register tree type = TREE_TYPE (decl);
  282.   register enum tree_code code = TREE_CODE (decl);
  283.   int spec_size = DECL_SIZE_UNIT (decl);
  284.  
  285.   if (code != VAR_DECL && code != PARM_DECL && code != RESULT_DECL
  286.       && code != FIELD_DECL)
  287.     abort ();
  288.  
  289.   if (type == error_mark_node)
  290.     {
  291.       type = void_type_node;
  292.       spec_size = 0;
  293.     }
  294.   if (TYPE_SIZE_UNIT (type) == 0)
  295.     abort ();
  296.  
  297.   /* Usually the size and mode come from the data type without change.  */
  298.  
  299.   DECL_MODE (decl) = TYPE_MODE (type);
  300.   DECL_SIZE (decl) = TYPE_SIZE (type);
  301.   DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (type);
  302.   TREE_UNSIGNED (decl) = TREE_UNSIGNED (type);
  303.  
  304.   if (code == FIELD_DECL && TREE_PACKED (decl))
  305.     {
  306.       /* This is a bit-field.  We don't know how to handle
  307.      them except for integers and enums, and front end should
  308.      never generate them otherwise.  */
  309.  
  310.       if (! (TREE_CODE (type) == INTEGER_TYPE
  311.          || TREE_CODE (type) == ENUMERAL_TYPE))
  312.     abort ();
  313.  
  314.       if (spec_size == 0)
  315.     abort ();
  316.  
  317.       /* Mode is "integer bit field".  */
  318.       DECL_MODE (decl) = BImode;
  319.       /* Size is specified number of bits.  */
  320.       DECL_SIZE (decl) = size_one_node;
  321.       DECL_SIZE_UNIT (decl) = spec_size;
  322.     }
  323.   /* Force alignment required for the data type.
  324.      But if the decl itself wants greater alignment, don't override that.  */
  325.   else if (TYPE_ALIGN (type) > DECL_ALIGN (decl))
  326.     DECL_ALIGN (decl) = TYPE_ALIGN (type);
  327.  
  328.   /* See if we can use a scalar mode such as QImode or SImode
  329.      in place of BLKmode or a packed byte mode.  */
  330.   /* Conditions are: a fixed size that is correct for another mode
  331.      and occupying a complete byte or bytes on proper boundary.  */
  332.   if ((DECL_MODE (decl) == BLKmode
  333.        || DECL_MODE (decl) == BImode)
  334.       /* Don't do this is DECL's type requires it to be BLKmode.  */
  335.       && TYPE_MODE (type) != BLKmode
  336.       && TYPE_SIZE (type) != 0
  337.       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
  338.     {
  339.       register unsigned packed_size 
  340.     = TREE_INT_CST_LOW (DECL_SIZE (decl)) * DECL_SIZE_UNIT (decl);
  341.       register enum machine_mode xmode = agg_mode (packed_size);
  342.  
  343.       if (xmode != BLKmode
  344.       && known_align % GET_MODE_ALIGNMENT (xmode) == 0)
  345.     {
  346.       DECL_ALIGN (decl) = MAX (GET_MODE_ALIGNMENT (xmode),
  347.                    DECL_ALIGN (decl));
  348.       DECL_MODE (decl) = xmode;
  349.       DECL_SIZE (decl) = build_int (GET_MODE_SIZE (xmode));
  350.       DECL_SIZE_UNIT (decl) = BITS_PER_UNIT;
  351.     }
  352.     }
  353.  
  354.   /* Evaluate nonconstant size only once, either now or as soon as safe.  */
  355.   if (DECL_SIZE (decl) != 0 && ! TREE_LITERAL (DECL_SIZE (decl)))
  356.     DECL_SIZE (decl) = variable_size (DECL_SIZE (decl));
  357. }
  358.  
  359. /* Lay out a RECORD_TYPE type (a C struct).
  360.    This means laying out the fields, determining their offsets,
  361.    and computing the overall size and required alignment of the record.
  362.    Note that if you set the TYPE_ALIGN before calling this
  363.    then the struct is aligned to at least that boundary.  */
  364.  
  365. static void
  366. layout_record (rec)
  367.      tree rec;
  368. {
  369.   register tree field;
  370. #ifdef STRUCTURE_SIZE_BOUNDARY
  371.   int record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec));
  372. #else
  373.   int record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec));
  374. #endif
  375.   /* Record size so far is CONST_SIZE + VAR_SIZE * SIZE_UNIT bits,
  376.      where CONST_SIZE is an integer
  377.      and VAR_SIZE is a tree expression.
  378.      If VAR_SIZE is null, the size is just CONST_SIZE.
  379.      Naturally we try to avoid using VAR_SIZE.  */
  380.   register int const_size = 0;
  381.   register tree var_size = 0;
  382.   register int size_unit = BITS_PER_UNIT;
  383.  
  384.   for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
  385.     {
  386.       register int desired_align;
  387.  
  388.       /* Lay out the field so we know what alignment it needs.
  389.      For KNOWN_ALIGN, pass the number of bits from start of record
  390.      or some divisor of it.  */
  391.      
  392.       layout_decl (field, var_size ? size_unit : const_size);
  393.       desired_align = DECL_ALIGN (field);
  394.  
  395.       /* Record must have at least as much alignment as any field.
  396.      Otherwise, the alignment of the field within the record
  397.      is meaningless.  */
  398.  
  399.       record_align = MAX (record_align, desired_align);
  400.  
  401.       /* Does this field automatically have alignment it needs
  402.      by virtue of the fields that precede it and the record's
  403.      own alignment?  */
  404.  
  405.       if (const_size % desired_align != 0
  406.       || (size_unit % desired_align != 0
  407.           && var_size))
  408.     {
  409.       /* No, we need to skip space before this field.
  410.          Bump the cumulative size to multiple of field alignment.  */
  411.  
  412.       if (var_size == 0
  413.           || size_unit % desired_align == 0)
  414.         const_size
  415.           = CEIL (const_size, desired_align) * desired_align;
  416.       else
  417.         {
  418.           var_size
  419.         = genop (PLUS_EXPR, var_size,
  420.              build_int (CEIL (const_size, size_unit)));
  421.           const_size = 0;
  422.           var_size = convert_units (var_size, size_unit, desired_align);
  423.           size_unit = desired_align;
  424.         }
  425.     }
  426.  
  427.       /* Size so far becomes the offset of this field.  */
  428.  
  429.       DECL_OFFSET (field) = const_size;
  430.       DECL_VOFFSET (field) = var_size;
  431.       DECL_VOFFSET_UNIT (field) = size_unit;
  432.  
  433.       /* Now add size of this field to the size of the record.  */
  434.  
  435.       {
  436.         register tree dsize = DECL_SIZE (field);
  437.  
  438.     if (TREE_LITERAL (dsize))
  439.       const_size += TREE_INT_CST_LOW (dsize) * DECL_SIZE_UNIT (field);
  440.     else if (var_size == 0)
  441.       {
  442.         var_size = dsize;
  443.         size_unit = DECL_SIZE_UNIT (field);
  444.       }
  445.     else
  446.       {
  447.         register int tunits = MIN (size_unit, DECL_SIZE_UNIT (field));
  448.         var_size
  449.           = genop (PLUS_EXPR,
  450.                convert_units (var_size, size_unit, tunits),
  451.                convert_units (dsize, DECL_SIZE_UNIT (field), tunits));
  452.       }
  453.       }
  454.     }
  455.  
  456.   /* Work out the total size and alignment of the record
  457.      as one expression and store in the record type.
  458.      Round it up to a multiple of the record's alignment.  */
  459.  
  460.   if (var_size == 0)
  461.     TYPE_SIZE (rec)
  462.       = build_int (CEIL (CEIL (const_size, record_align) * record_align,
  463.              size_unit));
  464.   else
  465.     {
  466.       if (const_size)
  467.     var_size
  468.       = genop (PLUS_EXPR, var_size,
  469.            build_int (CEIL (const_size, size_unit)));
  470.       TYPE_SIZE (rec)
  471.     = convert_units (var_size,
  472.              size_unit,
  473.              record_align);
  474.       size_unit = record_align;
  475.     }
  476.  
  477.   TYPE_SIZE (rec) = convert_units (TYPE_SIZE (rec), size_unit,
  478.                    BITS_PER_UNIT);
  479.   TYPE_SIZE_UNIT (rec) = BITS_PER_UNIT;
  480.   TYPE_ALIGN (rec) = MIN (BIGGEST_ALIGNMENT, record_align);
  481. }
  482.  
  483. /* Lay out a UNION_TYPE type.
  484.    Lay out all the fields, set their offsets to zero,
  485.    and compute the size and alignment of the union (maximum of any field).
  486.    Note that if you set the TYPE_ALIGN before calling this
  487.    then the union align is aligned to at least that boundary.  */
  488.  
  489. static void
  490. layout_union (rec)
  491.      tree rec;
  492. {
  493.   register tree field;
  494. #ifdef STRUCTURE_SIZE_BOUNDARY
  495.   int union_align = STRUCTURE_SIZE_BOUNDARY;
  496. #else
  497.   int union_align = BITS_PER_UNIT;
  498. #endif
  499.  
  500.   /* The size of the union, based on the fields scanned so far,
  501.      is max (CONST_SIZE, VAR_SIZE).
  502.      VAR_SIZE may be null; then CONST_SIZE by itself is the size.  */
  503.   register int const_size = 0;
  504.   register tree var_size = 0;
  505.  
  506.   for (field = TYPE_FIELDS (rec); field; field = TREE_CHAIN (field))
  507.     {
  508.       layout_decl (field, 0);
  509.       DECL_OFFSET (field) = 0;
  510.       DECL_VOFFSET (field) = 0;
  511.       DECL_VOFFSET_UNIT (field) = BITS_PER_UNIT;
  512.  
  513.       /* Union must be at least as aligned as any field requires.  */
  514.  
  515.       union_align = MAX (union_align, DECL_ALIGN (field));
  516.  
  517.       /* Set union_size to max (decl_size, union_size).
  518.      There are more and less general ways to do this.
  519.      Use only CONST_SIZE unless forced to use VAR_SIZE.  */
  520.  
  521.       if (TREE_LITERAL (DECL_SIZE (field)))
  522.     const_size = MAX (const_size,
  523.               TREE_INT_CST_LOW (DECL_SIZE (field))
  524.               * DECL_SIZE_UNIT (field));
  525.       else if (var_size == 0)
  526.     var_size = convert_units (DECL_SIZE (field),
  527.                   DECL_SIZE_UNIT (field),
  528.                   BITS_PER_UNIT);
  529.       else
  530.     var_size = genop (MAX_EXPR,
  531.               convert_units (DECL_SIZE (field),
  532.                      DECL_SIZE_UNIT (field),
  533.                      BITS_PER_UNIT),
  534.               var_size);
  535.     }
  536.  
  537.   /* Determine the ultimate size of the union (in bytes).  */
  538.   if (NULL == var_size)
  539.     TYPE_SIZE (rec) = build_int (CEIL (const_size, BITS_PER_UNIT));
  540.   else if (const_size == 0)
  541.     TYPE_SIZE (rec) = var_size;
  542.   else
  543.     TYPE_SIZE (rec) = genop (MAX_EXPR, var_size,
  544.                  build_int (CEIL (const_size, BITS_PER_UNIT)));
  545.  
  546.   /* Determine the desired alignment.  */
  547.   union_align = MIN (BIGGEST_ALIGNMENT, union_align);
  548.   TYPE_ALIGN (rec) = MAX (TYPE_ALIGN (rec), union_align);
  549.  
  550.   /* Round the size up to be a multiple of the required alignment */
  551.   TYPE_SIZE (rec)
  552.     = convert_units (TYPE_SIZE (rec), BITS_PER_UNIT, TYPE_ALIGN (rec));
  553.   TYPE_SIZE_UNIT (rec) = TYPE_ALIGN (rec);
  554. }
  555.  
  556. /* Calculate the mode, size, and alignment for TYPE.
  557.    For an array type, calculate the element separation as well.
  558.    Record TYPE on the chain of permanent or temporary types
  559.    so that dbxout will find out about it.
  560.  
  561.    TYPE_SIZE of a type is nonzero if the type has been laid out already.
  562.    layout_type does nothing on such a type.
  563.  
  564.    If the type is incomplete, its TYPE_SIZE remains zero.  */
  565.  
  566. void
  567. layout_type (type)
  568.      tree type;
  569. {
  570.   int old;
  571.  
  572.   if (type == 0)
  573.     abort ();
  574.  
  575.   /* Do nothing if type has been laid out before.  */
  576.   if (TYPE_SIZE (type))
  577.     return;
  578.  
  579.   /* Make sure all nodes we allocate are not momentary;
  580.      they must last past the current statement.  */
  581.   old  = suspend_momentary ();
  582.  
  583.   chain_type (type);
  584.  
  585.   switch (TREE_CODE (type))
  586.     {
  587.     case VOID_TYPE:
  588.       TYPE_SIZE (type) = size_zero_node;
  589.       TYPE_SIZE_UNIT (type) = BITS_PER_UNIT;
  590.       TYPE_ALIGN (type) = 1;
  591.       TYPE_MODE (type) = VOIDmode;
  592.       break;
  593.  
  594.     case INTEGER_TYPE:
  595.     case ENUMERAL_TYPE:
  596.       if (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (type)) >= 0)
  597.     TREE_UNSIGNED (type) = 1;
  598.  
  599.       TYPE_MODE (type) = agg_mode (TYPE_PRECISION (type));
  600.       TYPE_SIZE (type) = build_int (GET_MODE_SIZE (TYPE_MODE (type)));
  601.       TYPE_SIZE_UNIT (type) = BITS_PER_UNIT;
  602.       TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
  603.       break;
  604.  
  605.     case REAL_TYPE:
  606.       {
  607.     register int prec = TYPE_PRECISION (type);
  608.     if (prec <= GET_MODE_BITSIZE (SFmode))
  609.       TYPE_MODE (type) = SFmode;
  610.     else if (prec <= GET_MODE_BITSIZE (DFmode))
  611.       TYPE_MODE (type) = DFmode;
  612.     else
  613.       abort ();
  614.       }
  615.       TYPE_SIZE (type) = build_int (GET_MODE_SIZE (TYPE_MODE (type)));
  616.       TYPE_SIZE_UNIT (type) = BITS_PER_UNIT;
  617.       TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
  618.       break;
  619.  
  620.     case POINTER_TYPE:
  621.       TYPE_MODE (type) = Pmode;
  622.       TYPE_SIZE (type) = build_int (POINTER_SIZE / BITS_PER_UNIT);
  623.       TYPE_SIZE_UNIT (type) = BITS_PER_UNIT;
  624.       TYPE_ALIGN (type) = POINTER_BOUNDARY;
  625.       TREE_UNSIGNED (type) = 1;
  626.       TYPE_PRECISION (type) = POINTER_SIZE;
  627.       break;
  628.  
  629.     case ARRAY_TYPE:
  630.       {
  631.     register tree index = TYPE_DOMAIN (type);
  632.     register tree length;
  633.     register tree element = TREE_TYPE (type);
  634.  
  635. /*     layout_type (element);  */
  636.     build_pointer_type (element);
  637.  
  638.     if (index == 0)
  639.       length = 0;
  640.     else
  641.       length = genop (PLUS_EXPR, size_one_node,
  642.               genop (MINUS_EXPR, TYPE_MAX_VALUE (index),
  643.                  TYPE_MIN_VALUE (index)));
  644.  
  645.     if (TREE_PACKED (type))
  646.       abort ();  /* ??? Not written yet since not needed for C.  */
  647.  
  648.     TYPE_SIZE_UNIT (type) = TYPE_SIZE_UNIT (element);
  649.     if (length && TYPE_SIZE (element))
  650.       TYPE_SIZE (type) = genop (MULT_EXPR, TYPE_SIZE (element), length);
  651.     TYPE_SEP (type) = TYPE_SIZE (element);
  652.     TYPE_SEP_UNIT (type) = TYPE_SIZE_UNIT (element);
  653.     TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT);
  654.     TYPE_MODE (type) = BLKmode;
  655.     if (TYPE_SIZE (type) != 0
  656.         && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
  657.       {
  658.         TYPE_MODE (type) 
  659.           = agg_mode (TREE_INT_CST_LOW (TYPE_SIZE (type))
  660.               * TYPE_SIZE_UNIT (type));
  661.       }
  662.     break;
  663.       }
  664.  
  665.     case RECORD_TYPE:
  666.       layout_record (type);
  667.       TYPE_MODE (type) = BLKmode;
  668.       if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
  669.     {
  670.       tree field;
  671.       /* A record which has any BLKmode members must itself be BLKmode;
  672.          it can't go in a register.  */
  673.       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  674.         if (TYPE_MODE (TREE_TYPE (field)) == BLKmode)
  675.           goto record_lose;
  676.  
  677.       TYPE_MODE (type) 
  678.         = agg_mode (TREE_INT_CST_LOW (TYPE_SIZE (type))
  679.             * TYPE_SIZE_UNIT (type));
  680.     record_lose: ;
  681.     }
  682.       break;
  683.  
  684.     case UNION_TYPE:
  685.       layout_union (type);
  686.       TYPE_MODE (type) = BLKmode;
  687.       if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
  688.     {
  689.       tree field;
  690.       /* A union which has any BLKmode members must itself be BLKmode;
  691.          it can't go in a register.  */
  692.       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  693.         if (TYPE_MODE (TREE_TYPE (field)) == BLKmode)
  694.           goto union_lose;
  695.  
  696.       TYPE_MODE (type) 
  697.         = agg_mode (TREE_INT_CST_LOW (TYPE_SIZE (type))
  698.             * TYPE_SIZE_UNIT (type));
  699.     union_lose: ;
  700.     }
  701.       break;
  702.  
  703.     case FUNCTION_TYPE:
  704.       TYPE_MODE (type) = EPmode;
  705.       TYPE_SIZE (type) = build_int (2 * POINTER_SIZE / BITS_PER_UNIT);
  706.       TYPE_SIZE_UNIT (type) = BITS_PER_UNIT;
  707.       TYPE_ALIGN (type) = POINTER_BOUNDARY;
  708.       break;
  709.  
  710.     default:
  711.       abort ();
  712.     } /* end switch */
  713.  
  714.   /* Evaluate nonconstant size only once, either now or as soon as safe.  */
  715.   if (TYPE_SIZE (type) != 0 && ! TREE_LITERAL (TYPE_SIZE (type)))
  716.     TYPE_SIZE (type) = variable_size (TYPE_SIZE (type));
  717.     
  718.   resume_momentary (old);
  719. }
  720.  
  721. /* Create and return a type for signed integers of PRECISION bits.  */
  722.  
  723. tree
  724. make_signed_type (precision)
  725.      int precision;
  726. {
  727.   register tree type = make_node (INTEGER_TYPE);
  728.  
  729.   TYPE_PRECISION (type) = precision;
  730.  
  731.   /* Create the extreme values based on the number of bits.  */
  732.  
  733.   TYPE_MIN_VALUE (type)
  734.     = build_int_2 ((precision-BITS_PER_WORD > 0 ? 0 : (-1)<<(precision-1)),
  735.            (-1)<<(precision-BITS_PER_WORD-1 > 0
  736.               ? precision-BITS_PER_WORD-1
  737.               : 0));
  738.   TYPE_MAX_VALUE (type)
  739.     = build_int_2 ((precision-BITS_PER_WORD > 0 ? -1 : (1<<(precision-1))-1),
  740.            (precision-BITS_PER_WORD-1 > 0
  741.             ? (1<<(precision-BITS_PER_WORD-1))-1
  742.             : 0));
  743.  
  744.   /* Give this type's extreme values this type as their type.  */
  745.  
  746.   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
  747.   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
  748.  
  749.   /* The first type made with this or `make_unsigned_type'
  750.      is the type for size values.  */
  751.  
  752.   if (sizetype == 0)
  753.     sizetype = type;
  754.  
  755.   /* Lay out the type: set its alignment, size, etc.  */
  756.  
  757.   layout_type (type);
  758.  
  759.   return type;
  760. }
  761.  
  762. /* Create and return a type for unsigned integers of PRECISION bits.  */
  763.  
  764. tree
  765. make_unsigned_type (precision)
  766.      int precision;
  767. {
  768.   register tree type = make_node (INTEGER_TYPE);
  769.   register tree low, high;
  770.  
  771.   TYPE_PRECISION (type) = precision;
  772.  
  773.   /* The first type made with this or `make_unsigned_type'
  774.      is the type for size values.  */
  775.  
  776.   if (sizetype == 0)
  777.     sizetype = type;
  778.  
  779.   fixup_unsigned_type (type);
  780.   return type;
  781. }
  782.  
  783. /* Set the extreme values of TYPE based on its precision in bits,
  784.    the lay it out.  This is used both in `make_unsigned_type'
  785.    and for enumeral types.  */
  786.  
  787. void
  788. fixup_unsigned_type (type)
  789.      tree type;
  790. {
  791.   register int precision = TYPE_PRECISION (type);
  792.  
  793.   TYPE_MIN_VALUE (type) = build_int_2 (0, 0);
  794.   TYPE_MAX_VALUE (type)
  795.     = build_int_2 (precision-BITS_PER_WORD >= 0 ? -1 : (1<<precision)-1,
  796.            precision-BITS_PER_WORD > 0
  797.            ? (1<<(precision-BITS_PER_WORD))-1 : 0);
  798.   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
  799.   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
  800.  
  801.   /* Lay out the type: set its alignment, size, etc.  */
  802.  
  803.   layout_type (type);
  804. }
  805.