At the 2012 ACM SIGAda HILT Conference, AdaCore released an update to its GNAT Pro tool suite that now allows Ada developers to portably and reliably define data layout in an endianness-independent fashion.
According to Quentin Ochem, Technical Account Manager at AdaCore, this capability makes it possible to port and reuse existing code bases on a different hardware platform, without having to manually implement the error-prone, byte-swapping logic that would otherwise be needed.
Portability is a key requirement for many Ada applications, which often have to be maintained and perhaps augmented with new functionality, over a timespan comprising many years. Their lifetime often survives major evolutions in hardware architecture, moving away from old platforms either for obsolescence reasons or because of costs.
Whatever the reason, said Ochem, x86 platforms are now typical targets for many projects. However, the x86 processor represents numeric data in ‘little endian’ format (lower address for lower order byte), while legacy platforms, such as 68K, PowerPC, and SPARC, are in ‘big endian’ format (lower address for higher order byte).
This difference, he said, can make the porting effort a substantial and error-prone endeavor, and, indeed, the costs and risks associated with moving to a different binary representation may simply be prohibitive.
To solve this problem, GNAT Pro has been enhanced with an ‘endianness-agnostic’ feature that specifies the endianness of a specific data structure independent of the underlying architecture.
The definition of the representation uses a natural extension to the existing Ada data representation model. Ada source code is thus portable across big endian and little endian architectures, even when manipulating low-level data structure representations.
The cumbersome and error-prone task of writing bitwise data manipulation is transparently managed by the compiler, significantly simplifying the task of porting such applications between architectures.