B.2 The Package Interfaces
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
Package Interfaces is the parent of several library packages that declare types and other entities useful for interfacing to foreign languages. It also contains some implementation-defined types that are useful across more than one language (in particular for interfacing to assembly language).
Static Semantics
2The library package Interfaces has the following skeletal declaration:
package Interfaces
with Pure is
4type Integer_n is range -2**(n-1) .. 2**(n-1) - 1; --2's complement
5type Unsigned_n is mod 2**n;
6function Shift_Left (Value : Unsigned_n; Amount : Natural)
return Unsigned_n;
function Shift_Right (Value : Unsigned_n; Amount : Natural)
return Unsigned_n;
function Shift_Right_Arithmetic (Value : Unsigned_n; Amount : Natural)
return Unsigned_n;
function Rotate_Left (Value : Unsigned_n; Amount : Natural)
return Unsigned_n;
function Rotate_Right (Value : Unsigned_n; Amount : Natural)
return Unsigned_n;
...
end Interfaces;
Implementation Requirements
7An implementation shall provide the following declarations in the visible part of package Interfaces:
- Signed and modular integer types of n bits, if supported by the target architecture, for each n that is at least the size of a storage element and that is a factor of the word size. The names of these types are of the form Integer_n for the signed types, and Unsigned_n for the modular types;
- For each such modular type in Interfaces, shifting and rotating subprograms as specified in the declaration of Interfaces above. These subprograms are Intrinsic. They operate on a bit-by-bit basis, using the binary representation of the value of the operands to yield a binary representation for the result. The Amount parameter gives the number of bits by which to shift or rotate. For shifting, zero bits are shifted in, except in the case of Shift_Right_Arithmetic, where one bits are shifted in if Value is at least half the modulus.
function Rotate_Left (Value : Unsigned_n; Amount : Natural)
return Unsigned_n is
Result : Unsigned_n := Value;
Bit : Unsigned_n range 0 .. 1;
begin
for Count in 1 .. Amount loop
Bit := Result/2**(n-1); -- High-bit of Result
Result := Result*2 + Bit;
end loop;
return Result;
end Rotate_Left;
9.d/5function Rotate_Right (Value : Unsigned_n; Amount : Natural)
return Unsigned_n is
Result : Unsigned_n := Value;
Bit : Unsigned_n range 0 .. 1;
begin
for Count in 1 .. Amount loop
Bit := Result mod 2; -- Low-bit of Result
Result := Result/2 + (Bit * 2**(n-1));
end loop;
return Result;
end Rotate_Right;
9.e/5function Shift_Left (Value : Unsigned_n; Amount : Natural)
return Unsigned_n is
Result : Unsigned_n := Value;
begin
for Count in 1 .. Amount loop
Result := Result * 2;
end loop;
return Result;
end Shift_Left;
9.f/5function Shift_Right (Value : Unsigned_n; Amount : Natural)
return Unsigned_n is
Result : Unsigned_n := Value;
begin
for Count in 1 .. Amount loop
Result := Result / 2;
end loop;
return Result;
end Shift_Right;
9.g/5function Shift_Right_Arithmetic (Value : Unsigned_n; Amount : Natural)
return Unsigned_n is
Result : Unsigned_n := Value;
Neg : constant Boolean :=
Result/2**(n-1) = 1; -- High-bit of Result
begin
for Count in 1 .. Amount loop
if Neg then
Result := Result / 2 + 2**(n-1);
else
Result := Result / 2;
end if;
end loop;
return Result;
end Shift_Right_Arithmetic;
- Floating point types corresponding to each floating point format fully supported by the hardware.
Implementation Permissions
11An implementation may provide implementation-defined library units that are children of Interfaces, and may add declarations to the visible part of Interfaces in addition to the ones defined above.
A child package of package Interfaces with the name of a convention may be provided independently of whether the convention is supported by the Convention aspect and vice versa. Such a child package should contain any declarations that would be useful for interfacing to the language (implementation) represented by the convention. Any declarations useful for interfacing to any language on the given hardware architecture should be provided directly in Interfaces.
Implementation Advice
12/2This paragraph was deleted.
An implementation supporting an interface to C, COBOL, or Fortran should provide the corresponding package or packages described in the following subclauses.
package Interfaces.Fortran renames Interfaces.This_Fortran;