annotate gcc/ada/libgnat/s-pooloc.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 _ L O C 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.Memory;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 with Ada.Unchecked_Conversion;
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 package body System.Pool_Local is
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 package SSE renames System.Storage_Elements;
kono
parents:
diff changeset
39 use type SSE.Storage_Offset;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 Pointer_Size : constant SSE.Storage_Offset := Address'Size / Storage_Unit;
kono
parents:
diff changeset
42 Pointers_Size : constant SSE.Storage_Offset := 2 * Pointer_Size;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 type Acc_Address is access all Address;
kono
parents:
diff changeset
45 function To_Acc_Address is
kono
parents:
diff changeset
46 new Ada.Unchecked_Conversion (Address, Acc_Address);
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -----------------------
kono
parents:
diff changeset
49 -- Local Subprograms --
kono
parents:
diff changeset
50 -----------------------
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 function Next (A : Address) return Acc_Address;
kono
parents:
diff changeset
53 pragma Inline (Next);
kono
parents:
diff changeset
54 -- Given an address of a block, return an access to the next block
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 function Prev (A : Address) return Acc_Address;
kono
parents:
diff changeset
57 pragma Inline (Prev);
kono
parents:
diff changeset
58 -- Given an address of a block, return an access to the previous block
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 --------------
kono
parents:
diff changeset
61 -- Allocate --
kono
parents:
diff changeset
62 --------------
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 procedure Allocate
kono
parents:
diff changeset
65 (Pool : in out Unbounded_Reclaim_Pool;
kono
parents:
diff changeset
66 Address : out System.Address;
kono
parents:
diff changeset
67 Storage_Size : SSE.Storage_Count;
kono
parents:
diff changeset
68 Alignment : SSE.Storage_Count)
kono
parents:
diff changeset
69 is
kono
parents:
diff changeset
70 pragma Warnings (Off, Alignment);
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 Allocated : constant System.Address :=
kono
parents:
diff changeset
73 Memory.Alloc
kono
parents:
diff changeset
74 (Memory.size_t (Storage_Size + Pointers_Size));
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 begin
kono
parents:
diff changeset
77 -- The call to Alloc returns an address whose alignment is compatible
kono
parents:
diff changeset
78 -- with the worst case alignment requirement for the machine; thus the
kono
parents:
diff changeset
79 -- Alignment argument can be safely ignored.
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 if Allocated = Null_Address then
kono
parents:
diff changeset
82 raise Storage_Error;
kono
parents:
diff changeset
83 else
kono
parents:
diff changeset
84 Address := Allocated + Pointers_Size;
kono
parents:
diff changeset
85 Next (Allocated).all := Pool.First;
kono
parents:
diff changeset
86 Prev (Allocated).all := Null_Address;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 if Pool.First /= Null_Address then
kono
parents:
diff changeset
89 Prev (Pool.First).all := Allocated;
kono
parents:
diff changeset
90 end if;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 Pool.First := Allocated;
kono
parents:
diff changeset
93 end if;
kono
parents:
diff changeset
94 end Allocate;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 ----------------
kono
parents:
diff changeset
97 -- Deallocate --
kono
parents:
diff changeset
98 ----------------
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 procedure Deallocate
kono
parents:
diff changeset
101 (Pool : in out Unbounded_Reclaim_Pool;
kono
parents:
diff changeset
102 Address : System.Address;
kono
parents:
diff changeset
103 Storage_Size : SSE.Storage_Count;
kono
parents:
diff changeset
104 Alignment : SSE.Storage_Count)
kono
parents:
diff changeset
105 is
kono
parents:
diff changeset
106 pragma Warnings (Off, Storage_Size);
kono
parents:
diff changeset
107 pragma Warnings (Off, Alignment);
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 Allocated : constant System.Address := Address - Pointers_Size;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 begin
kono
parents:
diff changeset
112 if Prev (Allocated).all = Null_Address then
kono
parents:
diff changeset
113 Pool.First := Next (Allocated).all;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 -- Comment needed
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 if Pool.First /= Null_Address then
kono
parents:
diff changeset
118 Prev (Pool.First).all := Null_Address;
kono
parents:
diff changeset
119 end if;
kono
parents:
diff changeset
120 else
kono
parents:
diff changeset
121 Next (Prev (Allocated).all).all := Next (Allocated).all;
kono
parents:
diff changeset
122 end if;
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 if Next (Allocated).all /= Null_Address then
kono
parents:
diff changeset
125 Prev (Next (Allocated).all).all := Prev (Allocated).all;
kono
parents:
diff changeset
126 end if;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 Memory.Free (Allocated);
kono
parents:
diff changeset
129 end Deallocate;
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 --------------
kono
parents:
diff changeset
132 -- Finalize --
kono
parents:
diff changeset
133 --------------
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 procedure Finalize (Pool : in out Unbounded_Reclaim_Pool) is
kono
parents:
diff changeset
136 N : System.Address := Pool.First;
kono
parents:
diff changeset
137 Allocated : System.Address;
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 begin
kono
parents:
diff changeset
140 while N /= Null_Address loop
kono
parents:
diff changeset
141 Allocated := N;
kono
parents:
diff changeset
142 N := Next (N).all;
kono
parents:
diff changeset
143 Memory.Free (Allocated);
kono
parents:
diff changeset
144 end loop;
kono
parents:
diff changeset
145 end Finalize;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 ----------
kono
parents:
diff changeset
148 -- Next --
kono
parents:
diff changeset
149 ----------
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 function Next (A : Address) return Acc_Address is
kono
parents:
diff changeset
152 begin
kono
parents:
diff changeset
153 return To_Acc_Address (A);
kono
parents:
diff changeset
154 end Next;
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 ----------
kono
parents:
diff changeset
157 -- Prev --
kono
parents:
diff changeset
158 ----------
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 function Prev (A : Address) return Acc_Address is
kono
parents:
diff changeset
161 begin
kono
parents:
diff changeset
162 return To_Acc_Address (A + Pointer_Size);
kono
parents:
diff changeset
163 end Prev;
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 end System.Pool_Local;