annotate gcc/ada/libgnat/i-pacdec.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- I N T E R F A C E S . P A C K E D _ D E C I M A L --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- (Version for IBM Mainframe Packed Decimal Format) --
kono
parents:
diff changeset
9 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
10 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
11 -- --
kono
parents:
diff changeset
12 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
13 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
14 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
17 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
18 -- --
kono
parents:
diff changeset
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
20 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
21 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
22 -- --
kono
parents:
diff changeset
23 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
24 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
26 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
27 -- --
kono
parents:
diff changeset
28 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
29 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
30 -- --
kono
parents:
diff changeset
31 ------------------------------------------------------------------------------
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 -- This unit defines the packed decimal format used by GNAT in response to
kono
parents:
diff changeset
34 -- a specification of Machine_Radix 10 for a decimal fixed-point type. The
kono
parents:
diff changeset
35 -- format and operations are completely encapsulated in this unit, so all
kono
parents:
diff changeset
36 -- that is necessary to compile using different packed decimal formats is
kono
parents:
diff changeset
37 -- to replace this single unit.
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 -- Note that the compiler access the spec of this unit during compilation
kono
parents:
diff changeset
40 -- to obtain the data length that needs allocating, so the correct version
kono
parents:
diff changeset
41 -- of the spec must be available to the compiler, and must correspond to
kono
parents:
diff changeset
42 -- the spec and body made available to the linker, and all units of a given
kono
parents:
diff changeset
43 -- program must be compiled with the same version of the spec and body.
kono
parents:
diff changeset
44 -- This consistency will be enforced automatically using the normal binder
kono
parents:
diff changeset
45 -- consistency checking, since any unit declaring Machine_Radix 10 types or
kono
parents:
diff changeset
46 -- containing operations on such data will implicitly with Packed_Decimal.
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 with System;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 package Interfaces.Packed_Decimal is
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 ------------------------
kono
parents:
diff changeset
53 -- Format Description --
kono
parents:
diff changeset
54 ------------------------
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 -- IBM Mainframe packed decimal format uses a byte string of length one
kono
parents:
diff changeset
57 -- to 10 bytes, with the most significant byte first. Each byte contains
kono
parents:
diff changeset
58 -- two decimal digits (with the high order digit in the left nibble, and
kono
parents:
diff changeset
59 -- the low order four bits contain the sign, using the following code:
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -- 16#A# 2#1010# positive
kono
parents:
diff changeset
62 -- 16#B# 2#1011# negative
kono
parents:
diff changeset
63 -- 16#C# 2#1100# positive (preferred representation)
kono
parents:
diff changeset
64 -- 16#D# 2#1101# negative (preferred representation)
kono
parents:
diff changeset
65 -- 16#E# 2#1110# positive
kono
parents:
diff changeset
66 -- 16#F# 2#1011# positive
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 -- In this package, all six sign representations are interpreted as
kono
parents:
diff changeset
69 -- shown above when an operand is read, when an operand is written,
kono
parents:
diff changeset
70 -- the preferred representations are always used. Constraint_Error
kono
parents:
diff changeset
71 -- is raised if any other bit pattern is found in the sign nibble,
kono
parents:
diff changeset
72 -- or if a digit nibble contains an invalid digit code.
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 -- Some examples follow:
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 -- 05 76 3C +5763
kono
parents:
diff changeset
77 -- 00 01 1D -11
kono
parents:
diff changeset
78 -- 00 04 4E +44 (non-standard sign)
kono
parents:
diff changeset
79 -- 00 00 00 invalid (incorrect sign nibble)
kono
parents:
diff changeset
80 -- 0A 01 1C invalid (bad digit)
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 ------------------
kono
parents:
diff changeset
83 -- Length Array --
kono
parents:
diff changeset
84 ------------------
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 -- The following array must be declared in exactly the form shown, since
kono
parents:
diff changeset
87 -- the compiler accesses the associated tree to determine the size to be
kono
parents:
diff changeset
88 -- allocated to a machine radix 10 type, depending on the number of digits.
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 subtype Byte_Length is Positive range 1 .. 10;
kono
parents:
diff changeset
91 -- Range of possible byte lengths
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 Packed_Size : constant array (1 .. 18) of Byte_Length :=
kono
parents:
diff changeset
94 (01 => 01, -- Length in bytes for digits 1
kono
parents:
diff changeset
95 02 => 02, -- Length in bytes for digits 2
kono
parents:
diff changeset
96 03 => 02, -- Length in bytes for digits 2
kono
parents:
diff changeset
97 04 => 03, -- Length in bytes for digits 2
kono
parents:
diff changeset
98 05 => 03, -- Length in bytes for digits 2
kono
parents:
diff changeset
99 06 => 04, -- Length in bytes for digits 2
kono
parents:
diff changeset
100 07 => 04, -- Length in bytes for digits 2
kono
parents:
diff changeset
101 08 => 05, -- Length in bytes for digits 2
kono
parents:
diff changeset
102 09 => 05, -- Length in bytes for digits 2
kono
parents:
diff changeset
103 10 => 06, -- Length in bytes for digits 2
kono
parents:
diff changeset
104 11 => 06, -- Length in bytes for digits 2
kono
parents:
diff changeset
105 12 => 07, -- Length in bytes for digits 2
kono
parents:
diff changeset
106 13 => 07, -- Length in bytes for digits 2
kono
parents:
diff changeset
107 14 => 08, -- Length in bytes for digits 2
kono
parents:
diff changeset
108 15 => 08, -- Length in bytes for digits 2
kono
parents:
diff changeset
109 16 => 09, -- Length in bytes for digits 2
kono
parents:
diff changeset
110 17 => 09, -- Length in bytes for digits 2
kono
parents:
diff changeset
111 18 => 10); -- Length in bytes for digits 2
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -------------------------
kono
parents:
diff changeset
114 -- Conversion Routines --
kono
parents:
diff changeset
115 -------------------------
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 subtype D32 is Positive range 1 .. 9;
kono
parents:
diff changeset
118 -- Used to represent number of digits in a packed decimal value that
kono
parents:
diff changeset
119 -- can be represented in a 32-bit binary signed integer form.
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 subtype D64 is Positive range 10 .. 18;
kono
parents:
diff changeset
122 -- Used to represent number of digits in a packed decimal value that
kono
parents:
diff changeset
123 -- requires a 64-bit signed binary integer for representing all values.
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 function Packed_To_Int32 (P : System.Address; D : D32) return Integer_32;
kono
parents:
diff changeset
126 -- The argument P is the address of a packed decimal value and D is the
kono
parents:
diff changeset
127 -- number of digits (in the range 1 .. 9, as implied by the subtype).
kono
parents:
diff changeset
128 -- The returned result is the corresponding signed binary value. The
kono
parents:
diff changeset
129 -- exception Constraint_Error is raised if the input is invalid.
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 function Packed_To_Int64 (P : System.Address; D : D64) return Integer_64;
kono
parents:
diff changeset
132 -- The argument P is the address of a packed decimal value and D is the
kono
parents:
diff changeset
133 -- number of digits (in the range 10 .. 18, as implied by the subtype).
kono
parents:
diff changeset
134 -- The returned result is the corresponding signed binary value. The
kono
parents:
diff changeset
135 -- exception Constraint_Error is raised if the input is invalid.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 procedure Int32_To_Packed (V : Integer_32; P : System.Address; D : D32);
kono
parents:
diff changeset
138 -- The argument V is a signed binary integer, which is converted to
kono
parents:
diff changeset
139 -- packed decimal format and stored using P, the address of a packed
kono
parents:
diff changeset
140 -- decimal item of D digits (D is in the range 1-9). Constraint_Error
kono
parents:
diff changeset
141 -- is raised if V is out of range of this number of digits.
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 procedure Int64_To_Packed (V : Integer_64; P : System.Address; D : D64);
kono
parents:
diff changeset
144 -- The argument V is a signed binary integer, which is converted to
kono
parents:
diff changeset
145 -- packed decimal format and stored using P, the address of a packed
kono
parents:
diff changeset
146 -- decimal item of D digits (D is in the range 10-18). Constraint_Error
kono
parents:
diff changeset
147 -- is raised if V is out of range of this number of digits.
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 end Interfaces.Packed_Decimal;