* gimplify.c (find_single_pointer_decl_1): New static function.
[official-gcc.git] / gcc / ada / s-pooloc.adb
blob3a7875c580c565f2b12ce85ff29f1baa164cf1e2
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . P O O L _ L O C A L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 ------------------------------------------------------------------------------
34 with System.Memory;
35 with System.Storage_Elements;
37 with Unchecked_Conversion;
39 package body System.Pool_Local is
41 package SSE renames System.Storage_Elements;
42 use type SSE.Storage_Offset;
44 Pointer_Size : constant SSE.Storage_Offset := Address'Size / Storage_Unit;
45 Pointers_Size : constant SSE.Storage_Offset := 2 * Pointer_Size;
47 type Acc_Address is access all Address;
48 function To_Acc_Address is new Unchecked_Conversion (Address, Acc_Address);
50 -----------------------
51 -- Local Subprograms --
52 -----------------------
54 function Next (A : Address) return Acc_Address;
55 pragma Inline (Next);
56 -- Given an address of a block, return an access to the next block
58 function Prev (A : Address) return Acc_Address;
59 pragma Inline (Prev);
60 -- Given an address of a block, return an access to the previous block
62 --------------
63 -- Allocate --
64 --------------
66 procedure Allocate
67 (Pool : in out Unbounded_Reclaim_Pool;
68 Address : out System.Address;
69 Storage_Size : SSE.Storage_Count;
70 Alignment : SSE.Storage_Count)
72 pragma Warnings (Off, Alignment);
74 Allocated : constant System.Address :=
75 Memory.Alloc
76 (Memory.size_t (Storage_Size + Pointers_Size));
78 begin
79 -- The call to Alloc returns an address whose alignment is compatible
80 -- with the worst case alignment requirement for the machine; thus the
81 -- Alignment argument can be safely ignored.
83 if Allocated = Null_Address then
84 raise Storage_Error;
85 else
86 Address := Allocated + Pointers_Size;
87 Next (Allocated).all := Pool.First;
88 Prev (Allocated).all := Null_Address;
90 if Pool.First /= Null_Address then
91 Prev (Pool.First).all := Allocated;
92 end if;
94 Pool.First := Allocated;
95 end if;
96 end Allocate;
98 ----------------
99 -- Deallocate --
100 ----------------
102 procedure Deallocate
103 (Pool : in out Unbounded_Reclaim_Pool;
104 Address : System.Address;
105 Storage_Size : SSE.Storage_Count;
106 Alignment : SSE.Storage_Count)
108 pragma Warnings (Off, Storage_Size);
109 pragma Warnings (Off, Alignment);
111 Allocated : constant System.Address := Address - Pointers_Size;
113 begin
114 if Prev (Allocated).all = Null_Address then
115 Pool.First := Next (Allocated).all;
116 Prev (Pool.First).all := Null_Address;
117 else
118 Next (Prev (Allocated).all).all := Next (Allocated).all;
119 end if;
121 if Next (Allocated).all /= Null_Address then
122 Prev (Next (Allocated).all).all := Prev (Allocated).all;
123 end if;
125 Memory.Free (Allocated);
126 end Deallocate;
128 --------------
129 -- Finalize --
130 --------------
132 procedure Finalize (Pool : in out Unbounded_Reclaim_Pool) is
133 N : System.Address := Pool.First;
134 Allocated : System.Address;
136 begin
137 while N /= Null_Address loop
138 Allocated := N;
139 N := Next (N).all;
140 Memory.Free (Allocated);
141 end loop;
142 end Finalize;
144 ----------
145 -- Next --
146 ----------
148 function Next (A : Address) return Acc_Address is
149 begin
150 return To_Acc_Address (A);
151 end Next;
153 ----------
154 -- Prev --
155 ----------
157 function Prev (A : Address) return Acc_Address is
158 begin
159 return To_Acc_Address (A + Pointer_Size);
160 end Prev;
162 end System.Pool_Local;