summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gnat.dg/blkextract_from_reg.adb
blob: 204d71964c75347837f571259635197e7939295d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
--  { dg-do run }

with System, Ada.Unchecked_Conversion; use System;

procedure BLKextract_From_Reg is

   type Byte is range 0 .. +255;
   for  Byte'size use 8;

   type RGB is array (1 .. 3) of Byte;
   for RGB'Size use 24;

   type RAW_Packet is range 0 .. 2 ** 32 - 1;
   for  RAW_Packet'Size use 32;

   type Composite_Packet is record
      Values : RGB;
      Pad    : Byte;
   end record;
   for Composite_Packet use record
      Values at 0 range 0 .. 23;
      Pad    at 3 range 0 .. 7;
   end record;
   for Composite_Packet'Size use 32;

   function To_Composite_Packet is
      new Ada.Unchecked_Conversion (RAW_Packet, Composite_Packet);

   function Blob return RGB is
      RAW_Blob : RAW_Packet := 16#01020304#;
   begin
      return To_Composite_Packet (RAW_Blob).Values;
   end;

   Blob_Color : RGB := Blob;
   Expected_Color : RGB;
begin
   if System.Default_Bit_Order = High_Order_First then
      Expected_Color := (1 => 1, 2 => 2, 3 => 3);
   else
      Expected_Color := (1 => 4, 2 => 3, 3 => 2);
   end if;
   
   for I in Blob_Color'Range loop
      if Blob_Color (I) /= Expected_Color (I) then
	 raise Program_Error;
      end if;
   end loop;
end;