OSDN Git Service

2008-03-26 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / opt.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                                  O P T                                   --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2007, 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 ------------------------------------------------------------------------------
33
34 with Gnatvsn; use Gnatvsn;
35 with System;  use System;
36 with Tree_IO; use Tree_IO;
37
38 package body Opt is
39
40    SU : constant := Storage_Unit;
41    --  Shorthand for System.Storage_Unit
42
43    ----------------------------------
44    -- Register_Opt_Config_Switches --
45    ----------------------------------
46
47    procedure Register_Opt_Config_Switches is
48    begin
49       Ada_Version_Config                    := Ada_Version;
50       Ada_Version_Explicit_Config           := Ada_Version_Explicit;
51       Assertions_Enabled_Config             := Assertions_Enabled;
52       Debug_Pragmas_Enabled_Config          := Debug_Pragmas_Enabled;
53       Dynamic_Elaboration_Checks_Config     := Dynamic_Elaboration_Checks;
54       Exception_Locations_Suppressed_Config := Exception_Locations_Suppressed;
55       Extensions_Allowed_Config             := Extensions_Allowed;
56       External_Name_Exp_Casing_Config       := External_Name_Exp_Casing;
57       External_Name_Imp_Casing_Config       := External_Name_Imp_Casing;
58       Fast_Math_Config                      := Fast_Math;
59       Optimize_Alignment_Config             := Optimize_Alignment;
60       Persistent_BSS_Mode_Config            := Persistent_BSS_Mode;
61       Polling_Required_Config               := Polling_Required;
62       Use_VADS_Size_Config                  := Use_VADS_Size;
63    end Register_Opt_Config_Switches;
64
65    ---------------------------------
66    -- Restore_Opt_Config_Switches --
67    ---------------------------------
68
69    procedure Restore_Opt_Config_Switches (Save : Config_Switches_Type) is
70    begin
71       Ada_Version                    := Save.Ada_Version;
72       Ada_Version_Explicit           := Save.Ada_Version_Explicit;
73       Assertions_Enabled             := Save.Assertions_Enabled;
74       Debug_Pragmas_Enabled          := Save.Debug_Pragmas_Enabled;
75       Dynamic_Elaboration_Checks     := Save.Dynamic_Elaboration_Checks;
76       Exception_Locations_Suppressed := Save.Exception_Locations_Suppressed;
77       Extensions_Allowed             := Save.Extensions_Allowed;
78       External_Name_Exp_Casing       := Save.External_Name_Exp_Casing;
79       External_Name_Imp_Casing       := Save.External_Name_Imp_Casing;
80       Fast_Math                      := Save.Fast_Math;
81       Optimize_Alignment             := Save.Optimize_Alignment;
82       Persistent_BSS_Mode            := Save.Persistent_BSS_Mode;
83       Polling_Required               := Save.Polling_Required;
84       Use_VADS_Size                  := Save.Use_VADS_Size;
85    end Restore_Opt_Config_Switches;
86
87    ------------------------------
88    -- Save_Opt_Config_Switches --
89    ------------------------------
90
91    procedure Save_Opt_Config_Switches (Save : out Config_Switches_Type) is
92    begin
93       Save.Ada_Version                    := Ada_Version;
94       Save.Ada_Version_Explicit           := Ada_Version_Explicit;
95       Save.Assertions_Enabled             := Assertions_Enabled;
96       Save.Debug_Pragmas_Enabled          := Debug_Pragmas_Enabled;
97       Save.Dynamic_Elaboration_Checks     := Dynamic_Elaboration_Checks;
98       Save.Exception_Locations_Suppressed := Exception_Locations_Suppressed;
99       Save.Extensions_Allowed             := Extensions_Allowed;
100       Save.External_Name_Exp_Casing       := External_Name_Exp_Casing;
101       Save.External_Name_Imp_Casing       := External_Name_Imp_Casing;
102       Save.Fast_Math                      := Fast_Math;
103       Save.Optimize_Alignment             := Optimize_Alignment;
104       Save.Persistent_BSS_Mode            := Persistent_BSS_Mode;
105       Save.Polling_Required               := Polling_Required;
106       Save.Use_VADS_Size                  := Use_VADS_Size;
107    end Save_Opt_Config_Switches;
108
109    -----------------------------
110    -- Set_Opt_Config_Switches --
111    -----------------------------
112
113    procedure Set_Opt_Config_Switches
114      (Internal_Unit : Boolean;
115       Main_Unit     : Boolean)
116    is
117    begin
118       --  Case of internal unit
119
120       if Internal_Unit then
121
122          --  Set standard switches. Note we do NOT set Ada_Version_Explicit
123          --  since the whole point of this is that it still properly indicates
124          --  the configuration setting even in a run time unit.
125
126          Ada_Version                := Ada_Version_Runtime;
127          Dynamic_Elaboration_Checks := False;
128          Extensions_Allowed         := True;
129          External_Name_Exp_Casing   := As_Is;
130          External_Name_Imp_Casing   := Lowercase;
131          Optimize_Alignment         := 'O';
132          Persistent_BSS_Mode        := False;
133          Use_VADS_Size              := False;
134
135          --  For an internal unit, assertions/debug pragmas are off unless this
136          --  is the main unit and they were explicitly enabled.
137
138          if Main_Unit then
139             Assertions_Enabled    := Assertions_Enabled_Config;
140             Debug_Pragmas_Enabled := Debug_Pragmas_Enabled_Config;
141          else
142             Assertions_Enabled    := False;
143             Debug_Pragmas_Enabled := False;
144          end if;
145
146       --  Case of non-internal unit
147
148       else
149          Ada_Version                := Ada_Version_Config;
150          Ada_Version_Explicit       := Ada_Version_Explicit_Config;
151          Assertions_Enabled         := Assertions_Enabled_Config;
152          Debug_Pragmas_Enabled      := Debug_Pragmas_Enabled_Config;
153          Dynamic_Elaboration_Checks := Dynamic_Elaboration_Checks_Config;
154          Extensions_Allowed         := Extensions_Allowed_Config;
155          External_Name_Exp_Casing   := External_Name_Exp_Casing_Config;
156          External_Name_Imp_Casing   := External_Name_Imp_Casing_Config;
157          Fast_Math                  := Fast_Math_Config;
158          Optimize_Alignment         := Optimize_Alignment_Config;
159          Persistent_BSS_Mode        := Persistent_BSS_Mode_Config;
160          Use_VADS_Size              := Use_VADS_Size_Config;
161       end if;
162
163       Exception_Locations_Suppressed := Exception_Locations_Suppressed_Config;
164       Fast_Math                      := Fast_Math_Config;
165       Optimize_Alignment             := Optimize_Alignment_Config;
166       Polling_Required               := Polling_Required_Config;
167    end Set_Opt_Config_Switches;
168
169    ---------------
170    -- Tree_Read --
171    ---------------
172
173    procedure Tree_Read is
174       Tree_Version_String_Len         : Nat;
175       Ada_Version_Config_Val          : Nat;
176       Ada_Version_Explicit_Config_Val : Nat;
177       Assertions_Enabled_Config_Val   : Nat;
178
179    begin
180       Tree_Read_Int  (Tree_ASIS_Version_Number);
181       Tree_Read_Bool (Brief_Output);
182       Tree_Read_Bool (GNAT_Mode);
183       Tree_Read_Char (Identifier_Character_Set);
184       Tree_Read_Int  (Maximum_File_Name_Length);
185       Tree_Read_Data (Suppress_Options'Address,
186                       (Suppress_Options'Size + SU - 1) / SU);
187       Tree_Read_Bool (Verbose_Mode);
188       Tree_Read_Data (Warning_Mode'Address,
189                       (Warning_Mode'Size + SU - 1) / SU);
190       Tree_Read_Int  (Ada_Version_Config_Val);
191       Tree_Read_Int  (Ada_Version_Explicit_Config_Val);
192       Tree_Read_Int  (Assertions_Enabled_Config_Val);
193       Tree_Read_Bool (All_Errors_Mode);
194       Tree_Read_Bool (Assertions_Enabled);
195       Tree_Read_Bool (Debug_Pragmas_Enabled);
196       Tree_Read_Bool (Enable_Overflow_Checks);
197       Tree_Read_Bool (Full_List);
198
199       Ada_Version_Config :=
200         Ada_Version_Type'Val (Ada_Version_Config_Val);
201       Ada_Version_Explicit_Config :=
202         Ada_Version_Type'Val (Ada_Version_Explicit_Config_Val);
203       Assertions_Enabled_Config :=
204         Boolean'Val (Assertions_Enabled_Config_Val);
205
206       --  Read version string: we have to get the length first
207
208       Tree_Read_Int (Tree_Version_String_Len);
209
210       declare
211          Tmp : String (1 .. Integer (Tree_Version_String_Len));
212       begin
213          Tree_Read_Data
214            (Tmp'Address, Tree_Version_String_Len);
215          System.Strings.Free (Tree_Version_String);
216          Free (Tree_Version_String);
217          Tree_Version_String := new String'(Tmp);
218       end;
219
220       Tree_Read_Data (Distribution_Stub_Mode'Address,
221                       (Distribution_Stub_Mode'Size + SU - 1) / Storage_Unit);
222       Tree_Read_Bool (Inline_Active);
223       Tree_Read_Bool (Inline_Processing_Required);
224       Tree_Read_Bool (List_Units);
225       Tree_Read_Bool (Configurable_Run_Time_Mode);
226       Tree_Read_Data (Operating_Mode'Address,
227                       (Operating_Mode'Size + SU - 1) / Storage_Unit);
228       Tree_Read_Bool (Suppress_Checks);
229       Tree_Read_Bool (Try_Semantics);
230       Tree_Read_Data (Wide_Character_Encoding_Method'Address,
231                       (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
232       Tree_Read_Bool (Upper_Half_Encoding);
233       Tree_Read_Bool (Force_ALI_Tree_File);
234    end Tree_Read;
235
236    ----------------
237    -- Tree_Write --
238    ----------------
239
240    procedure Tree_Write is
241       Version_String : String := Gnat_Version_String;
242
243    begin
244       Tree_Write_Int  (ASIS_Version_Number);
245       Tree_Write_Bool (Brief_Output);
246       Tree_Write_Bool (GNAT_Mode);
247       Tree_Write_Char (Identifier_Character_Set);
248       Tree_Write_Int  (Maximum_File_Name_Length);
249       Tree_Write_Data (Suppress_Options'Address,
250                        (Suppress_Options'Size + SU - 1) / SU);
251       Tree_Write_Bool (Verbose_Mode);
252       Tree_Write_Data (Warning_Mode'Address,
253                        (Warning_Mode'Size + SU - 1) / Storage_Unit);
254       Tree_Write_Int  (Ada_Version_Type'Pos (Ada_Version_Config));
255       Tree_Write_Int  (Ada_Version_Type'Pos (Ada_Version_Explicit_Config));
256       Tree_Write_Int  (Boolean'Pos (Assertions_Enabled_Config));
257       Tree_Write_Bool (All_Errors_Mode);
258       Tree_Write_Bool (Assertions_Enabled);
259       Tree_Write_Bool (Debug_Pragmas_Enabled);
260       Tree_Write_Bool (Enable_Overflow_Checks);
261       Tree_Write_Bool (Full_List);
262       Tree_Write_Int  (Int (Version_String'Length));
263       Tree_Write_Data (Version_String'Address, Version_String'Length);
264       Tree_Write_Data (Distribution_Stub_Mode'Address,
265                        (Distribution_Stub_Mode'Size + SU - 1) / SU);
266       Tree_Write_Bool (Inline_Active);
267       Tree_Write_Bool (Inline_Processing_Required);
268       Tree_Write_Bool (List_Units);
269       Tree_Write_Bool (Configurable_Run_Time_Mode);
270       Tree_Write_Data (Operating_Mode'Address,
271                        (Operating_Mode'Size + SU - 1) / SU);
272       Tree_Write_Bool (Suppress_Checks);
273       Tree_Write_Bool (Try_Semantics);
274       Tree_Write_Data (Wide_Character_Encoding_Method'Address,
275                        (Wide_Character_Encoding_Method'Size + SU - 1) / SU);
276       Tree_Write_Bool (Upper_Half_Encoding);
277       Tree_Write_Bool (Force_ALI_Tree_File);
278    end Tree_Write;
279
280 end Opt;