stor-layout.c (set_alignment): New global.
authorPer Bothner <bothner@gcc.gnu.org>
Thu, 1 Sep 1994 00:15:03 +0000 (17:15 -0700)
committerPer Bothner <bothner@gcc.gnu.org>
Thu, 1 Sep 1994 00:15:03 +0000 (17:15 -0700)
* stor-layout.c (set_alignment):  New global.
(layout-type):  Add support for SET_TYPE.

From-SVN: r8010

gcc/stor-layout.c

index d2c6f2824f98264d2679af8f00e6d79770c4c56b..9fdc65100d63f35811cf7c9850703a186ebb550b 100644 (file)
@@ -44,6 +44,10 @@ tree size_one_node;
    The value is measured in bits.  */
 int maximum_field_alignment;
 
+/* If non-zero, the alignment of a bitsting or (power-)set value, in bits.
+   May be overridden by front-ends.  */
+int set_alignment = 0;
+
 #define GET_MODE_ALIGNMENT(MODE)   \
   MIN (BIGGEST_ALIGNMENT,         \
        MAX (1, (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT)))
@@ -898,6 +902,31 @@ layout_type (type)
       TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
       break;
 
+    case SET_TYPE:
+      if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST
+         || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST)
+       abort();
+      else
+       {
+#ifndef SET_WORD_SIZE
+#define SET_WORD_SIZE BITS_PER_WORD
+#endif
+         int alignment = set_alignment ? set_alignment : SET_WORD_SIZE;
+         int size_in_bits =
+           TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
+             - TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1;
+         int rounded_size
+           = ((size_in_bits + alignment - 1) / alignment) * alignment;
+         if (rounded_size > alignment)
+           TYPE_MODE (type) = BLKmode;
+         else
+           TYPE_MODE (type) = mode_for_size (alignment, MODE_INT, 1);
+         TYPE_SIZE (type) = size_int (rounded_size);
+         TYPE_ALIGN (type) = alignment;
+         TYPE_PRECISION (type) = size_in_bits;
+       }
+      break;
+
     case FILE_TYPE:
       /* The size may vary in different languages, so the language front end
         should fill in the size.  */