summaryrefslogtreecommitdiff
path: root/gcc/stor-layout.c
diff options
context:
space:
mode:
authorkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-29 20:34:34 +0000
committerkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-29 20:34:34 +0000
commit6d731e4def9f9f9b3cb2d8621092c7655d1b7435 (patch)
tree113b51730f955c5321c5845dfbce388eaf91bb66 /gcc/stor-layout.c
parent4876fb4ef3c21d6d7898059cea6225a9cbf5ffef (diff)
downloadgcc-6d731e4def9f9f9b3cb2d8621092c7655d1b7435.tar.gz
* stor-layout.c (bit_from_pos, byte_from_pos): New functions.
(pos_from_byte, pos_from_bit, normalize_offset): Likewise. (normalize_rli, rli_size_so_far, rli_size_unit_so_far): Use them. * tree.c (bit_position, byte_position): Likewise. * tree.h: Declare new functions. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@32813 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/stor-layout.c')
-rw-r--r--gcc/stor-layout.c106
1 files changed, 83 insertions, 23 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 7621e61508e..966945fe9a2 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -433,6 +433,86 @@ start_record_layout (t)
return rli;
}
+/* These four routines perform computations that convert between
+ the offset/bitpos forms and byte and bit offsets. */
+
+tree
+bit_from_pos (offset, bitpos)
+ tree offset, bitpos;
+{
+ return size_binop (PLUS_EXPR, bitpos,
+ size_binop (MULT_EXPR, convert (bitsizetype, offset),
+ bitsize_unit_node));
+}
+
+tree
+byte_from_pos (offset, bitpos)
+ tree offset, bitpos;
+{
+ return size_binop (PLUS_EXPR, offset,
+ convert (sizetype,
+ size_binop (CEIL_DIV_EXPR, bitpos,
+ bitsize_unit_node)));
+}
+
+void
+pos_from_byte (poffset, pbitpos, off_align, pos)
+ tree *poffset, *pbitpos;
+ unsigned int off_align;
+ tree pos;
+{
+ *poffset
+ = size_binop (MULT_EXPR,
+ convert (sizetype,
+ size_binop (FLOOR_DIV_EXPR, pos,
+ bitsize_int (off_align
+ / BITS_PER_UNIT))),
+ size_int (off_align / BITS_PER_UNIT));
+ *pbitpos = size_binop (MULT_EXPR,
+ size_binop (FLOOR_MOD_EXPR, pos,
+ bitsize_int (off_align / BITS_PER_UNIT)),
+ bitsize_unit_node);
+}
+
+void
+pos_from_bit (poffset, pbitpos, off_align, pos)
+ tree *poffset, *pbitpos;
+ unsigned int off_align;
+ tree pos;
+{
+ *poffset = size_binop (MULT_EXPR,
+ convert (sizetype,
+ size_binop (FLOOR_DIV_EXPR, pos,
+ bitsize_int (off_align))),
+ size_int (off_align / BITS_PER_UNIT));
+ *pbitpos = size_binop (FLOOR_MOD_EXPR, pos, bitsize_int (off_align));
+}
+
+/* Given a pointer to bit and byte offsets and an offset alignment,
+ normalize the offsets so they are within the alignment. */
+
+void
+normalize_offset (poffset, pbitpos, off_align)
+ tree *poffset, *pbitpos;
+ unsigned int off_align;
+{
+ /* If the bit position is now larger than it should be, adjust it
+ downwards. */
+ if (compare_tree_int (*pbitpos, off_align) >= 0)
+ {
+ tree extra_aligns = size_binop (FLOOR_DIV_EXPR, *pbitpos,
+ bitsize_int (off_align));
+
+ *poffset
+ = size_binop (PLUS_EXPR, *poffset,
+ size_binop (MULT_EXPR, convert (sizetype, extra_aligns),
+ size_int (off_align / BITS_PER_UNIT)));
+
+ *pbitpos
+ = size_binop (FLOOR_MOD_EXPR, *pbitpos, bitsize_int (off_align));
+ }
+}
+
/* Print debugging information about the information in RLI. */
void
@@ -462,22 +542,7 @@ void
normalize_rli (rli)
record_layout_info rli;
{
- /* If the bit position is now larger than it should be, adjust it
- downwards. */
- if (compare_tree_int (rli->bitpos, rli->offset_align) >= 0)
- {
- tree extra_aligns = size_binop (FLOOR_DIV_EXPR, rli->bitpos,
- bitsize_int (rli->offset_align));
-
- rli->offset
- = size_binop (PLUS_EXPR, rli->offset,
- size_binop (MULT_EXPR, convert (sizetype, extra_aligns),
- size_int (rli->offset_align
- / BITS_PER_UNIT)));
-
- rli->bitpos = size_binop (FLOOR_MOD_EXPR, rli->bitpos,
- bitsize_int (rli->offset_align));
- }
+ normalize_offset (&rli->offset, &rli->bitpos, rli->offset_align);
}
/* Returns the size in bytes allocated so far. */
@@ -486,10 +551,7 @@ tree
rli_size_unit_so_far (rli)
record_layout_info rli;
{
- return size_binop (PLUS_EXPR, rli->offset,
- convert (sizetype,
- size_binop (CEIL_DIV_EXPR, rli->bitpos,
- bitsize_unit_node)));
+ return byte_from_pos (rli->offset, rli->bitpos);
}
/* Returns the size in bits allocated so far. */
@@ -498,9 +560,7 @@ tree
rli_size_so_far (rli)
record_layout_info rli;
{
- return size_binop (PLUS_EXPR, rli->bitpos,
- size_binop (MULT_EXPR, convert (bitsizetype, rli->offset),
- bitsize_unit_node));
+ return bit_from_pos (rli->offset, rli->bitpos);
}
/* Called from place_field to handle unions. */