From: Stephen Leake <Stephe.Leake@nasa.gov>
To: comp.lang.ada@ada-france.org
Subject: Re: Endian-Independent Rep Clauses
Date: 26 Jan 2004 21:01:18 -0500
Date: 2004-01-26T21:01:18-05:00 [thread overview]
Message-ID: <mailman.29.1075168937.2270.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <L8CdnXVgkvVGJYjdRVn-tA@comcast.com>
"Robert I. Eachus" <rieachus@comcast.net> writes:
> Jeffrey Carter wrote:
>
> > IIRC, it addresses the fact that Default_Bit_Order is static, thanks
> > to an AI, and uses static universal math based on Boolean'Pos
> > (Default_Bit_Order = <one_of_the_choices>) to calculate bit
> > positions. I've done this kind of thing; it requires long
> > expressions for bit numbers, but works fine.
>
> Not really, just declare:
>
> Bits: constant := System.Bit_Order'Pos(System.Default_Bit_Order);
>
> then go on from there.
Here's a real-life example:
package SAL.Endianness is
Bit_Order : constant := 1; -- 1 or -1
High_Bit_First : constant := 0; -- 0 or 1
Low_Bit_First : constant := 1; -- opposite of High_Bit_First
-- Use one of these, corresponding to the natural size of the
-- record you are laying out.
LSBit_8 : constant := High_Bit_First * 7;
LSBit_16 : constant := High_Bit_First * 15;
LSBit_24 : constant := High_Bit_First * 23;
LSBit_32 : constant := High_Bit_First * 31;
LSBit_56 : constant := High_Bit_First * 55;
end SAL.Endianness;
with SAL.Endianness; use SAL.Endianness;
package body DA.Digital is
type Analog_Collection_Mode_Type is record
Spare_1 : Interfaces_More.Unsigned_30;
Data : Interfaces_More.Unsigned_2;
end record;
for Analog_Collection_Mode_Type use record
Spare_1 at 0 range
Low_Bit_First * (LSBit_32 + Bit_Order * 2) + High_Bit_First * (LSBit_32 + Bit_Order * 31) ..
High_Bit_First * (LSBit_32 + Bit_Order * 2) + Low_Bit_First * (LSBit_32 + Bit_Order * 31);
Data at 0 range
Low_Bit_First * (LSBit_32 + Bit_Order * 0) + High_Bit_First * (LSBit_32 + Bit_Order * 1) ..
High_Bit_First * (LSBit_32 + Bit_Order * 0) + Low_Bit_First * (LSBit_32 + Bit_Order * 1);
end record;
for Analog_Collection_Mode_Type'Size use 32;
...
end DA.Digital;
There is probably a way to improve the SAL.Endianness package, so I
don't need more than one. I was unable to find a smaller expression
for the rep clauses.
--
-- Stephe
next prev parent reply other threads:[~2004-01-27 2:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-26 13:30 Standard Ada Preprocessor Lionel.DRAGHI
2004-01-26 16:10 ` Robert I. Eachus
2004-01-26 19:20 ` Endian-Independent Rep Clauses (was: Standard Ada Preprocessor) Jeffrey Carter
2004-01-27 1:03 ` Endian-Independent Rep Clauses Robert I. Eachus
2004-01-27 2:01 ` Stephen Leake [this message]
2004-01-27 3:16 ` Robert I. Eachus
2004-01-27 8:10 ` Stephen Leake
2004-01-27 3:34 ` Jeffrey Carter
2004-01-27 8:14 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox