Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I get this data into the .data section of the binary?

300 views
Skip to first unread message

Luke A. Guest

unread,
Jun 16, 2020, 7:32:13 AM6/16/20
to
Hi,

I'm trying to get some static data tables into the data section rather
than be elaborated at runtime. I can see no reason why this particular
set of types, records and aggregates cannot go into the data section.

I've searched for use of pragma Static_Elaboration_Desired, but there is
very little information.

Here's the full modified source from SDL minus the header:

pragma Restrictions (No_Implicit_Loops);
with Ada.Characters.Latin_1;
with Ada.Unchecked_Conversion;
with Interfaces;
with Interfaces.C;
with SDL.Video.Palettes;

package SDL.Video.Pixel_Formats is
package C renames Interfaces.C;

type Pixel_Types is
(Unknown,
Index_1,
Index_4,
Index_8,
Packed_8,
Packed_16,
Packed_32,
Array_U8,
Array_U16,
Array_U32,
Array_F16,
Array_F32) with
Convention => C;
pragma Static_Elaboration_Desired (Pixel_Types);

-- Bitmap pixel order, high bit -> low bit.
type Bitmap_Pixel_Order is (None, Little_Endian, Big_Endian) with
Convention => C;
pragma Static_Elaboration_Desired (Bitmap_Pixel_Order);

-- Packed component order, high bit -> low bit.
type Packed_Component_Order is
(None,
XRGB,
RGBX,
ARGB,
RGBA,
XBGR,
BGRX,
ABGR,
BGRA) with
Convention => C;
pragma Static_Elaboration_Desired (Packed_Component_Order);

-- Array component order, low byte -> high byte.
type Array_Component_Order is (None, RGB, RGBA, ARGB, BGR, BGRA, ABGR);
pragma Static_Elaboration_Desired (Array_Component_Order);

-- Describe how the components are laid out in bit form.
type Packed_Component_Layout is
(None,
Bits_332,
Bits_4444,
Bits_1555,
Bits_5551,
Bits_565,
Bits_8888,
Bits_2101010,
Bits_1010102) with
Convention => C;
pragma Static_Elaboration_Desired (Packed_Component_Layout);

type Bits_Per_Pixels is range 0 .. 32 with
Static_Predicate => Bits_Per_Pixels in 0 | 1 | 4 | 8 | 12 | 15 | 16
| 24 | 32,
Convention => C;
pragma Static_Elaboration_Desired (Bits_Per_Pixels);

Bits_Per_Pixel_Error : constant Bits_Per_Pixels := 0;

type Bytes_Per_Pixels is range 0 .. 4 with
Convention => C;
pragma Static_Elaboration_Desired (Bytes_Per_Pixels);

Bytes_Per_Pixel_Error : constant Bytes_Per_Pixels :=
Bytes_Per_Pixels'First;

-- 29 28 24 20 16 8 0
-- 000 1 ptpt popo llll bibibibi bybybyby
--
-- or
--
-- 24 16 8 0
-- DDDDDDDD CCCCCCCC BBBBBBBB AAAAAAAA

type Index_Order_Padding is range 0 .. 1 with
Convention => C;
pragma Static_Elaboration_Desired (Index_Order_Padding);

type Pixel_Orders (Pixel_Type : Pixel_Types := Unknown) is
record
case Pixel_Type is
when Index_1 | Index_4 | Index_8 =>
Indexed_Order : Bitmap_Pixel_Order;
Indexed_Pad : Index_Order_Padding;

when Packed_8 | Packed_16 | Packed_32 =>
Packed_Order : Packed_Component_Order;

when Array_U8 | Array_U16 | Array_U32 | Array_F16 | Array_F32 =>
Array_Order : Array_Component_Order;

when others =>
null;
end case;
end record with
Unchecked_Union => True,
Convention => C,
Size => 4;

pragma Warnings (Off, "no component clause given");
for Pixel_Orders use
record
Indexed_Order at 0 range 0 .. 2; -- This was 2 as that is the
max size required but it causes a bit set bug!
Indexed_Pad at 0 range 3 .. 3;
Packed_Order at 0 range 0 .. 3;
Array_Order at 0 range 0 .. 3;
end record;
pragma Static_Elaboration_Desired (Pixel_Orders);
pragma Warnings (On, "no component clause given");

type Planar_Pixels is
record
A : Character;
B : Character;
C : Character;
D : Character;
end record with
Size => 32,
Convention => C;

for Planar_Pixels use
record
A at 0 range 0 .. 7;
B at 0 range 8 .. 15;
C at 0 range 16 .. 23;
D at 0 range 24 .. 31;
end record;
pragma Static_Elaboration_Desired (Planar_Pixels);

type Non_Planar_Pixel_Padding is range 0 .. 7 with
Convention => C;
pragma Static_Elaboration_Desired (Non_Planar_Pixel_Padding);

type Non_Planar_Pixels is
record
Bytes_Per_Pixel : Bytes_Per_Pixels;
Bits_Per_Pixel : Bits_Per_Pixels;
Layout : Packed_Component_Layout;
Pixel_Order : Pixel_Orders;
Pixel_Type : Pixel_Types;
Flag : Boolean;
Padding : Non_Planar_Pixel_Padding;
end record with
Size => 32,
Convention => C;

for Non_Planar_Pixels use
record
Bytes_Per_Pixel at 0 range 0 .. 7;
Bits_Per_Pixel at 0 range 8 .. 15;
Layout at 0 range 16 .. 19;
Pixel_Order at 0 range 20 .. 23;
Pixel_Type at 0 range 24 .. 27;
Flag at 0 range 28 .. 28;
Padding at 0 range 29 .. 31;
end record;
pragma Static_Elaboration_Desired (Non_Planar_Pixels);

type Pixel_Format_Names (Planar : Boolean := False) is
record
case Planar is
when True =>
Planar_Format : Planar_Pixels;
when False =>
Non_Planar_Format : Non_Planar_Pixels;
end case;
end record with
Unchecked_Union => True,
Size => 32,
Convention => C;
pragma Static_Elaboration_Desired (Pixel_Format_Names);

Pixel_Format_Unknown : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => True,
Planar_Format => Planar_Pixels'
(others => Ada.Characters.Latin_1.NUL));
pragma Static_Elaboration_Desired (Pixel_Format_Unknown);

Pixel_Format_Index_1_LSB : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Index_1,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Index_1,
Indexed_Order => Little_Endian,
Indexed_Pad => Index_Order_Padding'First),
Layout => None,
Bits_Per_Pixel => 1,
Bytes_Per_Pixel => 0));
pragma Static_Elaboration_Desired (Pixel_Format_Index_1_LSB);

Pixel_Format_Index_1_MSB : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Index_1,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Index_1,
Indexed_Order => Big_Endian,
Indexed_Pad => Index_Order_Padding'First),
Layout => None,
Bits_Per_Pixel => 1,
Bytes_Per_Pixel => 0));
pragma Static_Elaboration_Desired (Pixel_Format_Index_1_MSB);

Pixel_Format_Index_4_LSB : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Index_4,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Index_4,
Indexed_Order => Little_Endian,
Indexed_Pad => Index_Order_Padding'First),
Layout => None,
Bits_Per_Pixel => 4,
Bytes_Per_Pixel => 0));
pragma Static_Elaboration_Desired (Pixel_Format_Index_4_LSB);

Pixel_Format_Index_4_MSB : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Index_4,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Index_4,
Indexed_Order => Big_Endian,
Indexed_Pad => Index_Order_Padding'First),
Layout => None,
Bits_Per_Pixel => 4,
Bytes_Per_Pixel => 0));
pragma Static_Elaboration_Desired (Pixel_Format_Index_4_MSB);

Pixel_Format_Index_8 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Index_8,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Index_8,
Indexed_Order => None,
Indexed_Pad => Index_Order_Padding'First),
Layout => None,
Bits_Per_Pixel => 8,
Bytes_Per_Pixel => 1));
pragma Static_Elaboration_Desired (Pixel_Format_Index_8);

Pixel_Format_RGB_332 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_8,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_8,
Packed_Order => XRGB),
Layout => Bits_332,
Bits_Per_Pixel => 8,
Bytes_Per_Pixel => 1));
pragma Static_Elaboration_Desired (Pixel_Format_RGB_332);

Pixel_Format_RGB_444 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => XRGB),
Layout => Bits_4444,
Bits_Per_Pixel => 12,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_RGB_444);

Pixel_Format_RGB_555 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => XRGB),
Layout => Bits_1555,
Bits_Per_Pixel => 15,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_RGB_555);

Pixel_Format_BGR_555 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => XBGR),
Layout => Bits_1555,
Bits_Per_Pixel => 15,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_BGR_555);

Pixel_Format_ARGB_4444 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => ARGB),
Layout => Bits_4444,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_ARGB_4444);

Pixel_Format_RGBA_4444 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => RGBA),
Layout => Bits_4444,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_RGBA_4444);

Pixel_Format_ABGR_4444 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => ABGR),
Layout => Bits_4444,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_ABGR_4444);

Pixel_Format_BGRA_4444 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => BGRA),
Layout => Bits_4444,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_BGRA_4444);

Pixel_Format_ARGB_1555 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => ARGB),
Layout => Bits_1555,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_ARGB_1555);

Pixel_Format_RGBA_5551 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => RGBA),
Layout => Bits_5551,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_RGBA_5551);

Pixel_Format_ABGR_1555 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => ABGR),
Layout => Bits_1555,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_ABGR_1555);

Pixel_Format_BGRA_5551 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => BGRA),
Layout => Bits_5551,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_BGRA_5551);

Pixel_Format_RGB_565 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => XRGB),
Layout => Bits_565,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_RGB_565);

Pixel_Format_BGR_565 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_16,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_16,
Packed_Order => XBGR),
Layout => Bits_565,
Bits_Per_Pixel => 16,
Bytes_Per_Pixel => 2));
pragma Static_Elaboration_Desired (Pixel_Format_BGR_565);

Pixel_Format_RGB_24 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Array_U8,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Array_U8,
Array_Order => RGB),
Layout => None,
Bits_Per_Pixel => 24,
Bytes_Per_Pixel => 3));
pragma Static_Elaboration_Desired (Pixel_Format_RGB_24);

Pixel_Format_BGR_24 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Array_U8,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Array_U8,
Array_Order => BGR),
Layout => None,
Bits_Per_Pixel => 24,
Bytes_Per_Pixel => 3));
pragma Static_Elaboration_Desired (Pixel_Format_BGR_24);

Pixel_Format_RGB_888 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_32,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_32,
Packed_Order => XRGB),
Layout => Bits_8888,
Bits_Per_Pixel => 24,
Bytes_Per_Pixel => 4));
pragma Static_Elaboration_Desired (Pixel_Format_RGB_888);

Pixel_Format_RGBX_8888 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_32,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_32,
Packed_Order => RGBX),
Layout => Bits_8888,
Bits_Per_Pixel => 24,
Bytes_Per_Pixel => 4));
pragma Static_Elaboration_Desired (Pixel_Format_RGBX_8888);

Pixel_Format_BGR_888 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_32,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_32,
Packed_Order => XBGR),
Layout => Bits_8888,
Bits_Per_Pixel => 24,
Bytes_Per_Pixel => 4));
pragma Static_Elaboration_Desired (Pixel_Format_BGR_888);

Pixel_Format_BGRX_8888 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_32,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_32,
Packed_Order => BGRX),
Layout => Bits_8888,
Bits_Per_Pixel => 24,
Bytes_Per_Pixel => 4));
pragma Static_Elaboration_Desired (Pixel_Format_BGRX_8888);

Pixel_Format_ARGB_8888 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_32,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_32,
Packed_Order => ARGB),
Layout => Bits_8888,
Bits_Per_Pixel => 32,
Bytes_Per_Pixel => 4));
pragma Static_Elaboration_Desired (Pixel_Format_ARGB_8888);

Pixel_Format_RGBA_8888 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_32,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_32,
Packed_Order => RGBA),
Layout => Bits_8888,
Bits_Per_Pixel => 32,
Bytes_Per_Pixel => 4));
pragma Static_Elaboration_Desired (Pixel_Format_RGBA_8888);

Pixel_Format_ABGR_8888 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_32,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_32,
Packed_Order => ABGR),
Layout => Bits_8888,
Bits_Per_Pixel => 32,
Bytes_Per_Pixel => 4));
pragma Static_Elaboration_Desired (Pixel_Format_ABGR_8888);

Pixel_Format_BGRA_8888 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_32,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_32,
Packed_Order => BGRA),
Layout => Bits_8888,
Bits_Per_Pixel => 32,
Bytes_Per_Pixel => 4));
pragma Static_Elaboration_Desired (Pixel_Format_BGRA_8888);

Pixel_Format_ARGB_2101010 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => False,
Non_Planar_Format => Non_Planar_Pixels'
(Padding =>
Non_Planar_Pixel_Padding'First,
Flag => True,
Pixel_Type => Packed_32,
Pixel_Order => Pixel_Orders'
(Pixel_Type => Packed_32,
Packed_Order => ARGB),
Layout => Bits_2101010,
Bits_Per_Pixel => 32,
Bytes_Per_Pixel => 4));
pragma Static_Elaboration_Desired (Pixel_Format_ARGB_2101010);

Pixel_Format_YV_12 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => True,
Planar_Format => Planar_Pixels'
(A => 'Y',
B => 'V',
C => '1',
D => '2'));
pragma Static_Elaboration_Desired (Pixel_Format_YV_12);

Pixel_Format_IYUV : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => True,
Planar_Format => Planar_Pixels'
(A => 'I',
B => 'Y',
C => 'U',
D => 'V'));
pragma Static_Elaboration_Desired (Pixel_Format_IYUV);

Pixel_Format_YUY_2 : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => True,
Planar_Format => Planar_Pixels'
(A => 'Y',
B => 'U',
C => 'Y',
D => '2'));
pragma Static_Elaboration_Desired (Pixel_Format_YUY_2);

Pixel_Format_UYVY : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => True,
Planar_Format => Planar_Pixels'
(A => 'U',
B => 'Y',
C => 'V',
D => 'Y'));
pragma Static_Elaboration_Desired (Pixel_Format_UYVY);

Pixel_Format_YVYU : constant Pixel_Format_Names :=
Pixel_Format_Names'(Planar => True,
Planar_Format => Planar_Pixels'
(A => 'Y',
B => 'V',
C => 'Y',
D => 'U'));
pragma Static_Elaboration_Desired (Pixel_Format_YVYU);

type Colour_Mask is mod 2 ** 32 with
Convention => C;

type Private_Pixel_Format is private;

type Pixel_Format is
record
Format : Pixel_Format_Names;
Palette : Palettes.Palette_Access;
Bits : Bits_Per_Pixels;
Bytes : Bytes_Per_Pixels;
Padding : Interfaces.Unsigned_16;
Red_Mask : Colour_Mask;
Green_Mask : Colour_Mask;
Blue_Mask : Colour_Mask;
Alpha_Mask : Colour_Mask;

-- This is mainly padding to make sure the record size matches
what is expected from C.
Private_Part : Private_Pixel_Format;
end record with
Convention => C;

-- TODO: Possibly change this to a controlled type.
type Pixel_Format_Access is access all Pixel_Format with
Convention => C;

function Create (Format : in Pixel_Format_Names) return
Pixel_Format_Access with
Import => True,
Convention => C,
External_Name => "SDL_AllocFormat";

procedure Free (Format : in Pixel_Format_Access) with
Import => True,
Convention => C,
External_Name => "SDL_FreeFormat";

function Image (Format : in Pixel_Format_Names) return String;
-- Import => True,
-- Convention => C,
-- External_Name => "SDL_GetPixelFormatName";

procedure To_Components
(Pixel : in Interfaces.Unsigned_32;
Format : in Pixel_Format_Access;
Red : out Palettes.Colour_Component;
Green : out Palettes.Colour_Component;
Blue : out Palettes.Colour_Component) with
Import => True,
Convention => C,
External_Name => "SDL_GetRGB";

procedure To_Components
(Pixel : in Interfaces.Unsigned_32;
Format : in Pixel_Format_Access;
Red : out Palettes.Colour_Component;
Green : out Palettes.Colour_Component;
Blue : out Palettes.Colour_Component;
Alpha : out Palettes.Colour_Component) with
Import => True,
Convention => C,
External_Name => "SDL_GetRGBA";

function To_Pixel
(Format : in Pixel_Format_Access;
Red : in Palettes.Colour_Component;
Green : in Palettes.Colour_Component;
Blue : in Palettes.Colour_Component) return
Interfaces.Unsigned_32 with
Import => True,
Convention => C,
External_Name => "SDL_MapRGB";

function To_Pixel
(Format : in Pixel_Format_Access;
Red : in Palettes.Colour_Component;
Green : in Palettes.Colour_Component;
Blue : in Palettes.Colour_Component;
Alpha : in Palettes.Colour_Component) return
Interfaces.Unsigned_32 with
Import => True,
Convention => C,
External_Name => "SDL_MapRGBA";

function To_Colour (Pixel : in Interfaces.Unsigned_32; Format : in
Pixel_Format_Access) return Palettes.Colour with
Inline => True;

function To_Pixel (Colour : in Palettes.Colour; Format : in
Pixel_Format_Access) return Interfaces.Unsigned_32 with
Inline => True;

function To_Name
(Bits : in Bits_Per_Pixels;
Red_Mask : in Colour_Mask;
Green_Mask : in Colour_Mask;
Blue_Mask : in Colour_Mask;
Alpha_Mask : in Colour_Mask) return Pixel_Format_Names with
Import => True,
Convention => C,
External_Name => "SDL_MasksToPixelFormatEnum";

function To_Masks
(Format : in Pixel_Format_Names;
Bits : out Bits_Per_Pixels;
Red_Mask : out Colour_Mask;
Green_Mask : out Colour_Mask;
Blue_Mask : out Colour_Mask;
Alpha_Mask : out Colour_Mask) return Boolean with
Inline => True;

-- Gamma
type Gamma_Value is mod 2 ** 16 with
Convention => C;

type Gamma_Ramp is array (Integer range 1 .. 256) of Gamma_Value with
Convention => C;

procedure Calculate (Gamma : in Float; Ramp : out Gamma_Ramp) with
Import => True,
Convention => C,
External_Name => "SDL_CalculateGammaRamp";
private
-- The following fields are defined as "internal use" in the SDL docs.
type Private_Pixel_Format is
record
Rred_Loss : Interfaces.Unsigned_8;
Green_Loss : Interfaces.Unsigned_8;
Blue_Loss : Interfaces.Unsigned_8;
Alpha_Loss : Interfaces.Unsigned_8;
Red_Shift : Interfaces.Unsigned_8;
Green_Shift : Interfaces.Unsigned_8;
Blue_Shift : Interfaces.Unsigned_8;
Alpha_Shift : Interfaces.Unsigned_8;
Ref_Count : C.int;
Next : Pixel_Format_Access;
end record with
Convention => C;
end SDL.Video.Pixel_Formats;

Luke A. Guest

unread,
Jun 16, 2020, 7:37:54 AM6/16/20
to
I realise that the pragma Static_Elaboration_Desired applies to the
whole package now, but it doesn't work:

package SDL.Video.Pixel_Formats is
pragma Static_Elaboration_Desired;
...

J-P. Rosen

unread,
Jun 16, 2020, 7:50:33 AM6/16/20
to
This is a Gnat specific pragma, so only AdaCore can help. But did you
try pragma Shared_Passive? Actually, pragma Preelaborate should be
enough to guarantee compile-time elaboration.

--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

Luke A. Guest

unread,
Jun 16, 2020, 8:37:38 AM6/16/20
to
On 16/06/2020 12:50, J-P. Rosen wrote:
> Le 16/06/2020 à 13:37, Luke A. Guest a écrit :
>> I realise that the pragma Static_Elaboration_Desired applies to the
>> whole package now, but it doesn't work:
>>
>> package SDL.Video.Pixel_Formats is
>> pragma Static_Elaboration_Desired;
>> ...
>>
> This is a Gnat specific pragma, so only AdaCore can help. But did you
> try pragma Shared_Passive? Actually, pragma Preelaborate should be
> enough to guarantee compile-time elaboration.
>

Except, you can't use that pragma, because it wants all other's to be
preelaborated, but they're not.

Luke A. Guest

unread,
Jun 16, 2020, 8:45:50 AM6/16/20
to
And this is one of the things that really annoys me about Ada.

J-P. Rosen

unread,
Jun 16, 2020, 8:56:47 AM6/16/20
to
Le 16/06/2020 à 14:45, Luke A. Guest a écrit :
>> Except, you can't use that pragma, because it wants all other's to be
>> preelaborated, but they're not.
>>
> And this is one of the things that really annoys me about Ada.
>
But how could it be otherwise? If you depend on a non-preelaborable
unit, then you depend on something which is not computable at compile
time...

Of course, there is the case where you depend only on preelaborable
declarations within a non-preelaborable package. You can then move these
declarations into a separate, preelaborable, package.

Luke A. Guest

unread,
Jun 16, 2020, 9:00:28 AM6/16/20
to
On 16/06/2020 13:56, J-P. Rosen wrote:
> Le 16/06/2020 à 14:45, Luke A. Guest a écrit :
>>> Except, you can't use that pragma, because it wants all other's to be
>>> preelaborated, but they're not.
>>>
>> And this is one of the things that really annoys me about Ada.
>>
> But how could it be otherwise? If you depend on a non-preelaborable
> unit, then you depend on something which is not computable at compile
> time...

Which misses the point entirely of my original issue, and complete
hatred of this part of Ada. Literally, if something can be compiled to
be in the data section, it should be.

Luke A. Guest

unread,
Jun 16, 2020, 9:04:26 AM6/16/20
to
So, I re-applied an old patch from onox which adds in preelaborate
everywhere and it still doesn't work. The pragma is in the package, the
disassembly for hte package shows the various objects being stored in
.bss not .data and there is an elaboration procedure which initialised
these objects in the .bss in the final applications.

J-P. Rosen

unread,
Jun 16, 2020, 9:29:34 AM6/16/20
to
Le 16/06/2020 à 14:59, Luke A. Guest a écrit :
> Which misses the point entirely of my original issue, and complete
> hatred of this part of Ada. Literally, if something can be compiled to
> be in the data section, it should be.

I understand your problem, but this is a compiler issue, not a language
issue. There is no such thing as a "data section" in a high level,
machine independent, definition of a programming language...

Luke A. Guest

unread,
Jun 16, 2020, 9:44:48 AM6/16/20
to
On 16/06/2020 14:29, J-P. Rosen wrote:
> Le 16/06/2020 à 14:59, Luke A. Guest a écrit :
>> Which misses the point entirely of my original issue, and complete
>> hatred of this part of Ada. Literally, if something can be compiled to
>> be in the data section, it should be.
>
> I understand your problem, but this is a compiler issue, not a language
> issue. There is no such thing as a "data section" in a high level,
> machine independent, definition of a programming language...
>

According to 10.2.1 it should be possible:

is important that programs be able to declare data structures that
are link-time initialized with aggregates, string_literals, and
concatenations thereof. etc.

Even adding pragma Preelaborable_Initialization (x) for each of the
types, doesn't do anything.

Mark Lorenzen

unread,
Jun 16, 2020, 9:52:01 AM6/16/20
to
I don't know why you insist on eliminating elaboration code, but try to see if this can help you:

https://docs.adacore.com/gnathie_ug-docs/html/gnathie_ug/gnathie_ug/using_gnat_pro_features_relevant_to_high_integrity.html#avoiding-elaboration-code

Regards,
Mark L

Luke A. Guest

unread,
Jun 16, 2020, 10:09:36 AM6/16/20
to
On 16/06/2020 14:52, Mark Lorenzen wrote:

