| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S Y S T E M . S T O R A G E _ E L E M E N T S -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2002-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- This specification is derived from the Ada Reference Manual for use with -- |
| 12 |
-- GNAT. The copyright notice above, and the license provisions that follow -- |
| 13 |
-- apply solely to the implementation dependent sections of this file. -- |
| 14 |
-- -- |
| 15 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 16 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 17 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 18 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 19 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 20 |
-- or FITNESS FOR A PARTICULAR PURPOSE. -- |
| 21 |
-- -- |
| 22 |
-- As a special exception under Section 7 of GPL version 3, you are granted -- |
| 23 |
-- additional permissions described in the GCC Runtime Library Exception, -- |
| 24 |
-- version 3.1, as published by the Free Software Foundation. -- |
| 25 |
-- -- |
| 26 |
-- You should have received a copy of the GNU General Public License and -- |
| 27 |
-- a copy of the GCC Runtime Library Exception along with this program; -- |
| 28 |
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- |
| 29 |
-- <http://www.gnu.org/licenses/>. -- |
| 30 |
-- -- |
| 31 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 32 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 33 |
-- -- |
| 34 |
------------------------------------------------------------------------------ |
| 35 |
|
| 36 |
-- This package provides the ``Storage_Elements`` package as defined by the |
| 37 |
-- Ada ARM 13.7.1 to allow for arithmetic operations on memory addresses. |
| 38 |
|
| 39 |
-- Warning: declarations in this package are ambiguous with respect to the |
| 40 |
-- extra declarations that can be introduced into System using Extend_System. |
| 41 |
-- It is a good idea to avoid use clauses for this package. |
| 42 |
|
| 43 |
package System.Storage_Elements with |
| 44 |
Always_Terminates |
| 45 |
is |
| 46 |
pragma Pure; |
| 47 |
-- Note that we take advantage of the implementation permission to make |
| 48 |
-- this unit Pure instead of Preelaborable; see RM 13.7.1(15). In Ada 2005, |
| 49 |
-- this is Pure in any case (AI-362). |
| 50 |
|
| 51 |
pragma No_Elaboration_Code_All; |
| 52 |
-- Allow the use of that restriction in units that WITH this unit |
| 53 |
|
| 54 |
type Storage_Offset is range -Memory_Size / 2 .. Memory_Size / 2 - 1; |
| 55 |
|
| 56 |
subtype Storage_Count is Storage_Offset range 0 .. Storage_Offset'Last; |
| 57 |
-- *Storage_Count* is a subtype of *Storage_Offset* with only the null or |
| 58 |
-- positive values. |
| 59 |
|
| 60 |
type Storage_Element is mod 2 ** Storage_Unit; |
| 61 |
for Storage_Element'Size use Storage_Unit; |
| 62 |
-- The type *Storage_Element* represents a byte |
| 63 |
|
| 64 |
pragma Universal_Aliasing (Storage_Element); |
| 65 |
-- This type is used by the expander to implement aggregate copy |
| 66 |
|
| 67 |
type Storage_Array is |
| 68 |
array (Storage_Offset range <>) of aliased Storage_Element; |
| 69 |
for Storage_Array'Component_Size use Storage_Unit; |
| 70 |
-- The type *Storage_Array* represents a part of the memory |
| 71 |
|
| 72 |
-- Address arithmetic |
| 73 |
|
| 74 |
function "+" (Left : Address; Right : Storage_Offset) return Address; |
| 75 |
function "+" (Left : Storage_Offset; Right : Address) return Address; |
| 76 |
pragma Import (Intrinsic, "+"); |
| 77 |
-- Returns the sum of ``Left`` and ``Right`` |
| 78 |
|
| 79 |
function "-" (Left : Address; Right : Storage_Offset) return Address; |
| 80 |
function "-" (Left, Right : Address) return Storage_Offset; |
| 81 |
pragma Import (Intrinsic, "-"); |
| 82 |
-- Returns the difference between ``Left`` and ``Right`` |
| 83 |
|
| 84 |
function "mod" |
| 85 |
(Left : Address; |
| 86 |
Right : Storage_Offset) return Storage_Offset; |
| 87 |
pragma Import (Intrinsic, "mod"); |
| 88 |
-- Returns the modulus between ``Left`` and ``Right`` |
| 89 |
|
| 90 |
-- Conversion to/from integers |
| 91 |
|
| 92 |
type Integer_Address is mod Memory_Size; |
| 93 |
-- Finally, *Integer_Address* is a non-private modular |
| 94 |
-- type that represents an address. |
| 95 |
|
| 96 |
function To_Address (Value : Integer_Address) return Address; |
| 97 |
pragma Import (Intrinsic, To_Address); |
| 98 |
-- Converts the *Integer_Address* ``Value`` to an *Address* |
| 99 |
|
| 100 |
function To_Integer (Value : Address) return Integer_Address; |
| 101 |
pragma Import (Intrinsic, To_Integer); |
| 102 |
-- Converts the *Address* ``Value`` to an *Integer_Address* |
| 103 |
|
| 104 |
end System.Storage_Elements; |