Commit f2704b9f by Richard Kenner Committed by Richard Kenner

stor-layout.c (bit_from_pos, [...]): New functions.

	* 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.

From-SVN: r32813
parent 2e3120e8
Wed Mar 29 15:39:10 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* 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.
2000-03-29 Nick Clifton <nickc@cygnus.com> 2000-03-29 Nick Clifton <nickc@cygnus.com>
* config/arm/arm.c: Minor formatting changes/ * config/arm/arm.c: Minor formatting changes/
......
...@@ -433,6 +433,86 @@ start_record_layout (t) ...@@ -433,6 +433,86 @@ start_record_layout (t)
return rli; 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. */ /* Print debugging information about the information in RLI. */
void void
...@@ -462,22 +542,7 @@ void ...@@ -462,22 +542,7 @@ void
normalize_rli (rli) normalize_rli (rli)
record_layout_info rli; record_layout_info rli;
{ {
/* If the bit position is now larger than it should be, adjust it normalize_offset (&rli->offset, &rli->bitpos, rli->offset_align);
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));
}
} }
/* Returns the size in bytes allocated so far. */ /* Returns the size in bytes allocated so far. */
...@@ -486,10 +551,7 @@ tree ...@@ -486,10 +551,7 @@ tree
rli_size_unit_so_far (rli) rli_size_unit_so_far (rli)
record_layout_info rli; record_layout_info rli;
{ {
return size_binop (PLUS_EXPR, rli->offset, return byte_from_pos (rli->offset, rli->bitpos);
convert (sizetype,
size_binop (CEIL_DIV_EXPR, rli->bitpos,
bitsize_unit_node)));
} }
/* Returns the size in bits allocated so far. */ /* Returns the size in bits allocated so far. */
...@@ -498,9 +560,7 @@ tree ...@@ -498,9 +560,7 @@ tree
rli_size_so_far (rli) rli_size_so_far (rli)
record_layout_info rli; record_layout_info rli;
{ {
return size_binop (PLUS_EXPR, rli->bitpos, return bit_from_pos (rli->offset, rli->bitpos);
size_binop (MULT_EXPR, convert (bitsizetype, rli->offset),
bitsize_unit_node));
} }
/* Called from place_field to handle unions. */ /* Called from place_field to handle unions. */
......
...@@ -2321,11 +2321,9 @@ tree ...@@ -2321,11 +2321,9 @@ tree
bit_position (field) bit_position (field)
tree field; tree field;
{ {
return size_binop (PLUS_EXPR, DECL_FIELD_BIT_OFFSET (field),
size_binop (MULT_EXPR, return bit_from_pos (DECL_FIELD_OFFSET (field),
convert (bitsizetype, DECL_FIELD_BIT_OFFSET (field));
DECL_FIELD_OFFSET (field)),
bitsize_unit_node));
} }
/* Likewise, but return as an integer. Abort if it cannot be represented /* Likewise, but return as an integer. Abort if it cannot be represented
...@@ -2346,11 +2344,8 @@ tree ...@@ -2346,11 +2344,8 @@ tree
byte_position (field) byte_position (field)
tree field; tree field;
{ {
return size_binop (PLUS_EXPR, DECL_FIELD_OFFSET (field), return byte_from_pos (DECL_FIELD_OFFSET (field),
convert (sizetype, DECL_FIELD_BIT_OFFSET (field));
size_binop (FLOOR_DIV_EXPR,
DECL_FIELD_BIT_OFFSET (field),
bitsize_unit_node)));
} }
/* Likewise, but return as an integer. Abort if it cannot be represented /* Likewise, but return as an integer. Abort if it cannot be represented
......
...@@ -1802,6 +1802,14 @@ typedef struct record_layout_info ...@@ -1802,6 +1802,14 @@ typedef struct record_layout_info
} *record_layout_info; } *record_layout_info;
extern record_layout_info start_record_layout PARAMS ((tree)); extern record_layout_info start_record_layout PARAMS ((tree));
extern tree bit_from_pos PARAMS ((tree, tree));
extern tree byte_from_pos PARAMS ((tree, tree));
extern void pos_from_byte PARAMS ((tree *, tree *, unsigned int,
tree));
extern void pos_from_bit PARAMS ((tree *, tree *, unsigned int,
tree));
extern void normalize_offset PARAMS ((tree *, tree *,
unsigned int));
extern tree rli_size_unit_so_far PARAMS ((record_layout_info)); extern tree rli_size_unit_so_far PARAMS ((record_layout_info));
extern tree rli_size_so_far PARAMS ((record_layout_info)); extern tree rli_size_so_far PARAMS ((record_layout_info));
extern void normalize_rli PARAMS ((record_layout_info)); extern void normalize_rli PARAMS ((record_layout_info));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment