annotate gcc/ada/libgnat/s-pooglo.adb @ 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 -- S Y S T E M . P O O L _ G L O B A L --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 with System.Storage_Pools; use System.Storage_Pools;
kono
parents:
diff changeset
33 with System.Memory;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 package body System.Pool_Global is
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 package SSE renames System.Storage_Elements;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 --------------
kono
parents:
diff changeset
40 -- Allocate --
kono
parents:
diff changeset
41 --------------
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 overriding procedure Allocate
kono
parents:
diff changeset
44 (Pool : in out Unbounded_No_Reclaim_Pool;
kono
parents:
diff changeset
45 Address : out System.Address;
kono
parents:
diff changeset
46 Storage_Size : SSE.Storage_Count;
kono
parents:
diff changeset
47 Alignment : SSE.Storage_Count)
kono
parents:
diff changeset
48 is
kono
parents:
diff changeset
49 use SSE;
kono
parents:
diff changeset
50 pragma Warnings (Off, Pool);
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 Aligned_Size : Storage_Count := Storage_Size;
kono
parents:
diff changeset
53 Aligned_Address : System.Address;
kono
parents:
diff changeset
54 Allocated : System.Address;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 begin
kono
parents:
diff changeset
57 if Alignment > Standard'System_Allocator_Alignment then
kono
parents:
diff changeset
58 Aligned_Size := Aligned_Size + Alignment;
kono
parents:
diff changeset
59 end if;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 Allocated := Memory.Alloc (Memory.size_t (Aligned_Size));
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 -- The call to Alloc returns an address whose alignment is compatible
kono
parents:
diff changeset
64 -- with the worst case alignment requirement for the machine; thus the
kono
parents:
diff changeset
65 -- Alignment argument can be safely ignored.
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 if Allocated = Null_Address then
kono
parents:
diff changeset
68 raise Storage_Error;
kono
parents:
diff changeset
69 end if;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 -- Case where alignment requested is greater than the alignment that is
kono
parents:
diff changeset
72 -- guaranteed to be provided by the system allocator.
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 if Alignment > Standard'System_Allocator_Alignment then
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 -- Realign the returned address
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 Aligned_Address := To_Address
kono
parents:
diff changeset
79 (To_Integer (Allocated) + Integer_Address (Alignment)
kono
parents:
diff changeset
80 - (To_Integer (Allocated) mod Integer_Address (Alignment)));
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 -- Save the block address
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 declare
kono
parents:
diff changeset
85 Saved_Address : System.Address;
kono
parents:
diff changeset
86 pragma Import (Ada, Saved_Address);
kono
parents:
diff changeset
87 for Saved_Address'Address use
kono
parents:
diff changeset
88 Aligned_Address
kono
parents:
diff changeset
89 - Storage_Offset (System.Address'Size / Storage_Unit);
kono
parents:
diff changeset
90 begin
kono
parents:
diff changeset
91 Saved_Address := Allocated;
kono
parents:
diff changeset
92 end;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 Address := Aligned_Address;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 else
kono
parents:
diff changeset
97 Address := Allocated;
kono
parents:
diff changeset
98 end if;
kono
parents:
diff changeset
99 end Allocate;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 ----------------
kono
parents:
diff changeset
102 -- Deallocate --
kono
parents:
diff changeset
103 ----------------
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 overriding procedure Deallocate
kono
parents:
diff changeset
106 (Pool : in out Unbounded_No_Reclaim_Pool;
kono
parents:
diff changeset
107 Address : System.Address;
kono
parents:
diff changeset
108 Storage_Size : SSE.Storage_Count;
kono
parents:
diff changeset
109 Alignment : SSE.Storage_Count)
kono
parents:
diff changeset
110 is
kono
parents:
diff changeset
111 use System.Storage_Elements;
kono
parents:
diff changeset
112 pragma Warnings (Off, Pool);
kono
parents:
diff changeset
113 pragma Warnings (Off, Storage_Size);
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 begin
kono
parents:
diff changeset
116 -- Case where the alignment of the block exceeds the guaranteed
kono
parents:
diff changeset
117 -- alignment required by the system storage allocator, meaning that
kono
parents:
diff changeset
118 -- this was specially wrapped at allocation time.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 if Alignment > Standard'System_Allocator_Alignment then
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 -- Retrieve the block address
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 declare
kono
parents:
diff changeset
125 Saved_Address : System.Address;
kono
parents:
diff changeset
126 pragma Import (Ada, Saved_Address);
kono
parents:
diff changeset
127 for Saved_Address'Address use
kono
parents:
diff changeset
128 Address - Storage_Offset (System.Address'Size / Storage_Unit);
kono
parents:
diff changeset
129 begin
kono
parents:
diff changeset
130 Memory.Free (Saved_Address);
kono
parents:
diff changeset
131 end;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 else
kono
parents:
diff changeset
134 Memory.Free (Address);
kono
parents:
diff changeset
135 end if;
kono
parents:
diff changeset
136 end Deallocate;
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 ------------------
kono
parents:
diff changeset
139 -- Storage_Size --
kono
parents:
diff changeset
140 ------------------
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 overriding function Storage_Size
kono
parents:
diff changeset
143 (Pool : Unbounded_No_Reclaim_Pool)
kono
parents:
diff changeset
144 return SSE.Storage_Count
kono
parents:
diff changeset
145 is
kono
parents:
diff changeset
146 pragma Warnings (Off, Pool);
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 begin
kono
parents:
diff changeset
149 -- Intuitively, should return System.Memory_Size. But on Sun/Alsys,
kono
parents:
diff changeset
150 -- System.Memory_Size > System.Max_Int, which means all you can do with
kono
parents:
diff changeset
151 -- it is raise CONSTRAINT_ERROR...
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 return SSE.Storage_Count'Last;
kono
parents:
diff changeset
154 end Storage_Size;
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 end System.Pool_Global;