comp.lang.ada
 help / color / mirror / Atom feed
* Converting application from BIG ENDIAN to LITTLE ENDIAN machine
@ 2004-04-23 15:50 Claude Riendeau
  2004-04-23 17:16 ` Jean-Pierre Rosen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Claude Riendeau @ 2004-04-23 15:50 UTC (permalink / raw)


Hello

I'm new to ADA and this is probably a classical.

I have to have this large application that was programmed for a BIG
ENDIAN machine to run on a LITTLE ENDIAN machine.  I need to reorder
all the records BIT definitions (at 0 range 3 .. 12), and I have
10000+ lines of code to convert.  I'd like to automate this.

I planned to parse the source code and reorder the BIT fields myself,
but most of them contains constants, sizeof statements and
mathematical operations.  I wondered if it would be possible to stop
the ADA compiler in mid course where the compiler definitions would be
resolved, parse the intermediate file with my BIT reordering
application, than let the compiler continue its job.  This would be
like modifying a C preprocessor output.

I use RATIONAL ADA WINDOWS compiler.  Does someone knows how to have
this compiler generate intermediate files?

Does someone has a better approach to this problem?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Converting application from BIG ENDIAN to LITTLE ENDIAN machine
  2004-04-23 15:50 Converting application from BIG ENDIAN to LITTLE ENDIAN machine Claude Riendeau
@ 2004-04-23 17:16 ` Jean-Pierre Rosen
  2004-04-23 18:59 ` Jacob Sparre Andersen
  2004-04-23 21:49 ` Stephen Leake
  2 siblings, 0 replies; 5+ messages in thread
From: Jean-Pierre Rosen @ 2004-04-23 17:16 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 700 bytes --]


"Claude Riendeau" <claude.riendeau@cae.com> a �crit dans le message de news:89219f7f.0404230750.12f64b28@posting.google.com...
> I planned to parse the source code and reorder the BIT fields myself,
[Snip]
> Does someone has a better approach to this problem?
Of course :-)
Have a look at ASIS.
If you want an example about how to use it, together with many helpful utilities for writing an Ada text transformation program,
have a look at Adasubst/Adadep from Adalog's components page: http://www.adalog.fr/compo2.htm

(OK, it was a plug :-)

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Converting application from BIG ENDIAN to LITTLE ENDIAN machine
  2004-04-23 15:50 Converting application from BIG ENDIAN to LITTLE ENDIAN machine Claude Riendeau
  2004-04-23 17:16 ` Jean-Pierre Rosen
@ 2004-04-23 18:59 ` Jacob Sparre Andersen
  2004-04-23 21:42   ` Stephen Leake
  2004-04-23 21:49 ` Stephen Leake
  2 siblings, 1 reply; 5+ messages in thread
From: Jacob Sparre Andersen @ 2004-04-23 18:59 UTC (permalink / raw)


Claude Riendeau wrote:

> I'm new to ADA and this is probably a classical.

Writing Ada "Ada" and not "ADA" would have concealed this a bit. :-)

> I have to have this large application that was programmed for a BIG
> ENDIAN machine to run on a LITTLE ENDIAN machine.  I need to reorder
> all the records BIT definitions (at 0 range 3 .. 12), and I have
> 10000+ lines of code to convert.  I'd like to automate this.

Have you considered simply to use "Bit_Order" to handle this?  Take a
look at chapter 13 in the Ada Reference Manual for a formal
description of how it works.

Jacob
-- 
from DoD Directive 2000.12

"DEFINITIONS
(...)
 18. Terrorism.  The calculated use of violence or threat of
 violence to inculcate fear; intended to coerce or to
 intimidate governments or societies in the pursuit of goals
 that are generally political, religious, or ideological."



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Converting application from BIG ENDIAN to LITTLE ENDIAN machine
  2004-04-23 18:59 ` Jacob Sparre Andersen
@ 2004-04-23 21:42   ` Stephen Leake
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2004-04-23 21:42 UTC (permalink / raw)
  To: comp.lang.ada

Jacob Sparre Andersen <sparre@nbi.dk> writes:

> Claude Riendeau wrote:
> > I have to have this large application that was programmed for a BIG
> > ENDIAN machine to run on a LITTLE ENDIAN machine.  I need to reorder
> > all the records BIT definitions (at 0 range 3 .. 12), and I have
> > 10000+ lines of code to convert.  I'd like to automate this.
> 
> Have you considered simply to use "Bit_Order" to handle this?  Take a
> look at chapter 13 in the Ada Reference Manual for a formal
> description of how it works.