>
> I don't know why you insist on eliminating elaboration code, but try to see if this can help you:

To cut down on startup times when there is a lot of static data and to
make sure the compiler puts that data where it should.

> https://docs.adacore.com/gnathie_ug-docs/html/gnathie_ug/gnathie_ug/using_gnat_pro_features_relevant_to_high_integrity.html#avoiding-elaboration-code

I'm surprised that's back and it was deprecated a while back, but no
that doesn't work, throws up all manor of errors. One being the
Static_Predicate, so they cannot be used.

Niklas Holsti

unread,
Jun 16, 2020, 10:14:03 AM6/16/20
to
On 2020-06-16 14:31, Luke A. Guest wrote:
> Hi,
>
> I'm trying to get some static data tables into the data section rather
> than be elaborated at runtime. I can see no reason why this particular
> set of types, records and aggregates cannot go into the data section.

[snip]

> Pixel_Format_Unknown : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => True,
> Planar_Format => Planar_Pixels'
> (others => Ada.Characters.Latin_1.NUL));

Several years ago we had a problem like this, with a large constant
array that we wanted to have only once in RAM. This was with the XGC Ada
compiler, but there we found a work-around: using positional rather than
named association for the large array aggregate.

I have no idea if this will help you -- the types in our case were much
simpler -- but you might try it with a small subset of your package:

Pixel_Format_Unknown : constant Pixel_Format_Names :=
(True, (NUL, NUL, NUL, NUL));

(assuming "use Ada.Characters.Latin_1").

--
Niklas Holsti
niklas holsti tidorum fi
. @ .

Dmitry A. Kazakov

unread,
Jun 16, 2020, 10:25:04 AM6/16/20
to
That is interesting. Was there the "others =>" part?

I can imagine that with "others => NUL" a static zeroed section were
used with other parts written upon it during start.

P.S. I hope more people now see why compile-time subprograms are necessary.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Niklas Holsti

unread,
Jun 16, 2020, 10:32:02 AM6/16/20
to
On 2020-06-16 17:25, Dmitry A. Kazakov wrote:
> On 16/06/2020 16:14, Niklas Holsti wrote:
>> On 2020-06-16 14:31, Luke A. Guest wrote:
>
>>> I'm trying to get some static data tables into the data section rather
>>> than be elaborated at runtime. I can see no reason why this particular
>>> set of types, records and aggregates cannot go into the data section.
>>
>>     [snip]
>>
>>>     Pixel_Format_Unknown     : constant Pixel_Format_Names :=
>>>       Pixel_Format_Names'(Planar        => True,
>>>                           Planar_Format => Planar_Pixels'
>>>                             (others => Ada.Characters.Latin_1.NUL));
>>
>> Several years ago we had a problem like this, with a large constant
>> array that we wanted to have only once in RAM. This was with the XGC
>> Ada compiler, but there we found a work-around: using positional
>> rather than named association for the large array aggregate.
>>
>> I have no idea if this will help you -- the types in our case were
>> much simpler -- but you might try it with a small subset of your package:
>>
>>     Pixel_Format_Unknown     : constant Pixel_Format_Names :=
>>       (True, (NUL, NUL, NUL, NUL));
>>
>> (assuming "use Ada.Characters.Latin_1").
>
> That is interesting. Was there the "others =>" part?

I don't remember for sure, but I think not.

As I said, the types were much simpler. IIRC, the array elements were
System.Address, and the index was an integer range. The array mapped the
identifiers of the (many!) commandable/settable program "parameters" to
their memory locations.

Luke A. Guest

unread,
Jun 16, 2020, 10:41:05 AM6/16/20
to
On 16/06/2020 15:14, Niklas Holsti wrote:
> On 2020-06-16 14:31, Luke A. Guest wrote:
>> Hi,
>>
>> I'm trying to get some static data tables into the data section rather
>> than be elaborated at runtime. I can see no reason why this particular
>> set of types, records and aggregates cannot go into the data section.
>
>    [snip]
>
>>     Pixel_Format_Unknown     : constant Pixel_Format_Names :=
>>       Pixel_Format_Names'(Planar        => True,
>>                           Planar_Format => Planar_Pixels'
>>                             (others => Ada.Characters.Latin_1.NUL));

Strangely enough, with preelaborate, that's the only one which gets put
into rodata:

Disassembly of section
.rodata.sdl__video__pixel_formats__pixel_format_unknown:

0000000000000000 <sdl__video__pixel_formats__pixel_format_unknown>:
sdl__video__pixel_formats__pixel_format_unknown : constant
0: 00 00 add %al,(%rax)
...

Disassembly of section .bss.sdl__video__pixel_formats__A44s:

0000000000000000 <sdl__video__pixel_formats__A44s>:
0: 00 00 add %al,(%rax)
...

Disassembly of section
.bss.sdl__video__pixel_formats__pixel_format_index_1_lsb:

0000000000000000 <sdl__video__pixel_formats__pixel_format_index_1_lsb>:
sdl__video__pixel_formats__pixel_format_index_1_lsb : constant
0: 00 00 add %al,(%rax)

> Several years ago we had a problem like this, with a large constant
> array that we wanted to have only once in RAM. This was with the XGC Ada
> compiler, but there we found a work-around: using positional rather than
> named association for the large array aggregate.
>
> I have no idea if this will help you -- the types in our case were much
> simpler -- but you might try it with a small subset of your package:
>
>    Pixel_Format_Unknown     : constant Pixel_Format_Names :=
>      (True, (NUL, NUL, NUL, NUL));
>
> (assuming "use Ada.Characters.Latin_1").
>

Nope, that doesn't work.

Luke A. Guest

unread,
Jun 16, 2020, 10:42:53 AM6/16/20
to
I don't think Ada needs compile-time subprograms, it just needs to
recognise actual static data which can be generated at compile time,
also the static_predicate could be evaluated by the compiler at runtime
too.

Dmitry A. Kazakov

unread,
Jun 16, 2020, 11:21:17 AM6/16/20
to
Without calling subprograms? That is not possible in 99% of use cases.
Note also that initialization of shared sections using run-time code is
simply not possible as you must run the code exactly once.

> also the static_predicate could be evaluated by the compiler at runtime
> too.

And the predicate's terms were only literals?

Luke A. Guest

unread,
Jun 16, 2020, 11:43:53 AM6/16/20
to
On 16/06/2020 16:21, Dmitry A. Kazakov wrote:
> On 16/06/2020 16:42, Luke A. Guest wrote:
>> On 16/06/2020 15:25, Dmitry A. Kazakov wrote:
>>> On 16/06/2020 16:14, Niklas Holsti wrote:
>>
>>>> I have no idea if this will help you -- the types in our case were
>>>> much simpler -- but you might try it with a small subset of your
>>>> package:
>>>>
>>>>      Pixel_Format_Unknown     : constant Pixel_Format_Names :=
>>>>        (True, (NUL, NUL, NUL, NUL));
>>>>
>>>> (assuming "use Ada.Characters.Latin_1").
>>>
>>> That is interesting. Was there the "others =>" part?
>>>
>>> I can imagine that with "others => NUL" a static zeroed section were
>>> used with other parts written upon it during start.
>>>
>>> P.S. I hope more people now see why compile-time subprograms are
>>> necessary.
>>>
>>
>> I don't think Ada needs compile-time subprograms, it just needs to
>> recognise actual static data which can be generated at compile time,
>
> Without calling subprograms? That is not possible in 99% of use cases.

Course it is. The compiler will translate the code into data.

> Note also that initialization of shared sections using run-time code is
> simply not possible as you must run the code exactly once.
>
>> also the static_predicate could be evaluated by the compiler at runtime
>> too.
>
> And the predicate's terms were only literals?
>

Yup.

Dmitry A. Kazakov

