Daily bump.
[official-gcc.git] / gcc / ada / i-pacdec.ads
blobff7b9c13491ca62caf6b773af62ea7f4527d6a06
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- I N T E R F A C E S . P A C K E D _ D E C I M A L --
6 -- --
7 -- S p e c --
8 -- (Version for IBM Mainframe Packed Decimal Format) --
9 -- --
10 -- $Revision: 1.1.16.1 $
11 -- --
12 -- Copyright (C) 1992,1993,1994,1995 Free Software Foundation, Inc. --
13 -- --
14 -- GNAT is free software; you can redistribute it and/or modify it under --
15 -- terms of the GNU General Public License as published by the Free Soft- --
16 -- ware Foundation; either version 2, or (at your option) any later ver- --
17 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
18 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
19 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
20 -- for more details. You should have received a copy of the GNU General --
21 -- Public License distributed with GNAT; see file COPYING. If not, write --
22 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
23 -- MA 02111-1307, USA. --
24 -- --
25 -- As a special exception, if other files instantiate generics from this --
26 -- unit, or you link this unit with other files to produce an executable, --
27 -- this unit does not by itself cause the resulting executable to be --
28 -- covered by the GNU General Public License. This exception does not --
29 -- however invalidate any other reasons why the executable file might be --
30 -- covered by the GNU Public License. --
31 -- --
32 -- GNAT was originally developed by the GNAT team at New York University. --
33 -- Extensive contributions were provided by Ada Core Technologies Inc. --
34 -- --
36 -- This unit defines the packed decimal format used by GNAT in response to
37 -- a specication of Machine_Radix 10 for a decimal fixed-point type. The
38 -- format and operations are completely encapsulated in this unit, so all
39 -- that is necessary to compile using different packed decimal formats is
40 -- to replace this single unit.
42 -- Note that the compiler access the spec of this unit during compilation
43 -- to obtain the data length that needs allocating, so the correct version
44 -- of the spec must be available to the compiler, and must correspond to
45 -- the spec and body made available to the linker, and all units of a given
46 -- program must be compiled with the same version of the spec and body.
47 -- This consistency will be enforced automatically using the normal binder
48 -- consistency checking, since any unit declaring Machine_Radix 10 types or
49 -- containing operations on such data will implicitly with Packed_Decimal.
51 with System;
53 package Interfaces.Packed_Decimal is
55 ------------------------
56 -- Format Description --
57 ------------------------
59 -- IBM Mainframe packed decimal format uses a byte string of length one
60 -- to 10 bytes, with the most significant byte first. Each byte contains
61 -- two decimal digits (with the high order digit in the left nibble, and
62 -- the low order four bits contain the sign, using the following code:
64 -- 16#A# 2#1010# positive
65 -- 16#B# 2#1011# negative
66 -- 16#C# 2#1100# positive (preferred representation)
67 -- 16#D# 2#1101# negative (preferred representation)
68 -- 16#E# 2#1110# positive
69 -- 16#F# 2#1011# positive
71 -- In this package, all six sign representations are interpreted as
72 -- shown above when an operand is read, when an operand is written,
73 -- the preferred representations are always used. Constraint_Error
74 -- is raised if any other bit pattern is found in the sign nibble,
75 -- or if a digit nibble contains an invalid digit code.
77 -- Some examples follow:
79 -- 05 76 3C +5763
80 -- 00 01 1D -11
81 -- 00 04 4E +44 (non-standard sign)
82 -- 00 00 00 invalid (incorrect sign nibble)
83 -- 0A 01 1C invalid (bad digit)
85 ------------------
86 -- Length Array --
87 ------------------
89 -- The following array must be declared in exactly the form shown, since
90 -- the compiler accesses the associated tree to determine the size to be
91 -- allocated to a machine radix 10 type, depending on the number of digits.
93 subtype Byte_Length is Positive range 1 .. 10;
94 -- Range of possible byte lengths
96 Packed_Size : constant array (1 .. 18) of Byte_Length :=
97 (01 => 01, -- Length in bytes for digits 1
98 02 => 02, -- Length in bytes for digits 2
99 03 => 02, -- Length in bytes for digits 2
100 04 => 03, -- Length in bytes for digits 2
101 05 => 03, -- Length in bytes for digits 2
102 06 => 04, -- Length in bytes for digits 2
103 07 => 04, -- Length in bytes for digits 2
104 08 => 05, -- Length in bytes for digits 2
105 09 => 05, -- Length in bytes for digits 2
106 10 => 06, -- Length in bytes for digits 2
107 11 => 06, -- Length in bytes for digits 2
108 12 => 07, -- Length in bytes for digits 2
109 13 => 07, -- Length in bytes for digits 2
110 14 => 08, -- Length in bytes for digits 2
111 15 => 08, -- Length in bytes for digits 2
112 16 => 09, -- Length in bytes for digits 2
113 17 => 09, -- Length in bytes for digits 2
114 18 => 10); -- Length in bytes for digits 2
116 -------------------------
117 -- Conversion Routines --
118 -------------------------
120 subtype D32 is Positive range 1 .. 9;
121 -- Used to represent number of digits in a packed decimal value that
122 -- can be represented in a 32-bit binary signed integer form.
124 subtype D64 is Positive range 10 .. 18;
125 -- Used to represent number of digits in a packed decimal value that
126 -- requires a 64-bit signed binary integer for representing all values.
128 function Packed_To_Int32 (P : System.Address; D : D32) return Integer_32;
129 -- The argument P is the address of a packed decimal value and D is the
130 -- number of digits (in the range 1 .. 9, as implied by the subtype).
131 -- The returned result is the corresponding signed binary value. The
132 -- exception Constraint_Error is raised if the input is invalid.
134 function Packed_To_Int64 (P : System.Address; D : D64) return Integer_64;
135 -- The argument P is the address of a packed decimal value and D is the
136 -- number of digits (in the range 10 .. 18, as implied by the subtype).
137 -- The returned result is the corresponding signed binary value. The
138 -- exception Constraint_Error is raised if the input is invalid.
140 procedure Int32_To_Packed (V : Integer_32; P : System.Address; D : D32);
141 -- The argument V is a signed binary integer, which is converted to
142 -- packed decimal format and stored using P, the address of a packed
143 -- decimal item of D digits (D is in the range 1-9). Constraint_Error
144 -- is raised if V is out of range of this number of digits.
146 procedure Int64_To_Packed (V : Integer_64; P : System.Address; D : D64);
147 -- The argument V is a signed binary integer, which is converted to
148 -- packed decimal format and stored using P, the address of a packed
149 -- decimal item of D digits (D is in the range 10-18). Constraint_Error
150 -- is raised if V is out of range of this number of digits.
152 end Interfaces.Packed_Decimal;