From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,38159b1b5557a2e7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-01-26 18:14:53 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Endian-Independent Rep Clauses Date: 26 Jan 2004 21:01:18 -0500 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1075168939 76704 80.67.180.195 (27 Jan 2004 02:02:19 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 27 Jan 2004 02:02:19 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.3 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:4865 Date: 2004-01-26T21:01:18-05:00 "Robert I. Eachus" 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 = ) 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