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