OSDN Git Service

* sysdep.c: Problem discovered during IA64 VMS port.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-auxdec.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                       S Y S T E M . A U X _ D E C                        --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1996-2002 Free Software Foundation, Inc.          --
10 --                                                                          --
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 2,  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.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package contains definitions that are designed to be compatible
35 --  with the extra definitions in package System for DEC Ada implementations.
36
37 --  These definitions can be used directly by withing this package, or merged
38 --  with System using pragma Extend_System (Aux_DEC)
39
40 with Unchecked_Conversion;
41
42 package System.Aux_DEC is
43 pragma Elaborate_Body (Aux_DEC);
44
45    type Integer_8  is range -2 **  (8 - 1) .. +2 **  (8 - 1) - 1;
46    for Integer_8'Size  use  8;
47
48    type Integer_16 is range -2 ** (16 - 1) .. +2 ** (16 - 1) - 1;
49    for Integer_16'Size use 16;
50
51    type Integer_32 is range -2 ** (32 - 1) .. +2 ** (32 - 1) - 1;
52    for Integer_32'Size use 32;
53
54    type Integer_64 is range -2 ** (64 - 1) .. +2 ** (64 - 1) - 1;
55    for Integer_64'Size use 64;
56
57    type Largest_Integer is range Min_Int .. Max_Int;
58
59    type AST_Handler is limited private;
60
61    No_AST_Handler : constant AST_Handler;
62
63    type Type_Class is
64      (Type_Class_Enumeration,
65       Type_Class_Integer,
66       Type_Class_Fixed_Point,
67       Type_Class_Floating_Point,
68       Type_Class_Array,
69       Type_Class_Record,
70       Type_Class_Access,
71       Type_Class_Task,             -- also in Ada 95 protected
72       Type_Class_Address);
73
74    function "not" (Left        : Largest_Integer) return Largest_Integer;
75    function "and" (Left, Right : Largest_Integer) return Largest_Integer;
76    function "or"  (Left, Right : Largest_Integer) return Largest_Integer;
77    function "xor" (Left, Right : Largest_Integer) return Largest_Integer;
78
79    Address_Zero : constant Address;
80    No_Addr      : constant Address;
81    Address_Size : constant := Standard'Address_Size;
82
83    function "+" (Left : Address; Right : Integer) return Address;
84    function "+" (Left : Integer; Right : Address) return Address;
85    function "-" (Left : Address; Right : Address) return Integer;
86    function "-" (Left : Address; Right : Integer) return Address;
87
88    generic
89       type Target is private;
90    function Fetch_From_Address (A : Address) return Target;
91
92    generic
93       type Target is private;
94    procedure Assign_To_Address (A : Address; T : Target);
95
96    --  Floating point type declarations for VAX floating point data types
97
98    pragma Warnings (Off);
99
100    type F_Float is digits 6;
101    pragma Float_Representation (VAX_Float, F_Float);
102
103    type D_Float is digits 9;
104    pragma Float_Representation (Vax_Float, D_Float);
105
106    type G_Float is digits 15;
107    pragma Float_Representation (Vax_Float, G_Float);
108
109    --  Floating point type declarations for IEEE floating point data types
110
111    type IEEE_Single_Float is digits 6;
112    pragma Float_Representation (IEEE_Float, IEEE_Single_Float);
113
114    type IEEE_Double_Float is digits 15;
115    pragma Float_Representation (IEEE_Float, IEEE_Double_Float);
116
117    pragma Warnings (On);
118
119    Non_Ada_Error : exception;
120
121    --  Hardware-oriented types and functions
122
123    type Bit_Array is array (Integer range <>) of Boolean;
124    pragma Pack (Bit_Array);
125
126    subtype Bit_Array_8  is Bit_Array (0 ..  7);
127    subtype Bit_Array_16 is Bit_Array (0 .. 15);
128    subtype Bit_Array_32 is Bit_Array (0 .. 31);
129    subtype Bit_Array_64 is Bit_Array (0 .. 63);
130
131    type Unsigned_Byte is range 0 .. 255;
132    for  Unsigned_Byte'Size use 8;
133
134    function "not" (Left        : Unsigned_Byte) return Unsigned_Byte;
135    function "and" (Left, Right : Unsigned_Byte) return Unsigned_Byte;
136    function "or"  (Left, Right : Unsigned_Byte) return Unsigned_Byte;
137    function "xor" (Left, Right : Unsigned_Byte) return Unsigned_Byte;
138
139    function To_Unsigned_Byte (X : Bit_Array_8) return Unsigned_Byte;
140    function To_Bit_Array_8   (X : Unsigned_Byte) return Bit_Array_8;
141
142    type Unsigned_Byte_Array is array (Integer range <>) of Unsigned_Byte;
143
144    type Unsigned_Word is range 0 .. 65535;
145    for  Unsigned_Word'Size use 16;
146
147    function "not" (Left        : Unsigned_Word) return Unsigned_Word;
148    function "and" (Left, Right : Unsigned_Word) return Unsigned_Word;
149    function "or"  (Left, Right : Unsigned_Word) return Unsigned_Word;
150    function "xor" (Left, Right : Unsigned_Word) return Unsigned_Word;
151
152    function To_Unsigned_Word (X : Bit_Array_16) return Unsigned_Word;
153    function To_Bit_Array_16  (X : Unsigned_Word) return Bit_Array_16;
154
155    type Unsigned_Word_Array is array (Integer range <>) of Unsigned_Word;
156
157    type Unsigned_Longword is range -2_147_483_648 .. 2_147_483_647;
158    for  Unsigned_Longword'Size use 32;
159
160    function "not" (Left        : Unsigned_Longword) return Unsigned_Longword;
161    function "and" (Left, Right : Unsigned_Longword) return Unsigned_Longword;
162    function "or"  (Left, Right : Unsigned_Longword) return Unsigned_Longword;
163    function "xor" (Left, Right : Unsigned_Longword) return Unsigned_Longword;
164
165    function To_Unsigned_Longword (X : Bit_Array_32) return Unsigned_Longword;
166    function To_Bit_Array_32 (X : Unsigned_Longword) return Bit_Array_32;
167
168    type Unsigned_Longword_Array is
169       array (Integer range <>) of Unsigned_Longword;
170
171    type Unsigned_32 is range 0 .. 4_294_967_295;
172    for  Unsigned_32'Size use 32;
173
174    function "not" (Left        : Unsigned_32) return Unsigned_32;
175    function "and" (Left, Right : Unsigned_32) return Unsigned_32;
176    function "or"  (Left, Right : Unsigned_32) return Unsigned_32;
177    function "xor" (Left, Right : Unsigned_32) return Unsigned_32;
178
179    function To_Unsigned_32 (X : Bit_Array_32) return Unsigned_32;
180    function To_Bit_Array_32 (X : Unsigned_32) return Bit_Array_32;
181
182    type Unsigned_Quadword is record
183       L0 : Unsigned_Longword;
184       L1 : Unsigned_Longword;
185    end record;
186
187    for Unsigned_Quadword'Size      use 64;
188    for Unsigned_Quadword'Alignment use
189      Integer'Min (8, Standard'Maximum_Alignment);
190
191    function "not" (Left        : Unsigned_Quadword) return Unsigned_Quadword;
192    function "and" (Left, Right : Unsigned_Quadword) return Unsigned_Quadword;
193    function "or"  (Left, Right : Unsigned_Quadword) return Unsigned_Quadword;
194    function "xor" (Left, Right : Unsigned_Quadword) return Unsigned_Quadword;
195
196    function To_Unsigned_Quadword (X : Bit_Array_64) return Unsigned_Quadword;
197    function To_Bit_Array_64 (X : Unsigned_Quadword) return Bit_Array_64;
198
199    type Unsigned_Quadword_Array is
200       array (Integer range <>) of Unsigned_Quadword;
201
202    function To_Address      (X : Integer)           return Address;
203    pragma Pure_Function (To_Address);
204
205    function To_Address_Long (X : Unsigned_Longword) return Address;
206    pragma Pure_Function (To_Address_Long);
207
208    function To_Integer      (X : Address)           return Integer;
209
210    function To_Unsigned_Longword (X : Address)     return Unsigned_Longword;
211    function To_Unsigned_Longword (X : AST_Handler) return Unsigned_Longword;
212
213    --  Conventional names for static subtypes of type UNSIGNED_LONGWORD
214
215    subtype Unsigned_1  is Unsigned_Longword range 0 .. 2** 1-1;
216    subtype Unsigned_2  is Unsigned_Longword range 0 .. 2** 2-1;
217    subtype Unsigned_3  is Unsigned_Longword range 0 .. 2** 3-1;
218    subtype Unsigned_4  is Unsigned_Longword range 0 .. 2** 4-1;
219    subtype Unsigned_5  is Unsigned_Longword range 0 .. 2** 5-1;
220    subtype Unsigned_6  is Unsigned_Longword range 0 .. 2** 6-1;
221    subtype Unsigned_7  is Unsigned_Longword range 0 .. 2** 7-1;
222    subtype Unsigned_8  is Unsigned_Longword range 0 .. 2** 8-1;
223    subtype Unsigned_9  is Unsigned_Longword range 0 .. 2** 9-1;
224    subtype Unsigned_10 is Unsigned_Longword range 0 .. 2**10-1;
225    subtype Unsigned_11 is Unsigned_Longword range 0 .. 2**11-1;
226    subtype Unsigned_12 is Unsigned_Longword range 0 .. 2**12-1;
227    subtype Unsigned_13 is Unsigned_Longword range 0 .. 2**13-1;
228    subtype Unsigned_14 is Unsigned_Longword range 0 .. 2**14-1;
229    subtype Unsigned_15 is Unsigned_Longword range 0 .. 2**15-1;
230    subtype Unsigned_16 is Unsigned_Longword range 0 .. 2**16-1;
231    subtype Unsigned_17 is Unsigned_Longword range 0 .. 2**17-1;
232    subtype Unsigned_18 is Unsigned_Longword range 0 .. 2**18-1;
233    subtype Unsigned_19 is Unsigned_Longword range 0 .. 2**19-1;
234    subtype Unsigned_20 is Unsigned_Longword range 0 .. 2**20-1;
235    subtype Unsigned_21 is Unsigned_Longword range 0 .. 2**21-1;
236    subtype Unsigned_22 is Unsigned_Longword range 0 .. 2**22-1;
237    subtype Unsigned_23 is Unsigned_Longword range 0 .. 2**23-1;
238    subtype Unsigned_24 is Unsigned_Longword range 0 .. 2**24-1;
239    subtype Unsigned_25 is Unsigned_Longword range 0 .. 2**25-1;
240    subtype Unsigned_26 is Unsigned_Longword range 0 .. 2**26-1;
241    subtype Unsigned_27 is Unsigned_Longword range 0 .. 2**27-1;
242    subtype Unsigned_28 is Unsigned_Longword range 0 .. 2**28-1;
243    subtype Unsigned_29 is Unsigned_Longword range 0 .. 2**29-1;
244    subtype Unsigned_30 is Unsigned_Longword range 0 .. 2**30-1;
245    subtype Unsigned_31 is Unsigned_Longword range 0 .. 2**31-1;
246
247    --  Function for obtaining global symbol values
248
249    function Import_Value         (Symbol : String) return Unsigned_Longword;
250    function Import_Address       (Symbol : String) return Address;
251    function Import_Largest_Value (Symbol : String) return Largest_Integer;
252
253    pragma Import (Intrinsic, Import_Value);
254    pragma Import (Intrinsic, Import_Address);
255    pragma Import (Intrinsic, Import_Largest_Value);
256
257    --  For the following declarations, note that the declaration without
258    --  a Retry_Count parameter means to retry infinitely. A value of zero
259    --  for the Retry_Count parameter means do not retry.
260
261    --  Interlocked-instruction procedures
262
263    procedure Clear_Interlocked
264      (Bit       : in out Boolean;
265       Old_Value : out Boolean);
266
267    procedure Set_Interlocked
268      (Bit       : in out Boolean;
269       Old_Value : out Boolean);
270
271    type Aligned_Word is record
272       Value : Short_Integer;
273    end record;
274
275    for Aligned_Word'Alignment use
276      Integer'Min (2, Standard'Maximum_Alignment);
277
278    procedure Clear_Interlocked
279      (Bit          : in out Boolean;
280       Old_Value    : out Boolean;
281       Retry_Count  : in Natural;
282       Success_Flag : out Boolean);
283
284    procedure Set_Interlocked
285      (Bit          : in out Boolean;
286       Old_Value    : out Boolean;
287       Retry_Count  : in Natural;
288       Success_Flag : out Boolean);
289
290    procedure Add_Interlocked
291      (Addend       : in Short_Integer;
292       Augend       : in out Aligned_Word;
293       Sign         : out Integer);
294
295    type Aligned_Integer is record
296       Value : Integer;
297    end record;
298
299    for Aligned_Integer'Alignment use
300      Integer'Min (4, Standard'Maximum_Alignment);
301
302    type Aligned_Long_Integer is record
303       Value : Long_Integer;
304    end record;
305
306    for Aligned_Long_Integer'Alignment use
307      Integer'Min (8, Standard'Maximum_Alignment);
308
309    --  For the following declarations, note that the declaration without
310    --  a Retry_Count parameter mean to retry infinitely. A value of zero
311    --  for the Retry_Count means do not retry.
312
313    procedure Add_Atomic
314      (To           : in out Aligned_Integer;
315       Amount       : in Integer);
316
317    procedure Add_Atomic
318      (To           : in out Aligned_Integer;
319       Amount       : in Integer;
320       Retry_Count  : in Natural;
321       Old_Value    : out Integer;
322       Success_Flag : out Boolean);
323
324    procedure Add_Atomic
325      (To           : in out Aligned_Long_Integer;
326       Amount       : in Long_Integer);
327
328    procedure Add_Atomic
329      (To           : in out Aligned_Long_Integer;
330       Amount       : in Long_Integer;
331       Retry_Count  : in Natural;
332       Old_Value    : out Long_Integer;
333       Success_Flag : out Boolean);
334
335    procedure And_Atomic
336      (To           : in out Aligned_Integer;
337       From         : in Integer);
338
339    procedure And_Atomic
340      (To           : in out Aligned_Integer;
341       From         : in Integer;
342       Retry_Count  : in Natural;
343       Old_Value    : out Integer;
344       Success_Flag : out Boolean);
345
346    procedure And_Atomic
347      (To           : in out Aligned_Long_Integer;
348       From         : in Long_Integer);
349
350    procedure And_Atomic
351      (To           : in out Aligned_Long_Integer;
352       From         : in Long_Integer;
353       Retry_Count  : in Natural;
354       Old_Value    : out Long_Integer;
355       Success_Flag : out Boolean);
356
357    procedure Or_Atomic
358      (To           : in out Aligned_Integer;
359       From         : in Integer);
360
361    procedure Or_Atomic
362      (To           : in out Aligned_Integer;
363       From         : in Integer;
364       Retry_Count  : in Natural;
365       Old_Value    : out Integer;
366       Success_Flag : out Boolean);
367
368    procedure Or_Atomic
369      (To           : in out Aligned_Long_Integer;
370       From         : in Long_Integer);
371
372    procedure Or_Atomic
373      (To           : in out Aligned_Long_Integer;
374       From         : in Long_Integer;
375       Retry_Count  : in Natural;
376       Old_Value    : out Long_Integer;
377       Success_Flag : out Boolean);
378
379    type Insq_Status is
380      (Fail_No_Lock, OK_Not_First, OK_First);
381
382    for Insq_Status use
383      (Fail_No_Lock => -1,
384       OK_Not_First => 0,
385       OK_First     => +1);
386
387    type Remq_Status is (
388      Fail_No_Lock,
389      Fail_Was_Empty,
390      OK_Not_Empty,
391      OK_Empty);
392
393    for Remq_Status use
394      (Fail_No_Lock   => -1,
395       Fail_Was_Empty => 0,
396       OK_Not_Empty   => +1,
397       OK_Empty       => +2);
398
399    procedure Insqhi
400      (Item   : in  Address;
401       Header : in  Address;
402       Status : out Insq_Status);
403
404    procedure Remqhi
405      (Header : in  Address;
406       Item   : out Address;
407       Status : out Remq_Status);
408
409    procedure Insqti
410      (Item   : in  Address;
411       Header : in  Address;
412       Status : out Insq_Status);
413
414    procedure Remqti
415      (Header : in  Address;
416       Item   : out Address;
417       Status : out Remq_Status);
418
419 private
420
421    Address_Zero : constant Address := Null_Address;
422    No_Addr      : constant Address := Null_Address;
423
424    --  An AST_Handler value is from a typing point of view simply a pointer
425    --  to a procedure taking a single 64bit parameter. However, this
426    --  is a bit misleading, because the data that this pointer references is
427    --  highly stylized. See body of System.AST_Handling for full details.
428
429    type AST_Handler is access procedure (Param : Long_Integer);
430    No_AST_Handler : constant AST_Handler := null;
431
432    --  Other operators have incorrect profiles. It would be nice to make
433    --  them intrinsic, since the backend can handle them, but the front
434    --  end is not prepared to deal with them, so at least inline them.
435
436    pragma Inline_Always ("+");
437    pragma Inline_Always ("-");
438    pragma Inline_Always ("not");
439    pragma Inline_Always ("and");
440    pragma Inline_Always ("or");
441    pragma Inline_Always ("xor");
442
443    --  Other inlined subprograms
444
445    pragma Inline_Always (Fetch_From_Address);
446    pragma Inline_Always (Assign_To_Address);
447
448    --  Synchronization related subprograms. These are declared to have
449    --  convention C so that the critical parameters are passed by reference.
450    --  Without this, the parameters are passed by copy, creating load/store
451    --  race conditions. We also inline them, since this seems more in the
452    --  spirit of the original (hardware instrinsic) routines.
453
454    pragma Convention (C, Clear_Interlocked);
455    pragma Inline_Always (Clear_Interlocked);
456
457    pragma Convention (C, Set_Interlocked);
458    pragma Inline_Always (Set_Interlocked);
459
460    pragma Convention (C, Add_Interlocked);
461    pragma Inline_Always (Add_Interlocked);
462
463    pragma Convention (C, Add_Atomic);
464    pragma Inline_Always (Add_Atomic);
465
466    pragma Convention (C, And_Atomic);
467    pragma Inline_Always (And_Atomic);
468
469    pragma Convention (C, Or_Atomic);
470    pragma Inline_Always (Or_Atomic);
471
472    --  Provide proper unchecked conversion definitions for transfer
473    --  functions. Note that we need this level of indirection because
474    --  the formal parameter name is X and not Source (and this is indeed
475    --  detectable by a program)
476
477    function To_Unsigned_Byte_A is new
478      Unchecked_Conversion (Bit_Array_8, Unsigned_Byte);
479
480    function To_Unsigned_Byte (X : Bit_Array_8) return Unsigned_Byte
481      renames To_Unsigned_Byte_A;
482
483    function To_Bit_Array_8_A is new
484      Unchecked_Conversion (Unsigned_Byte, Bit_Array_8);
485
486    function To_Bit_Array_8 (X : Unsigned_Byte) return Bit_Array_8
487      renames To_Bit_Array_8_A;
488
489    function To_Unsigned_Word_A is new
490      Unchecked_Conversion (Bit_Array_16, Unsigned_Word);
491
492    function To_Unsigned_Word (X : Bit_Array_16) return Unsigned_Word
493      renames To_Unsigned_Word_A;
494
495    function To_Bit_Array_16_A is new
496      Unchecked_Conversion (Unsigned_Word, Bit_Array_16);
497
498    function To_Bit_Array_16 (X : Unsigned_Word) return Bit_Array_16
499      renames To_Bit_Array_16_A;
500
501    function To_Unsigned_Longword_A is new
502      Unchecked_Conversion (Bit_Array_32, Unsigned_Longword);
503
504    function To_Unsigned_Longword (X : Bit_Array_32) return Unsigned_Longword
505      renames To_Unsigned_Longword_A;
506
507    function To_Bit_Array_32_A is new
508      Unchecked_Conversion (Unsigned_Longword, Bit_Array_32);
509
510    function To_Bit_Array_32 (X : Unsigned_Longword) return Bit_Array_32
511      renames To_Bit_Array_32_A;
512
513    function To_Unsigned_32_A is new
514      Unchecked_Conversion (Bit_Array_32, Unsigned_32);
515
516    function To_Unsigned_32 (X : Bit_Array_32) return Unsigned_32
517      renames To_Unsigned_32_A;
518
519    function To_Bit_Array_32_A is new
520      Unchecked_Conversion (Unsigned_32, Bit_Array_32);
521
522    function To_Bit_Array_32 (X : Unsigned_32) return Bit_Array_32
523      renames To_Bit_Array_32_A;
524
525    function To_Unsigned_Quadword_A is new
526      Unchecked_Conversion (Bit_Array_64, Unsigned_Quadword);
527
528    function To_Unsigned_Quadword (X : Bit_Array_64) return Unsigned_Quadword
529      renames To_Unsigned_Quadword_A;
530
531    function To_Bit_Array_64_A is new
532      Unchecked_Conversion (Unsigned_Quadword, Bit_Array_64);
533
534    function To_Bit_Array_64 (X : Unsigned_Quadword) return Bit_Array_64
535      renames To_Bit_Array_64_A;
536
537    pragma Warnings (Off);
538    --  Turn warnings off. This is needed for systems with 64-bit integers,
539    --  where some of these operations are of dubious meaning, but we do not
540    --  want warnings when we compile on such systems.
541
542    function To_Address_A is new
543      Unchecked_Conversion (Integer, Address);
544    pragma Pure_Function (To_Address_A);
545
546    function To_Address (X : Integer) return Address
547      renames To_Address_A;
548    pragma Pure_Function (To_Address);
549
550    function To_Address_Long_A is new
551      Unchecked_Conversion (Unsigned_Longword, Address);
552    pragma Pure_Function (To_Address_Long_A);
553
554    function To_Address_Long (X : Unsigned_Longword) return Address
555      renames To_Address_Long_A;
556    pragma Pure_Function (To_Address_Long);
557
558    function To_Integer_A is new
559      Unchecked_Conversion (Address, Integer);
560
561    function To_Integer (X : Address) return Integer
562      renames To_Integer_A;
563
564    function To_Unsigned_Longword_A is new
565      Unchecked_Conversion (Address, Unsigned_Longword);
566
567    function To_Unsigned_Longword (X : Address) return Unsigned_Longword
568      renames To_Unsigned_Longword_A;
569
570    function To_Unsigned_Longword_A is new
571      Unchecked_Conversion (AST_Handler, Unsigned_Longword);
572
573    function To_Unsigned_Longword (X : AST_Handler) return Unsigned_Longword
574      renames To_Unsigned_Longword_A;
575
576    pragma Warnings (On);
577
578 end System.Aux_DEC;