unread,
Jun 16, 2020, 12:11:05 PM6/16/20
to
On 16/06/2020 17:43, Luke A. Guest wrote:
> On 16/06/2020 16:21, Dmitry A. Kazakov wrote:
>> On 16/06/2020 16:42, Luke A. Guest wrote:
>>> On 16/06/2020 15:25, Dmitry A. Kazakov wrote:
>>>> On 16/06/2020 16:14, Niklas Holsti wrote:
>>>
>>>>> I have no idea if this will help you -- the types in our case were
>>>>> much simpler -- but you might try it with a small subset of your
>>>>> package:
>>>>>
>>>>>      Pixel_Format_Unknown     : constant Pixel_Format_Names :=
>>>>>        (True, (NUL, NUL, NUL, NUL));
>>>>>
>>>>> (assuming "use Ada.Characters.Latin_1").
>>>>
>>>> That is interesting. Was there the "others =>" part?
>>>>
>>>> I can imagine that with "others => NUL" a static zeroed section were
>>>> used with other parts written upon it during start.
>>>>
>>>> P.S. I hope more people now see why compile-time subprograms are
>>>> necessary.
>>>>
>>>
>>> I don't think Ada needs compile-time subprograms, it just needs to
>>> recognise actual static data which can be generated at compile time,
>>
>> Without calling subprograms? That is not possible in 99% of use cases.
>
> Course it is. The compiler will translate the code into data.

Consider an array filled with Fibonacci numbers or a parser's tokens
table or a constant instance of Ada.Containers.Vectors. It is a big
issue for small embedded systems with instant booting time requirement.

Tero Koskinen

unread,
Jun 16, 2020, 2:19:46 PM6/16/20
to
Hi,

Luke A. Guest wrote on 16.6.2020 14.31:
> Hi,
>
> I'm trying to get some static data tables into the data section rather
> than be elaborated at runtime. I can see no reason why this particular
> set of types, records and aggregates cannot go into the data section.

I haven't tried with your example, but is GNAT specific pragma
Linker_Section acceptable?

https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/implementation_defined_pragmas.html#pragma-linker-section

I use that for some AVR-Ada code when I want to relocate some of the
stuff to progmem.

Example:

package PM_Strings is
type Text_In_Progmem (Len : AVR.Nat8) is record
Text : AVR.Strings.AVR_String(1..Len);
end record;

Select_Action_Str : constant AVR.Strings.AVR_String := "----
Select action ----";
Read_NFC_Str : constant AVR.Strings.AVR_String := "1 -
Read NFC tag";

Select_Action_PM : constant Text_In_Progmem :=
(Select_Action_Str'Length, Select_Action_Str);
Read_NFC_PM : constant Text_In_Progmem := (Read_NFC_Str'Length,
Read_NFC_Str);

pragma Linker_Section (Select_Action_PM, ".progmem");
pragma Linker_Section (Read_NFC_PM, ".progmem");
end PM_Strings;


-Tero

Luke A. Guest

unread,
Jun 17, 2020, 8:37:52 AM6/17/20
to
On 16/06/2020 19:19, Tero Koskinen wrote:
> Hi,
>
> I haven't tried with your example, but is GNAT specific pragma
> Linker_Section acceptable?

I can't really see how it would be as it would still require the
compiler to actually generate the correct value in .data or .rodata
space rather than a 0x0 which gets filled in later by elaboration.

Interesting though.

I wrote the above before trying. Trying to place it in ".rodata..."
caused a compiler error, placing it in .data worked, but there is still
elaboration code. Although changing the section caused many more
references to the object for some reason.

Anyone know how to get the data sections to not be disassembled as
instructions?

Niklas Holsti

unread,
Jun 17, 2020, 10:01:27 AM6/17/20
to
On 2020-06-17 15:37, Luke A. Guest wrote:
> On 16/06/2020 19:19, Tero Koskinen wrote:
>> Hi,
>>
>> I haven't tried with your example, but is GNAT specific pragma
>> Linker_Section acceptable?
>
> I can't really see how it would be as it would still require the
> compiler to actually generate the correct value in .data or .rodata
> space rather than a 0x0 which gets filled in later by elaboration.
>
> Interesting though.
>
> I wrote the above before trying. Trying to place it in ".rodata..."
> caused a compiler error, placing it in .data worked, but there is still
> elaboration code.

The compiler error probably resulted from the compiler generating
elaboration code to write something into the read-only ".rodata", right?

I once tried to put a static constant (a program-version string) into
".rodata" with pragma Linker_Section, and had no success -- it seemed to
me that (the version I had of) the GNU linker was doing some magic with
".rodata" that was not expressed in the linker command script.

I changed to use another section name (something of my own invention,
perhaps ".version" or whatever) and it worked right away. Of course I
also had to update the linker command script to place that section
somewhere.

(My object in that case was just a static string, so GNAT produced no
elaboration code, so no help for the original problem.)

Luke A. Guest

unread,
Jun 17, 2020, 11:18:36 AM6/17/20
to
On 17/06/2020 15:01, Niklas Holsti wrote:
> On 2020-06-17 15:37, Luke A. Guest wrote:

>> Interesting though.
>>
>> I wrote the above before trying. Trying to place it in ".rodata..."
>> caused a compiler error, placing it in .data worked, but there is still
>> elaboration code.
>
> The compiler error probably resulted from the compiler generating
> elaboration code to write something into the read-only ".rodata", right?

Nope, turns out it was the assembler:

/tmp/cc63XSy6.s: Assembler messages:
/tmp/cc63XSy6.s:5: Warning: setting incorrect section attributes for
.rodata.sdl__video__pixel_formats__pixel_format_index_1_lsb

Randy Brukardt

unread,
Jun 17, 2020, 10:55:07 PM6/17/20
to
"Luke A. Guest" <lag...@archeia.com> wrote in message
news:rcaicd$ifh$1...@gioia.aioe.org...
...
> According to 10.2.1 it should be possible:
>
> is important that programs be able to declare data structures that
> are link-time initialized with aggregates, string_literals, and
> concatenations thereof. etc.
>
> Even adding pragma Preelaborable_Initialization (x) for each of the
> types, doesn't do anything.

The requirement in the Ada Standard is that one should preelaborate data if
the containing package is preelaborated. There's no requirement otherwise,
and since it is an annex C requirement, it is not required of all Ada
compilers. Janus/Ada, for instance, has no concept of an initialized but
modifiable data segment so it can't do precisely what you want. (It does put
aggregates into such a segment, but it will copy them if they are used to
initialize variables.) We did that to match the RAM/ROM split of many
embedded systems.

Anyway, I would expect a compiler to do it if it is possible. But it very
often isn't possible for one reason or another (for instance, static
aggregates often are *way* bigger than dynamic initialization, so for a
compiler that tries to minimize memory usage, static initialization may not
be a good idea in some cases).

The better question is why you care? One ought to be concerned about whether
performance is good enough for your application, and it's highly unlikely
that the load time would have any impact on that whatsoever. (And as
previously noted, static initialization can require more work to load a
program.) On a desktop, antivirus overhead is way more than any sort of load
cost/saving from the memory layout. (The situation can be different on a
bare machine, of course.)

Randy.


Niklas Holsti

unread,
Jun 18, 2020, 5:55:50 AM6/18/20
to
On 2020-06-18 5:55, Randy Brukardt wrote:
> "Luke A. Guest" <lag...@archeia.com> wrote in message
> news:rcaicd$ifh$1...@gioia.aioe.org...
> ...
>> According to 10.2.1 it should be possible:
>>
>> is important that programs be able to declare data structures that
>> are link-time initialized with aggregates, string_literals, and
>> concatenations thereof. etc.


[snip]

> The better question is why you care?


[snip]

> (The situation can be different on a bare machine, of course.)


As I've posted in this thread two cases where I have needed things like
this, here are my reasons for needing them, just for the record.

For background, both cases occurred in bare-machine systems in which the
entire SW is stored in EEPROM and is then entirely copied to RAM for
execution, _including_ the code and read-only (constant) data.

For my case of the large constant array, we needed to save RAM space,
and did not want to spend RAM _both_ for the elaboration code that
initialized the array (larger than the array itself) and for the array.
If we had not discovered the positional-association method, we would
have had to define the array in assembly language, which would have
required _many_ Export pragmas in the Ada source.

For my case of the constant version-identifier string, the customer
required the executable SW image (in EEPROM) to contain a version
identifier at a fixed address. This is a very common requirement in this
domain. Of course it can be implemented in many ways (directly in the
linker command script, for example), but I was pleased to be able to do
it in Ada with the Linker_Section pragma.

Randy Brukardt

unread,
Jun 20, 2020, 11:55:40 PM6/20/20
to
"Niklas Holsti" <niklas...@tidorum.invalid> wrote in message
news:hl0s14...@mid.individual.net...
> On 2020-06-18 5:55, Randy Brukardt wrote:
...
>> The better question is why you care?
>
>
> [snip]
>
>> (The situation can be different on a bare machine, of course.)
>
>
...
> For my case of the large constant array, we needed to save RAM space, and
> did not want to spend RAM _both_ for the elaboration code that initialized
> the array (larger than the array itself) and for the array.

I suppose it would depend on the declaration of the array, but I would not
expect that to be the case most of the time. Typically, one can initialize
most Ada data types with a block-copy, which would only be a handful of
bytes on most target machines. Of course, if you have lots of controlled
types and tasks, you'd have issues, but those aren't preelaborable anyway
(some code would need to be executed for them).

That's the sort of thing that having a good relationship with your compiler
vendor can help with, since it often wouldn't take much tweaking to
eliminate expensive elaboration code. (It's not something I pay much
attention to unless a customer asks...)

Randy.


Niklas Holsti

unread,
Jun 21, 2020, 2:55:20 AM6/21/20
to
On 2020-06-21 6:55, Randy Brukardt wrote:
> "Niklas Holsti" <niklas...@tidorum.invalid> wrote in message
> news:hl0s14...@mid.individual.net...
>> On 2020-06-18 5:55, Randy Brukardt wrote:
> ...
>>> The better question is why you care?
>>
>>
>> [snip]
>>
>>> (The situation can be different on a bare machine, of course.)
>>
>>
> ...
>> For my case of the large constant array, we needed to save RAM space, and
>> did not want to spend RAM _both_ for the elaboration code that initialized
>> the array (larger than the array itself) and for the array.
>
> I suppose it would depend on the declaration of the array, but I would not
> expect that to be the case most of the time. Typically, one can initialize
> most Ada data types with a block-copy, which would only be a handful of
> bytes on most target machines.

I'm sure you are right, most of the time.

In our case, however, even if the compiler would have done a block-copy,
the *source* of the block-copy would also have been in RAM because the
*whole* SW image was copied at boot from EEPROM to RAM (as is ESA
practice). So the RAM consumption of the array would still be at least
twice the array size.

A block copy from EEPROM to RAM would have been ok, in principle, but in
our case the compiler/linker knew nothing about the program's EEPROM
residence. That was Boot SW business.

And if the compiler could have created the static source data for a
block copy, it could as well have placed the whole load-time initialized
array (a constant) in the read-only-data segment, which was what we
wanted, and got in the end.

This was in the days when RAM in ESA on-board computers was expensive
static RAM; nowadays it is usually dynamic RAM, I believe, and typical
RAM size has gone up by one or two orders of magnitude.

c+

unread,
Sep 3, 2020, 6:32:34 AM9/3/20
to
On Tuesday, 16 June 2020 17:02:13 UTC+5:30, Luke A. Guest wrote:
> Hi,
>
> I'm trying to get some static data tables into the data section rather
> than be elaborated at runtime. I can see no reason why this particular
> set of types, records and aggregates cannot go into the data section.
>
> I've searched for use of pragma Static_Elaboration_Desired, but there is
> very little information.
>
> Here's the full modified source from SDL minus the header:
>
> pragma Restrictions (No_Implicit_Loops);
> with Ada.Characters.Latin_1;
> with Ada.Unchecked_Conversion;
> with Interfaces;
> with Interfaces.C;
> with SDL.Video.Palettes;
>
> package SDL.Video.Pixel_Formats is
> package C renames Interfaces.C;
>
> type Pixel_Types is
> (Unknown,
> Index_1,
> Index_4,
> Index_8,
> Packed_8,
> Packed_16,
> Packed_32,
> Array_U8,
> Array_U16,
> Array_U32,
> Array_F16,
> Array_F32) with
> Convention => C;
> pragma Static_Elaboration_Desired (Pixel_Types);
>
> -- Bitmap pixel order, high bit -> low bit.
> type Bitmap_Pixel_Order is (None, Little_Endian, Big_Endian) with
> Convention => C;
> pragma Static_Elaboration_Desired (Bitmap_Pixel_Order);
>
> -- Packed component order, high bit -> low bit.
> type Packed_Component_Order is
> (None,
> XRGB,
> RGBX,
> ARGB,
> RGBA,
> XBGR,
> BGRX,
> ABGR,
> BGRA) with
> Convention => C;
> pragma Static_Elaboration_Desired (Packed_Component_Order);
>
> -- Array component order, low byte -> high byte.
> type Array_Component_Order is (None, RGB, RGBA, ARGB, BGR, BGRA, ABGR);
> pragma Static_Elaboration_Desired (Array_Component_Order);
>
> -- Describe how the components are laid out in bit form.
> type Packed_Component_Layout is
> (None,
> Bits_332,
> Bits_4444,
> Bits_1555,
> Bits_5551,
> Bits_565,
> Bits_8888,
> Bits_2101010,
> Bits_1010102) with
> Convention => C;
> pragma Static_Elaboration_Desired (Packed_Component_Layout);
>
> type Bits_Per_Pixels is range 0 .. 32 with
> Static_Predicate => Bits_Per_Pixels in 0 | 1 | 4 | 8 | 12 | 15 | 16
> | 24 | 32,
> Convention => C;
> pragma Static_Elaboration_Desired (Bits_Per_Pixels);
>
> Bits_Per_Pixel_Error : constant Bits_Per_Pixels := 0;
>
> type Bytes_Per_Pixels is range 0 .. 4 with
> Convention => C;
> pragma Static_Elaboration_Desired (Bytes_Per_Pixels);
>
> Bytes_Per_Pixel_Error : constant Bytes_Per_Pixels :=
> Bytes_Per_Pixels'First;
>
> -- 29 28 24 20 16 8 0
> -- 000 1 ptpt popo llll bibibibi bybybyby
> --
> -- or
> --
> -- 24 16 8 0
> -- DDDDDDDD CCCCCCCC BBBBBBBB AAAAAAAA
>
> type Index_Order_Padding is range 0 .. 1 with
> Convention => C;
> pragma Static_Elaboration_Desired (Index_Order_Padding);
>
> type Pixel_Orders (Pixel_Type : Pixel_Types := Unknown) is
> record
> case Pixel_Type is
> when Index_1 | Index_4 | Index_8 =>
> Indexed_Order : Bitmap_Pixel_Order;
> Indexed_Pad : Index_Order_Padding;
>
> when Packed_8 | Packed_16 | Packed_32 =>
> Packed_Order : Packed_Component_Order;
>
> when Array_U8 | Array_U16 | Array_U32 | Array_F16 | Array_F32 =>
> Array_Order : Array_Component_Order;
>
> when others =>
> null;
> end case;
> end record with
> Unchecked_Union => True,
> Convention => C,
> Size => 4;
>
> pragma Warnings (Off, "no component clause given");
> for Pixel_Orders use
> record
> Indexed_Order at 0 range 0 .. 2; -- This was 2 as that is the
> max size required but it causes a bit set bug!
> Indexed_Pad at 0 range 3 .. 3;
> Packed_Order at 0 range 0 .. 3;
> Array_Order at 0 range 0 .. 3;
> end record;
> pragma Static_Elaboration_Desired (Pixel_Orders);
> pragma Warnings (On, "no component clause given");
>
> type Planar_Pixels is
> record
> A : Character;
> B : Character;
> C : Character;
> D : Character;
> end record with
> Size => 32,
> Convention => C;
>
> for Planar_Pixels use
> record
> A at 0 range 0 .. 7;
> B at 0 range 8 .. 15;
> C at 0 range 16 .. 23;
> D at 0 range 24 .. 31;
> end record;
> pragma Static_Elaboration_Desired (Planar_Pixels);
>
> type Non_Planar_Pixel_Padding is range 0 .. 7 with
> Convention => C;
> pragma Static_Elaboration_Desired (Non_Planar_Pixel_Padding);
>
> type Non_Planar_Pixels is
> record
> Bytes_Per_Pixel : Bytes_Per_Pixels;
> Bits_Per_Pixel : Bits_Per_Pixels;
> Layout : Packed_Component_Layout;
> Pixel_Order : Pixel_Orders;
> Pixel_Type : Pixel_Types;
> Flag : Boolean;
> Padding : Non_Planar_Pixel_Padding;
> end record with
> Size => 32,
> Convention => C;
>
> for Non_Planar_Pixels use
> record
> Bytes_Per_Pixel at 0 range 0 .. 7;
> Bits_Per_Pixel at 0 range 8 .. 15;
> Layout at 0 range 16 .. 19;
> Pixel_Order at 0 range 20 .. 23;
> Pixel_Type at 0 range 24 .. 27;
> Flag at 0 range 28 .. 28;
> Padding at 0 range 29 .. 31;
> end record;
> pragma Static_Elaboration_Desired (Non_Planar_Pixels);
>
> type Pixel_Format_Names (Planar : Boolean := False) is
> record
> case Planar is
> when True =>
> Planar_Format : Planar_Pixels;
> when False =>
> Non_Planar_Format : Non_Planar_Pixels;
> end case;
> end record with
> Unchecked_Union => True,
> Size => 32,
> Convention => C;
> pragma Static_Elaboration_Desired (Pixel_Format_Names);
>
> Pixel_Format_Unknown : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => True,
> Planar_Format => Planar_Pixels'
> (others => Ada.Characters.Latin_1.NUL));
> pragma Static_Elaboration_Desired (Pixel_Format_Unknown);
>
> Pixel_Format_Index_1_LSB : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Index_1,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Index_1,
> Indexed_Order => Little_Endian,
> Indexed_Pad => Index_Order_Padding'First),
> Layout => None,
> Bits_Per_Pixel => 1,
> Bytes_Per_Pixel => 0));
> pragma Static_Elaboration_Desired (Pixel_Format_Index_1_LSB);
>
> Pixel_Format_Index_1_MSB : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Index_1,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Index_1,
> Indexed_Order => Big_Endian,
> Indexed_Pad => Index_Order_Padding'First),
> Layout => None,
> Bits_Per_Pixel => 1,
> Bytes_Per_Pixel => 0));
> pragma Static_Elaboration_Desired (Pixel_Format_Index_1_MSB);
>
> Pixel_Format_Index_4_LSB : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Index_4,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Index_4,
> Indexed_Order => Little_Endian,
> Indexed_Pad => Index_Order_Padding'First),
> Layout => None,
> Bits_Per_Pixel => 4,
> Bytes_Per_Pixel => 0));
> pragma Static_Elaboration_Desired (Pixel_Format_Index_4_LSB);
>
> Pixel_Format_Index_4_MSB : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Index_4,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Index_4,
> Indexed_Order => Big_Endian,
> Indexed_Pad => Index_Order_Padding'First),
> Layout => None,
> Bits_Per_Pixel => 4,
> Bytes_Per_Pixel => 0));
> pragma Static_Elaboration_Desired (Pixel_Format_Index_4_MSB);
>
> Pixel_Format_Index_8 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Index_8,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Index_8,
> Indexed_Order => None,
> Indexed_Pad => Index_Order_Padding'First),
> Layout => None,
> Bits_Per_Pixel => 8,
> Bytes_Per_Pixel => 1));
> pragma Static_Elaboration_Desired (Pixel_Format_Index_8);
>
> Pixel_Format_RGB_332 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_8,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_8,
> Packed_Order => XRGB),
> Layout => Bits_332,
> Bits_Per_Pixel => 8,
> Bytes_Per_Pixel => 1));
> pragma Static_Elaboration_Desired (Pixel_Format_RGB_332);
>
> Pixel_Format_RGB_444 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => XRGB),
> Layout => Bits_4444,
> Bits_Per_Pixel => 12,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_RGB_444);
>
> Pixel_Format_RGB_555 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => XRGB),
> Layout => Bits_1555,
> Bits_Per_Pixel => 15,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_RGB_555);
>
> Pixel_Format_BGR_555 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => XBGR),
> Layout => Bits_1555,
> Bits_Per_Pixel => 15,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_BGR_555);
>
> Pixel_Format_ARGB_4444 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => ARGB),
> Layout => Bits_4444,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_ARGB_4444);
>
> Pixel_Format_RGBA_4444 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => RGBA),
> Layout => Bits_4444,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_RGBA_4444);
>
> Pixel_Format_ABGR_4444 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => ABGR),
> Layout => Bits_4444,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_ABGR_4444);
>
> Pixel_Format_BGRA_4444 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => BGRA),
> Layout => Bits_4444,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_BGRA_4444);
>
> Pixel_Format_ARGB_1555 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => ARGB),
> Layout => Bits_1555,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_ARGB_1555);
>
> Pixel_Format_RGBA_5551 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => RGBA),
> Layout => Bits_5551,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_RGBA_5551);
>
> Pixel_Format_ABGR_1555 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => ABGR),
> Layout => Bits_1555,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_ABGR_1555);
>
> Pixel_Format_BGRA_5551 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => BGRA),
> Layout => Bits_5551,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_BGRA_5551);
>
> Pixel_Format_RGB_565 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => XRGB),
> Layout => Bits_565,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_RGB_565);
>
> Pixel_Format_BGR_565 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_16,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_16,
> Packed_Order => XBGR),
> Layout => Bits_565,
> Bits_Per_Pixel => 16,
> Bytes_Per_Pixel => 2));
> pragma Static_Elaboration_Desired (Pixel_Format_BGR_565);
>
> Pixel_Format_RGB_24 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Array_U8,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Array_U8,
> Array_Order => RGB),
> Layout => None,
> Bits_Per_Pixel => 24,
> Bytes_Per_Pixel => 3));
> pragma Static_Elaboration_Desired (Pixel_Format_RGB_24);
>
> Pixel_Format_BGR_24 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Array_U8,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Array_U8,
> Array_Order => BGR),
> Layout => None,
> Bits_Per_Pixel => 24,
> Bytes_Per_Pixel => 3));
> pragma Static_Elaboration_Desired (Pixel_Format_BGR_24);
>
> Pixel_Format_RGB_888 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_32,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_32,
> Packed_Order => XRGB),
> Layout => Bits_8888,
> Bits_Per_Pixel => 24,
> Bytes_Per_Pixel => 4));
> pragma Static_Elaboration_Desired (Pixel_Format_RGB_888);
>
> Pixel_Format_RGBX_8888 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_32,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_32,
> Packed_Order => RGBX),
> Layout => Bits_8888,
> Bits_Per_Pixel => 24,
> Bytes_Per_Pixel => 4));
> pragma Static_Elaboration_Desired (Pixel_Format_RGBX_8888);
>
> Pixel_Format_BGR_888 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_32,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_32,
> Packed_Order => XBGR),
> Layout => Bits_8888,
> Bits_Per_Pixel => 24,
> Bytes_Per_Pixel => 4));
> pragma Static_Elaboration_Desired (Pixel_Format_BGR_888);
>
> Pixel_Format_BGRX_8888 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_32,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_32,
> Packed_Order => BGRX),
> Layout => Bits_8888,
> Bits_Per_Pixel => 24,
> Bytes_Per_Pixel => 4));
> pragma Static_Elaboration_Desired (Pixel_Format_BGRX_8888);
>
> Pixel_Format_ARGB_8888 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_32,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_32,
> Packed_Order => ARGB),
> Layout => Bits_8888,
> Bits_Per_Pixel => 32,
> Bytes_Per_Pixel => 4));
> pragma Static_Elaboration_Desired (Pixel_Format_ARGB_8888);
>
> Pixel_Format_RGBA_8888 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_32,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_32,
> Packed_Order => RGBA),
> Layout => Bits_8888,
> Bits_Per_Pixel => 32,
> Bytes_Per_Pixel => 4));
> pragma Static_Elaboration_Desired (Pixel_Format_RGBA_8888);
>
> Pixel_Format_ABGR_8888 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_32,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_32,
> Packed_Order => ABGR),
> Layout => Bits_8888,
> Bits_Per_Pixel => 32,
> Bytes_Per_Pixel => 4));
> pragma Static_Elaboration_Desired (Pixel_Format_ABGR_8888);
>
> Pixel_Format_BGRA_8888 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_32,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_32,
> Packed_Order => BGRA),
> Layout => Bits_8888,
> Bits_Per_Pixel => 32,
> Bytes_Per_Pixel => 4));
> pragma Static_Elaboration_Desired (Pixel_Format_BGRA_8888);
>
> Pixel_Format_ARGB_2101010 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => False,
> Non_Planar_Format => Non_Planar_Pixels'
> (Padding =>
> Non_Planar_Pixel_Padding'First,
> Flag => True,
> Pixel_Type => Packed_32,
> Pixel_Order => Pixel_Orders'
> (Pixel_Type => Packed_32,
> Packed_Order => ARGB),
> Layout => Bits_2101010,
> Bits_Per_Pixel => 32,
> Bytes_Per_Pixel => 4));
> pragma Static_Elaboration_Desired (Pixel_Format_ARGB_2101010);
>
> Pixel_Format_YV_12 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => True,
> Planar_Format => Planar_Pixels'
> (A => 'Y',
> B => 'V',
> C => '1',
> D => '2'));
> pragma Static_Elaboration_Desired (Pixel_Format_YV_12);
>
> Pixel_Format_IYUV : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => True,
> Planar_Format => Planar_Pixels'
> (A => 'I',
> B => 'Y',
> C => 'U',
> D => 'V'));
> pragma Static_Elaboration_Desired (Pixel_Format_IYUV);
>
> Pixel_Format_YUY_2 : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => True,
> Planar_Format => Planar_Pixels'
> (A => 'Y',
> B => 'U',
> C => 'Y',
> D => '2'));
> pragma Static_Elaboration_Desired (Pixel_Format_YUY_2);
>
> Pixel_Format_UYVY : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => True,
> Planar_Format => Planar_Pixels'
> (A => 'U',
> B => 'Y',
> C => 'V',
> D => 'Y'));
> pragma Static_Elaboration_Desired (Pixel_Format_UYVY);
>
> Pixel_Format_YVYU : constant Pixel_Format_Names :=
> Pixel_Format_Names'(Planar => True,
> Planar_Format => Planar_Pixels'
> (A => 'Y',
> B => 'V',
> C => 'Y',
> D => 'U'));
> pragma Static_Elaboration_Desired (Pixel_Format_YVYU);
>
> type Colour_Mask is mod 2 ** 32 with
> Convention => C;
>
> type Private_Pixel_Format is private;
>
> type Pixel_Format is
> record
> Format : Pixel_Format_Names;
> Palette : Palettes.Palette_Access;
> Bits : Bits_Per_Pixels;
> Bytes : Bytes_Per_Pixels;
> Padding : Interfaces.Unsigned_16;
> Red_Mask : Colour_Mask;
> Green_Mask : Colour_Mask;
> Blue_Mask : Colour_Mask;
> Alpha_Mask : Colour_Mask;
>
> -- This is mainly padding to make sure the record size matches
> what is expected from C.
> Private_Part : Private_Pixel_Format;
> end record with
> Convention => C;
>
> -- TODO: Possibly change this to a controlled type.
> type Pixel_Format_Access is access all Pixel_Format with
> Convention => C;
>
> function Create (Format : in Pixel_Format_Names) return
> Pixel_Format_Access with
> Import => True,
> Convention => C,
> External_Name => "SDL_AllocFormat";
>
> procedure Free (Format : in Pixel_Format_Access) with
> Import => True,
> Convention => C,
> External_Name => "SDL_FreeFormat";
>
> function Image (Format : in Pixel_Format_Names) return String;
> -- Import => True,
> -- Convention => C,
> -- External_Name => "SDL_GetPixelFormatName";
>
> procedure To_Components
> (Pixel : in Interfaces.Unsigned_32;
> Format : in Pixel_Format_Access;
> Red : out Palettes.Colour_Component;
> Green : out Palettes.Colour_Component;
> Blue : out Palettes.Colour_Component) with
> Import => True,
> Convention => C,
> External_Name => "SDL_GetRGB";
>
> procedure To_Components
> (Pixel : in Interfaces.Unsigned_32;
> Format : in Pixel_Format_Access;
> Red : out Palettes.Colour_Component;
> Green : out Palettes.Colour_Component;
> Blue : out Palettes.Colour_Component;
> Alpha : out Palettes.Colour_Component) with
> Import => True,
> Convention => C,
> External_Name => "SDL_GetRGBA";
>
> function To_Pixel
> (Format : in Pixel_Format_Access;
> Red : in Palettes.Colour_Component;
> Green : in Palettes.Colour_Component;
> Blue : in Palettes.Colour_Component) return
> Interfaces.Unsigned_32 with
> Import => True,
> Convention => C,
> External_Name => "SDL_MapRGB";
>
> function To_Pixel
> (Format : in Pixel_Format_Access;
> Red : in Palettes.Colour_Component;
> Green : in Palettes.Colour_Component;
> Blue : in Palettes.Colour_Component;
> Alpha : in Palettes.Colour_Component) return
> Interfaces.Unsigned_32 with
> Import => True,
> Convention => C,
> External_Name => "SDL_MapRGBA";
>
> function To_Colour (Pixel : in Interfaces.Unsigned_32; Format : in
> Pixel_Format_Access) return Palettes.Colour with
> Inline => True;
>
> function To_Pixel (Colour : in Palettes.Colour; Format : in
> Pixel_Format_Access) return Interfaces.Unsigned_32 with
> Inline => True;
>
> function To_Name
> (Bits : in Bits_Per_Pixels;
> Red_Mask : in Colour_Mask;
> Green_Mask : in Colour_Mask;
> Blue_Mask : in Colour_Mask;
> Alpha_Mask : in Colour_Mask) return Pixel_Format_Names with
> Import => True,
> Convention => C,
> External_Name => "SDL_MasksToPixelFormatEnum";
>
> function To_Masks
> (Format : in Pixel_Format_Names;
> Bits : out Bits_Per_Pixels;
> Red_Mask : out Colour_Mask;
> Green_Mask : out Colour_Mask;
> Blue_Mask : out Colour_Mask;
> Alpha_Mask : out Colour_Mask) return Boolean with
> Inline => True;
>
> -- Gamma
> type Gamma_Value is mod 2 ** 16 with
> Convention => C;
>
> type Gamma_Ramp is array (Integer range 1 .. 256) of Gamma_Value with
> Convention => C;
>
> procedure Calculate (Gamma : in Float; Ramp : out Gamma_Ramp) with
> Import => True,
> Convention => C,
> External_Name => "SDL_CalculateGammaRamp";
> private
> -- The following fields are defined as "internal use" in the SDL docs.
> type Private_Pixel_Format is
> record
> Rred_Loss : Interfaces.Unsigned_8;
> Green_Loss : Interfaces.Unsigned_8;
> Blue_Loss : Interfaces.Unsigned_8;
> Alpha_Loss : Interfaces.Unsigned_8;
> Red_Shift : Interfaces.Unsigned_8;
> Green_Shift : Interfaces.Unsigned_8;
> Blue_Shift : Interfaces.Unsigned_8;
> Alpha_Shift : Interfaces.Unsigned_8;
> Ref_Count : C.int;
> Next : Pixel_Format_Access;
> end record with
> Convention => C;
> end SDL.Video.Pixel_Formats;

patelchet...@gmail.com

unread,
Sep 13, 2020, 9:36:56 AM9/13/20
to

erche...@gmail.com

unread,
Sep 19, 2020, 10:08:35 AM9/19/20
to

yhumina stir

unread,
Sep 28, 2020, 7:36:09 AM9/28/20
to
0 new messages