2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / ada / targparm.adb
blob6e911fba3cb8757ff74eb991b20b24963161a574
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- T A R G P A R M --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1999-2003 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Csets; use Csets;
28 with Namet; use Namet;
29 with Opt; use Opt;
30 with Osint; use Osint;
31 with Output; use Output;
33 package body Targparm is
34 use ASCII;
36 Parameters_Obtained : Boolean := False;
37 -- Set True after first call to Get_Target_Parameters. Used to avoid
38 -- reading system.ads more than once, since it cannot change.
40 -- The following array defines a tag name for each entry
42 type Targparm_Tags is
43 (AAM, -- AAMP
44 BDC, -- Backend_Divide_Checks
45 BOC, -- Backend_Overflow_Checks
46 CLA, -- Command_Line_Args
47 CRT, -- Configurable_Run_Time
48 D32, -- Duration_32_Bits
49 DEN, -- Denorm
50 DSP, -- Functions_Return_By_DSP
51 EXS, -- Exit_Status_Supported
52 FEL, -- Frontend_Layout
53 FFO, -- Fractional_Fixed_Ops
54 MOV, -- Machine_Overflows
55 MRN, -- Machine_Rounds
56 S64, -- Support_64_Bit_Divides
57 SAG, -- Support_Aggregates
58 SCA, -- Support_Composite_Assign
59 SCC, -- Support_Composite_Compare
60 SCD, -- Stack_Check_Default
61 SCP, -- Stack_Check_Probes
62 SLS, -- Support_Long_Shifts
63 SNZ, -- Signed_Zeros
64 SSL, -- Suppress_Standard_Library
65 UAM, -- Use_Ada_Main_Program_Name
66 VMS, -- OpenVMS
67 ZCD, -- ZCX_By_Default
68 ZCG, -- GCC_ZCX_Support
69 ZCF, -- Front_End_ZCX_Support
71 -- The following entries are obsolete and can eventually be removed
73 HIM, -- High_Integrity_Mode
74 LSI); -- Long_Shifts_Inlined
76 subtype Targparm_Tags_OK is Targparm_Tags range AAM .. ZCF;
77 -- Range excluding obsolete entries
79 Targparm_Flags : array (Targparm_Tags) of Boolean := (others => False);
80 -- Flag is set True if corresponding parameter is scanned
82 -- The following list of string constants gives the parameter names
84 AAM_Str : aliased constant Source_Buffer := "AAMP";
85 BDC_Str : aliased constant Source_Buffer := "Backend_Divide_Checks";
86 BOC_Str : aliased constant Source_Buffer := "Backend_Overflow_Checks";
87 CLA_Str : aliased constant Source_Buffer := "Command_Line_Args";
88 CRT_Str : aliased constant Source_Buffer := "Configurable_Run_Time";
89 D32_Str : aliased constant Source_Buffer := "Duration_32_Bits";
90 DEN_Str : aliased constant Source_Buffer := "Denorm";
91 DSP_Str : aliased constant Source_Buffer := "Functions_Return_By_DSP";
92 EXS_Str : aliased constant Source_Buffer := "Exit_Status_Supported";
93 FEL_Str : aliased constant Source_Buffer := "Frontend_Layout";
94 FFO_Str : aliased constant Source_Buffer := "Fractional_Fixed_Ops";
95 MOV_Str : aliased constant Source_Buffer := "Machine_Overflows";
96 MRN_Str : aliased constant Source_Buffer := "Machine_Rounds";
97 S64_Str : aliased constant Source_Buffer := "Support_64_Bit_Divides";
98 SAG_Str : aliased constant Source_Buffer := "Support_Aggregates";
99 SCA_Str : aliased constant Source_Buffer := "Support_Composite_Assign";
100 SCC_Str : aliased constant Source_Buffer := "Support_Composite_Compare";
101 SCD_Str : aliased constant Source_Buffer := "Stack_Check_Default";
102 SCP_Str : aliased constant Source_Buffer := "Stack_Check_Probes";
103 SLS_Str : aliased constant Source_Buffer := "Support_Long_Shifts";
104 SNZ_Str : aliased constant Source_Buffer := "Signed_Zeros";
105 SSL_Str : aliased constant Source_Buffer := "Suppress_Standard_Library";
106 UAM_Str : aliased constant Source_Buffer := "Use_Ada_Main_Program_Name";
107 VMS_Str : aliased constant Source_Buffer := "OpenVMS";
108 ZCD_Str : aliased constant Source_Buffer := "ZCX_By_Default";
109 ZCG_Str : aliased constant Source_Buffer := "GCC_ZCX_Support";
110 ZCF_Str : aliased constant Source_Buffer := "Front_End_ZCX_Support";
112 -- Obsolete entries
114 HIM_Str : aliased constant Source_Buffer := "High_Integrity_Mode";
115 LSI_Str : aliased constant Source_Buffer := "Long_Shifts_Inlined";
117 -- The following defines a set of pointers to the above strings,
118 -- indexed by the tag values.
120 type Buffer_Ptr is access constant Source_Buffer;
121 Targparm_Str : constant array (Targparm_Tags) of Buffer_Ptr :=
122 (AAM_Str'Access,
123 BDC_Str'Access,
124 BOC_Str'Access,
125 CLA_Str'Access,
126 CRT_Str'Access,
127 D32_Str'Access,
128 DEN_Str'Access,
129 DSP_Str'Access,
130 EXS_Str'Access,
131 FEL_Str'Access,
132 FFO_Str'Access,
133 MOV_Str'Access,
134 MRN_Str'Access,
135 S64_Str'Access,
136 SAG_Str'Access,
137 SCA_Str'Access,
138 SCC_Str'Access,
139 SCD_Str'Access,
140 SCP_Str'Access,
141 SLS_Str'Access,
142 SNZ_Str'Access,
143 SSL_Str'Access,
144 UAM_Str'Access,
145 VMS_Str'Access,
146 ZCD_Str'Access,
147 ZCG_Str'Access,
148 ZCF_Str'Access,
150 -- Obsolete entries
152 HIM_Str'Access,
153 LSI_Str'Access);
155 ---------------------------
156 -- Get_Target_Parameters --
157 ---------------------------
159 -- Version which reads in system.ads
161 procedure Get_Target_Parameters is
162 Text : Source_Buffer_Ptr;
163 Hi : Source_Ptr;
165 begin
166 if Parameters_Obtained then
167 return;
168 end if;
170 Name_Buffer (1 .. 10) := "system.ads";
171 Name_Len := 10;
173 Read_Source_File (Name_Find, Lo => 0, Hi => Hi, Src => Text);
175 if Text = null then
176 Write_Line ("fatal error, run-time library not installed correctly");
177 Write_Line ("cannot locate file system.ads");
178 raise Unrecoverable_Error;
179 end if;
181 Targparm.Get_Target_Parameters
182 (System_Text => Text,
183 Source_First => 0,
184 Source_Last => Hi);
185 end Get_Target_Parameters;
187 -- Version where caller supplies system.ads text
189 procedure Get_Target_Parameters
190 (System_Text : Source_Buffer_Ptr;
191 Source_First : Source_Ptr;
192 Source_Last : Source_Ptr)
194 P : Source_Ptr;
195 V : Uint;
197 Fatal : Boolean := False;
198 -- Set True if a fatal error is detected
200 Result : Boolean;
201 -- Records boolean from system line
203 begin
204 if Parameters_Obtained then
205 return;
206 else
207 Parameters_Obtained := True;
208 end if;
210 P := Source_First;
211 Line_Loop : while System_Text (P .. P + 10) /= "end System;" loop
213 -- Skip comments quickly
215 if System_Text (P) = '-' then
216 goto Line_Loop_Continue;
218 -- Test for pragma Restrictions
220 elsif System_Text (P .. P + 20) = "pragma Restrictions (" then
221 P := P + 21;
223 Rloop : for K in Partition_Restrictions loop
224 declare
225 Rname : constant String := Restriction_Id'Image (K);
227 begin
228 for J in Rname'Range loop
229 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
230 /= Rname (J)
231 then
232 goto Rloop_Continue;
233 end if;
234 end loop;
236 if System_Text (P + Rname'Length) = ')' then
237 Restrictions_On_Target (K) := True;
238 goto Line_Loop_Continue;
239 end if;
240 end;
242 <<Rloop_Continue>>
243 null;
244 end loop Rloop;
246 Ploop : for K in Restriction_Parameter_Id loop
247 declare
248 Rname : constant String :=
249 Restriction_Parameter_Id'Image (K);
251 begin
252 for J in Rname'Range loop
253 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
254 /= Rname (J)
255 then
256 goto Ploop_Continue;
257 end if;
258 end loop;
260 if System_Text (P + Rname'Length .. P + Rname'Length + 3) =
261 " => "
262 then
263 P := P + Rname'Length + 4;
264 V := Uint_0;
266 loop
267 if System_Text (P) in '0' .. '9' then
268 V := 10 * V + Character'Pos (System_Text (P)) - 48;
269 elsif System_Text (P) = '_' then
270 null;
271 elsif System_Text (P) = ')' then
272 Restriction_Parameters_On_Target (K) := V;
273 goto Line_Loop_Continue;
274 else
275 goto Ploop_Continue;
276 end if;
278 P := P + 1;
279 end loop;
280 end if;
281 end;
283 <<Ploop_Continue>>
284 null;
285 end loop Ploop;
287 Set_Standard_Error;
288 Write_Line
289 ("fatal error: system.ads is incorrectly formatted");
290 Write_Str ("unrecognized restrictions pragma: ");
292 while System_Text (P) /= ')'
293 and then
294 System_Text (P) /= ASCII.LF
295 loop
296 Write_Char (System_Text (P));
297 P := P + 1;
298 end loop;
300 Write_Eol;
301 Fatal := True;
302 Set_Standard_Output;
304 -- Discard_Names
306 elsif System_Text (P .. P + 20) = "pragma Discard_Names;" then
307 P := P + 21;
308 Opt.Global_Discard_Names := True;
309 goto Line_Loop_Continue;
311 -- Locking Policy
313 elsif System_Text (P .. P + 22) = "pragma Locking_Policy (" then
314 P := P + 23;
315 Opt.Locking_Policy := System_Text (P);
316 Opt.Locking_Policy_Sloc := System_Location;
317 goto Line_Loop_Continue;
319 -- Normalize_Scalars
321 elsif System_Text (P .. P + 24) = "pragma Normalize_Scalars;" then
322 P := P + 25;
323 Opt.Normalize_Scalars := True;
324 Opt.Init_Or_Norm_Scalars := True;
325 goto Line_Loop_Continue;
327 -- Polling (On)
329 elsif System_Text (P .. P + 19) = "pragma Polling (On);" then
330 P := P + 20;
331 Opt.Polling_Required := True;
332 goto Line_Loop_Continue;
334 -- Ignore pragma Pure (System)
336 elsif System_Text (P .. P + 20) = "pragma Pure (System);" then
337 P := P + 21;
338 goto Line_Loop_Continue;
340 -- Queuing Policy
342 elsif System_Text (P .. P + 22) = "pragma Queuing_Policy (" then
343 P := P + 23;
344 Opt.Queuing_Policy := System_Text (P);
345 Opt.Queuing_Policy_Sloc := System_Location;
346 goto Line_Loop_Continue;
348 -- Suppress_Exception_Locations
350 elsif System_Text (P .. P + 34) =
351 "pragma Suppress_Exception_Locations;"
352 then
353 P := P + 35;
354 Opt.Exception_Locations_Suppressed := True;
355 goto Line_Loop_Continue;
357 -- Task_Dispatching Policy
359 elsif System_Text (P .. P + 31) =
360 "pragma Task_Dispatching_Policy ("
361 then
362 P := P + 32;
363 Opt.Task_Dispatching_Policy := System_Text (P);
364 Opt.Task_Dispatching_Policy_Sloc := System_Location;
365 goto Line_Loop_Continue;
367 -- No other pragmas are permitted
369 elsif System_Text (P .. P + 6) = "pragma " then
370 Set_Standard_Error;
371 Write_Line ("unrecognized line in system.ads: ");
373 while System_Text (P) /= ')'
374 and then System_Text (P) /= ASCII.LF
375 loop
376 Write_Char (System_Text (P));
377 P := P + 1;
378 end loop;
380 Write_Eol;
381 Set_Standard_Output;
382 Fatal := True;
384 -- See if we have a Run_Time_Name
386 elsif System_Text (P .. P + 38) =
387 " Run_Time_Name : constant String := """
388 then
389 P := P + 39;
391 Name_Len := 0;
392 while System_Text (P) in 'A' .. 'Z'
393 or else
394 System_Text (P) in 'a' .. 'z'
395 or else
396 System_Text (P) in '0' .. '9'
397 or else
398 System_Text (P) = ' '
399 or else
400 System_Text (P) = '_'
401 loop
402 Add_Char_To_Name_Buffer (System_Text (P));
403 P := P + 1;
404 end loop;
406 if System_Text (P) /= '"'
407 or else System_Text (P + 1) /= ';'
408 or else (System_Text (P + 2) /= ASCII.LF
409 and then
410 System_Text (P + 2) /= ASCII.CR)
411 then
412 Set_Standard_Error;
413 Write_Line
414 ("incorrectly formatted Run_Time_Name in system.ads");
415 Set_Standard_Output;
416 Fatal := True;
418 else
419 Run_Time_Name_On_Target := Name_Enter;
420 end if;
422 goto Line_Loop_Continue;
424 -- Next See if we have a configuration parameter
426 else
427 Config_Param_Loop : for K in Targparm_Tags loop
428 if System_Text (P + 3 .. P + 2 + Targparm_Str (K)'Length) =
429 Targparm_Str (K).all
430 then
431 P := P + 3 + Targparm_Str (K)'Length;
434 if Targparm_Flags (K) then
435 Set_Standard_Error;
436 Write_Line
437 ("fatal error: system.ads is incorrectly formatted");
438 Write_Str ("duplicate line for parameter: ");
440 for J in Targparm_Str (K)'Range loop
441 Write_Char (Targparm_Str (K).all (J));
442 end loop;
444 Write_Eol;
445 Set_Standard_Output;
446 Fatal := True;
448 else
449 Targparm_Flags (K) := True;
450 end if;
452 while System_Text (P) /= ':'
453 or else System_Text (P + 1) /= '='
454 loop
455 P := P + 1;
456 end loop;
458 P := P + 2;
460 while System_Text (P) = ' ' loop
461 P := P + 1;
462 end loop;
464 Result := (System_Text (P) = 'T');
466 case K is
467 when AAM => AAMP_On_Target := Result;
468 when BDC => Backend_Divide_Checks_On_Target := Result;
469 when BOC => Backend_Overflow_Checks_On_Target := Result;
470 when CLA => Command_Line_Args_On_Target := Result;
471 when CRT => Configurable_Run_Time_On_Target := Result;
472 when D32 => Duration_32_Bits_On_Target := Result;
473 when DEN => Denorm_On_Target := Result;
474 when DSP => Functions_Return_By_DSP_On_Target := Result;
475 when EXS => Exit_Status_Supported_On_Target := Result;
476 when FEL => Frontend_Layout_On_Target := Result;
477 when FFO => Fractional_Fixed_Ops_On_Target := Result;
478 when MOV => Machine_Overflows_On_Target := Result;
479 when MRN => Machine_Rounds_On_Target := Result;
480 when S64 => Support_64_Bit_Divides_On_Target := Result;
481 when SAG => Support_Aggregates_On_Target := Result;
482 when SCA => Support_Composite_Assign_On_Target := Result;
483 when SCC => Support_Composite_Compare_On_Target := Result;
484 when SCD => Stack_Check_Default_On_Target := Result;
485 when SCP => Stack_Check_Probes_On_Target := Result;
486 when SLS => Support_Long_Shifts_On_Target := Result;
487 when SSL => Suppress_Standard_Library_On_Target := Result;
488 when SNZ => Signed_Zeros_On_Target := Result;
489 when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
490 when VMS => OpenVMS_On_Target := Result;
491 when ZCD => ZCX_By_Default_On_Target := Result;
492 when ZCG => GCC_ZCX_Support_On_Target := Result;
493 when ZCF => Front_End_ZCX_Support_On_Target := Result;
495 -- Obsolete entries
497 when HIM => null;
498 when LSI => null;
500 goto Line_Loop_Continue;
501 end case;
502 end if;
503 end loop Config_Param_Loop;
504 end if;
506 -- Here after processing one line of System spec
508 <<Line_Loop_Continue>>
510 while System_Text (P) /= CR and then System_Text (P) /= LF loop
511 P := P + 1;
512 exit when P >= Source_Last;
513 end loop;
515 while System_Text (P) = CR or else System_Text (P) = LF loop
516 P := P + 1;
517 exit when P >= Source_Last;
518 end loop;
520 if P >= Source_Last then
521 Set_Standard_Error;
522 Write_Line ("fatal error, system.ads not formatted correctly");
523 Set_Standard_Output;
524 end if;
525 end loop Line_Loop;
527 -- Check no missing target parameter settings
529 for K in Targparm_Tags_OK loop
530 if not Targparm_Flags (K) then
531 Set_Standard_Error;
532 Write_Line
533 ("fatal error: system.ads is incorrectly formatted");
534 Write_Str ("missing line for parameter: ");
536 for J in Targparm_Str (K)'Range loop
537 Write_Char (Targparm_Str (K).all (J));
538 end loop;
540 Write_Eol;
541 Set_Standard_Output;
542 Fatal := True;
543 end if;
544 end loop;
546 if Fatal then
547 raise Unrecoverable_Error;
548 end if;
549 end Get_Target_Parameters;
551 end Targparm;