OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / 1ssecsta.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --               S Y S T E M . S E C O N D A R Y _ S T A C K                --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                                                                          --
10 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- As a special exception,  if other files  instantiate  generics from this --
24 -- unit, or you link  this unit with other files  to produce an executable, --
25 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
26 -- covered  by the  GNU  General  Public  License.  This exception does not --
27 -- however invalidate  any other reasons why  the executable file  might be --
28 -- covered by the  GNU Public License.                                      --
29 --                                                                          --
30 -- GNAT was originally developed  by the GNAT team at  New York University. --
31 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 --  This is the HI-E version of this package.
36
37 with Unchecked_Conversion;
38
39 package body System.Secondary_Stack is
40
41    use type SSE.Storage_Offset;
42
43    type Memory is array (Mark_Id range <>) of SSE.Storage_Element;
44
45    type Stack_Id is record
46       Top  : Mark_Id;
47       Last : Mark_Id;
48       Mem  : Memory (1 .. Mark_Id'Last);
49    end record;
50    pragma Suppress_Initialization (Stack_Id);
51
52    type Stack_Ptr is access Stack_Id;
53
54    function From_Addr is new Unchecked_Conversion (Address, Stack_Ptr);
55
56    function Get_Sec_Stack return Stack_Ptr;
57    pragma Import (C, Get_Sec_Stack, "__gnat_get_secondary_stack");
58    --  Return the address of the secondary stack.
59    --  In a multi-threaded environment, Sec_Stack should be a thread-local
60    --  variable.
61
62    --  Possible implementation of Get_Sec_Stack in a single-threaded
63    --  environment:
64    --
65    --     Chunk : aliased Memory (1 .. Default_Secondary_Stack_Size);
66    --     for Chunk'Alignment use Standard'Maximum_Alignment;
67    --     --  The secondary stack.
68    --
69    --     function Get_Sec_Stack return Stack_Ptr is
70    --     begin
71    --        return From_Addr (Chunk'Address);
72    --     end Get_Sec_Stack;
73    --
74    --  begin
75    --     SS_Init (Chunk'Address, Default_Secondary_Stack_Size);
76    --  end System.Secondary_Stack;
77
78    -----------------
79    -- SS_Allocate --
80    -----------------
81
82    procedure SS_Allocate
83      (Address      : out System.Address;
84       Storage_Size : SSE.Storage_Count)
85    is
86       Max_Align    : constant Mark_Id := Mark_Id (Standard'Maximum_Alignment);
87       Max_Size     : constant Mark_Id :=
88                        ((Mark_Id (Storage_Size) + Max_Align - 1) / Max_Align)
89                          * Max_Align;
90       Sec_Stack    : constant Stack_Ptr := Get_Sec_Stack;
91
92    begin
93       if Sec_Stack.Top + Max_Size > Sec_Stack.Last then
94          raise Storage_Error;
95       end if;
96
97       Address := Sec_Stack.Mem (Sec_Stack.Top)'Address;
98       Sec_Stack.Top := Sec_Stack.Top + Mark_Id (Max_Size);
99    end SS_Allocate;
100
101    -------------
102    -- SS_Free --
103    -------------
104
105    procedure SS_Free (Stk : in out System.Address) is
106    begin
107       Stk := Null_Address;
108    end SS_Free;
109
110    -------------
111    -- SS_Init --
112    -------------
113
114    procedure SS_Init
115      (Stk  : System.Address;
116       Size : Natural := Default_Secondary_Stack_Size)
117    is
118       Stack : Stack_Ptr := From_Addr (Stk);
119    begin
120       pragma Assert (Size >= 2 * Mark_Id'Max_Size_In_Storage_Elements);
121
122       Stack.Top := Stack.Mem'First;
123       Stack.Last := Mark_Id (Size) - 2 * Mark_Id'Max_Size_In_Storage_Elements;
124    end SS_Init;
125
126    -------------
127    -- SS_Mark --
128    -------------
129
130    function SS_Mark return Mark_Id is
131    begin
132       return Get_Sec_Stack.Top;
133    end SS_Mark;
134
135    ----------------
136    -- SS_Release --
137    ----------------
138
139    procedure SS_Release (M : Mark_Id) is
140    begin
141       Get_Sec_Stack.Top := M;
142    end SS_Release;
143
144 end System.Secondary_Stack;