Be sure to ask your compiler if it supports this usage, first! Many do not.

-- 
-- Stephe




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Converting application from BIG ENDIAN to LITTLE ENDIAN machine
  2004-04-23 15:50 Converting application from BIG ENDIAN to LITTLE ENDIAN machine Claude Riendeau
  2004-04-23 17:16 ` Jean-Pierre Rosen
  2004-04-23 18:59 ` Jacob Sparre Andersen
@ 2004-04-23 21:49 ` Stephen Leake
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2004-04-23 21:49 UTC (permalink / raw)
  To: comp.lang.ada

claude.riendeau@cae.com (Claude Riendeau) writes:

> Hello
> 
> I'm new to ADA and this is probably a classical.
> 
> I have to have this large application that was programmed for a BIG
> ENDIAN machine to run on a LITTLE ENDIAN machine.  I need to reorder
> all the records BIT definitions (at 0 range 3 .. 12), and I have
> 10000+ lines of code to convert.  I'd like to automate this.

While you are at it, use an endian-independent format, as supported by
SAL.Endianness (below)

> I planned to parse the source code and reorder the BIT fields
> myself, but most of them contains constants, sizeof statements and
> mathematical operations. 

As someone else suggested, use ASIS. See
http://www.toadmail.com/~ada_wizard/ada/auto_text_io.html for ASIST
code that manipulates records. You need record representation clauses,
but that should be similar.

> I use RATIONAL ADA WINDOWS compiler.  Does someone knows how to have
> this compiler generate intermediate files?

You could also compile with GNAT, and use the debug switches -gnatd or
-gnatG; that may help.

-- 
-- Stephe

--  Abstract :
--
--  Define constants to reflect hardware bit and word endianness in
--  record representation clauses. Obviously, this file is highly
--  system-dependent.
--
--  Copyright (C) 2004 Stephen Leake.  All Rights Reserved.
--
--  This library is free software; you can redistribute it and/or
--  modify it under terms of the GNU General Public License as
--  published by the Free Software Foundation; either version 2, or (at
--  your option) any later version. This library is distributed in the
--  hope that it will be useful, but WITHOUT ANY WARRANTY; without even
--  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
--  PURPOSE. See the GNU General Public License for more details. You
--  should have received a copy of the GNU General Public License
--  distributed with this program; see file COPYING. If not, write to
--  the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
--  MA 02111-1307, USA.
--
--  As a special exception, if other files instantiate generics from
--  this unit, or you link this unit with other files to produce an
--  executable, this  unit  does not  by itself cause  the resulting
--  executable to be covered by the GNU General Public License. This
--  exception does not however invalidate any other reasons why the
--  executable file  might be covered by the  GNU Public License.

pragma License (Modified_GPL);

with System;
package SAL.Endianness is
   pragma Pure;

   -- this is for gnat on an Intel 386 compatible processor
   System_Name : constant System.Name := System.SYSTEM_NAME_GNAT;

   type Byte_Order_Type is (Big_Endian, Little_Endian);
   Byte_Order : constant Byte_Order_Type := Little_Endian;

   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 :=  0; -- 0 or  7
   LSBit_16       : constant :=  0; -- 0 or 15
   LSBit_32       : constant :=  0; -- 0 or 31
   LSBit_56       : constant :=  0; -- 0 or 55

   --  If the bit numbers are correct for Low_Bit_First = 1, use these
   --  patterns:
   --
   --     type Thruster_Pulse_Activation_Type is record
   --        --  [1] Table 4.5.2.5
   --        Pulse_Activation : Boolean;
   --        Spare            : Interfaces_More.Unsigned_31;
   --     end record;
   --     for Thruster_Pulse_Activation_Type use record
   --        Pulse_Activation at 0 range LSBit_32 + Bit_Order * 0 .. LSBit_32 + Bit_Order * 0;
   --        Spare            at 0 range
   --           Low_Bit_First  * (LSBit_32 + Bit_Order * 1) + High_Bit_First * (LSBit_32 + Bit_Order * 31) ..
   --           High_Bit_First * (LSBit_32 + Bit_Order * 1) + Low_Bit_First  * (LSBit_32 + Bit_Order * 31);
   --     end record;
   --     for Thruster_Pulse_Activation_Type'Size use 32;

   --     type VEC_Analog_Collection_Status_Type is record
   --        MUX_Channel               : Interfaces_More.Unsigned_4;
   --        Spare_2                   : Interfaces_More.Unsigned_3;
   --        Analog_Collection_Running : Boolean;
   --     end record;
   --
   --     for VEC_Analog_Collection_Status_Type use record
   --        MUX_Channel               at 0 range
   --           Low_Bit_First  * (LSBit_8 + Bit_Order *  4) + High_Bit_First * (LSBit_8 + Bit_Order *  7) ..
   --           High_Bit_First * (LSBit_8 + Bit_Order *  4) + Low_Bit_First  * (LSBit_8 + Bit_Order *  7);
   --
   --        Spare_2                   at 0 range
   --           Low_Bit_First  * (LSBit_8 + Bit_Order *  1) + High_Bit_First * (LSBit_8 + Bit_Order *  3) ..
   --           High_Bit_First * (LSBit_8 + Bit_Order *  1) + Low_Bit_First  * (LSBit_8 + Bit_Order *  3);
   --
   --        Analog_Collection_Running at 0 range LSBit_8 + Bit_Order * 0 .. LSBit_8 + Bit_Order * 0;
   --     end record;
   --     for VEC_Analog_Collection_Status_Type'Size use 8;

   --     type Packed_Raw_Data_Type is record
   --        Channel_1      : Interfaces_More.Signed_17;
   --        Channel_2      : Interfaces_More.Signed_17;
   --        Channel_3      : Interfaces_More.Signed_17;
   --        ADC_Reset      : Boolean;
   --        Selected_Range : Range_Type; -- 'range' is a reserved word.
   --        Spare          : Interfaces_More.Unsigned_3;
   --     end record;
   --     for Packed_Raw_Data_Type use record
   --        Channel_1 at 0 range
   --           Low_Bit_First  * (LSBit_56 + Bit_Order *  0) + High_Bit_First * (LSBit_56 + Bit_Order * 16) ..
   --           High_Bit_First * (LSBit_56 + Bit_Order *  0) + Low_Bit_First  * (LSBit_56 + Bit_Order * 16);
   --
   --        Channel_2 at 0 range
   --           Low_Bit_First  * (LSBit_56 + Bit_Order * 17) + High_Bit_First * (LSBit_56 + Bit_Order * 33) ..
   --           High_Bit_First * (LSBit_56 + Bit_Order * 17) + Low_Bit_First  * (LSBit_56 + Bit_Order * 33);
   --
   --        Channel_3  at 0 range
   --           Low_Bit_First  * (LSBit_56 + Bit_Order * 34) + High_Bit_First * (LSBit_56 + Bit_Order * 50) ..
   --           High_Bit_First * (LSBit_56 + Bit_Order * 34) + Low_Bit_First  * (LSBit_56 + Bit_Order * 50);
   --
   --        Selected_Range at 0 range LSBit_56 + Bit_Order * 51 .. LSBit_56 + Bit_Order * 51;
   --        ADC_Reset      at 0 range LSBit_56 + Bit_Order * 52 .. LSBit_56 + Bit_Order * 52;
   --
   --        Spare at 0 range
   --           Low_Bit_First  * (LSBit_56 + Bit_Order * 53) + High_Bit_First * (LSBit_56 + Bit_Order * 55) ..
   --           High_Bit_First * (LSBit_56 + Bit_Order * 53) + Low_Bit_First  * (LSBit_56 + Bit_Order * 55);
   --
   --     end record;
   --     Packed_Raw_Data_Octet_Length : constant := 7;
   --     for Packed_Raw_Data_Type'Size use Packed_Raw_Data_Octet_Length * 8;


   --  If the bit numbers are correct for High_Bit_First = 1, use this
   --  pattern:
   --  (TBD :).

end SAL.Endianness;




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-04-23 21:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-23 15:50 Converting application from BIG ENDIAN to LITTLE ENDIAN machine Claude Riendeau
2004-04-23 17:16 ` Jean-Pierre Rosen
2004-04-23 18:59 ` Jacob Sparre Andersen
2004-04-23 21:42   ` Stephen Leake
2004-04-23 21:49 ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox