1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . S T O R A G E _ E L E M E N T S --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 pragma Compiler_Unit_Warning
;
34 with Ada
.Unchecked_Conversion
;
36 package body System
.Storage_Elements
is
38 pragma Suppress
(All_Checks
);
40 -- Conversion to/from address
42 -- Note qualification below of To_Address to avoid ambiguities systems
43 -- where Address is a visible integer type.
45 function To_Address
is
46 new Ada
.Unchecked_Conversion
(Storage_Offset
, Address
);
48 new Ada
.Unchecked_Conversion
(Address
, Storage_Offset
);
50 -- Conversion to/from integers
52 -- These functions must be place first because they are inlined_always
53 -- and are used and inlined in other subprograms defined in this unit.
59 function To_Address
(Value
: Integer_Address
) return Address
is
61 return Address
(Value
);
68 function To_Integer
(Value
: Address
) return Integer_Address
is
70 return Integer_Address
(Value
);
79 function "+" (Left
: Address
; Right
: Storage_Offset
) return Address
is
81 return Storage_Elements
.To_Address
82 (To_Integer
(Left
) + To_Integer
(To_Address
(Right
)));
85 function "+" (Left
: Storage_Offset
; Right
: Address
) return Address
is
87 return Storage_Elements
.To_Address
88 (To_Integer
(To_Address
(Left
)) + To_Integer
(Right
));
95 function "-" (Left
: Address
; Right
: Storage_Offset
) return Address
is
97 return Storage_Elements
.To_Address
98 (To_Integer
(Left
) - To_Integer
(To_Address
(Right
)));
101 function "-" (Left
, Right
: Address
) return Storage_Offset
is
103 return To_Offset
(Storage_Elements
.To_Address
104 (To_Integer
(Left
) - To_Integer
(Right
)));
113 Right
: Storage_Offset
) return Storage_Offset
117 return Storage_Offset
118 (To_Integer
(Left
) mod Integer_Address
(Right
));
120 -- The negative case makes no sense since it is a case of a mod where
121 -- the left argument is unsigned and the right argument is signed. In
122 -- accordance with the (spirit of the) permission of RM 13.7.1(16),
123 -- we raise CE, and also include the zero case here. Yes, the RM says
124 -- PE, but this really is so obviously more like a constraint error.
127 raise Constraint_Error
;
131 end System
.Storage_Elements
;