2005-12-29 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / ada / targparm.adb
blob829535d860351e7fa22e40c5b1bac9e1bbd3bbc0
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-2005, 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 -- 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_Times
48 CSV, -- Compiler_System_Version
49 D32, -- Duration_32_Bits
50 DEN, -- Denorm
51 DSP, -- Functions_Return_By_DSP
52 EXS, -- Exit_Status_Supported
53 FEL, -- Frontend_Layout
54 FFO, -- Fractional_Fixed_Ops
55 MOV, -- Machine_Overflows
56 MRN, -- Machine_Rounds
57 PAS, -- Preallocated_Stacks
58 S64, -- Support_64_Bit_Divides
59 SAG, -- Support_Aggregates
60 SCA, -- Support_Composite_Assign
61 SCC, -- Support_Composite_Compare
62 SCD, -- Stack_Check_Default
63 SCP, -- Stack_Check_Probes
64 SLS, -- Support_Long_Shifts
65 SNZ, -- Signed_Zeros
66 SSL, -- Suppress_Standard_Library
67 UAM, -- Use_Ada_Main_Program_Name
68 VMS, -- OpenVMS
69 ZCD, -- ZCX_By_Default
70 ZCG); -- GCC_ZCX_Support
72 subtype Targparm_Tags_OK is Targparm_Tags range AAM .. ZCG;
73 -- Range excluding obsolete entries
75 Targparm_Flags : array (Targparm_Tags) of Boolean := (others => False);
76 -- Flag is set True if corresponding parameter is scanned
78 -- The following list of string constants gives the parameter names
80 AAM_Str : aliased constant Source_Buffer := "AAMP";
81 BDC_Str : aliased constant Source_Buffer := "Backend_Divide_Checks";
82 BOC_Str : aliased constant Source_Buffer := "Backend_Overflow_Checks";
83 CLA_Str : aliased constant Source_Buffer := "Command_Line_Args";
84 CRT_Str : aliased constant Source_Buffer := "Configurable_Run_Time";
85 CSV_Str : aliased constant Source_Buffer := "Compiler_System_Version";
86 D32_Str : aliased constant Source_Buffer := "Duration_32_Bits";
87 DEN_Str : aliased constant Source_Buffer := "Denorm";
88 DSP_Str : aliased constant Source_Buffer := "Functions_Return_By_DSP";
89 EXS_Str : aliased constant Source_Buffer := "Exit_Status_Supported";
90 FEL_Str : aliased constant Source_Buffer := "Frontend_Layout";
91 FFO_Str : aliased constant Source_Buffer := "Fractional_Fixed_Ops";
92 MOV_Str : aliased constant Source_Buffer := "Machine_Overflows";
93 MRN_Str : aliased constant Source_Buffer := "Machine_Rounds";
94 PAS_Str : aliased constant Source_Buffer := "Preallocated_Stacks";
95 S64_Str : aliased constant Source_Buffer := "Support_64_Bit_Divides";
96 SAG_Str : aliased constant Source_Buffer := "Support_Aggregates";
97 SCA_Str : aliased constant Source_Buffer := "Support_Composite_Assign";
98 SCC_Str : aliased constant Source_Buffer := "Support_Composite_Compare";
99 SCD_Str : aliased constant Source_Buffer := "Stack_Check_Default";
100 SCP_Str : aliased constant Source_Buffer := "Stack_Check_Probes";
101 SLS_Str : aliased constant Source_Buffer := "Support_Long_Shifts";
102 SNZ_Str : aliased constant Source_Buffer := "Signed_Zeros";
103 SSL_Str : aliased constant Source_Buffer := "Suppress_Standard_Library";
104 UAM_Str : aliased constant Source_Buffer := "Use_Ada_Main_Program_Name";
105 VMS_Str : aliased constant Source_Buffer := "OpenVMS";
106 ZCD_Str : aliased constant Source_Buffer := "ZCX_By_Default";
107 ZCG_Str : aliased constant Source_Buffer := "GCC_ZCX_Support";
109 -- The following defines a set of pointers to the above strings,
110 -- indexed by the tag values.
112 type Buffer_Ptr is access constant Source_Buffer;
113 Targparm_Str : constant array (Targparm_Tags) of Buffer_Ptr :=
114 (AAM_Str'Access,
115 BDC_Str'Access,
116 BOC_Str'Access,
117 CLA_Str'Access,
118 CRT_Str'Access,
119 CSV_Str'Access,
120 D32_Str'Access,
121 DEN_Str'Access,
122 DSP_Str'Access,
123 EXS_Str'Access,
124 FEL_Str'Access,
125 FFO_Str'Access,
126 MOV_Str'Access,
127 MRN_Str'Access,
128 PAS_Str'Access,
129 S64_Str'Access,
130 SAG_Str'Access,
131 SCA_Str'Access,
132 SCC_Str'Access,
133 SCD_Str'Access,
134 SCP_Str'Access,
135 SLS_Str'Access,
136 SNZ_Str'Access,
137 SSL_Str'Access,
138 UAM_Str'Access,
139 VMS_Str'Access,
140 ZCD_Str'Access,
141 ZCG_Str'Access);
143 -----------------------
144 -- Local Subprograms --
145 -----------------------
147 procedure Set_Profile_Restrictions (P : Profile_Name);
148 -- Set Restrictions_On_Target for the given profile
150 ------------------------------
151 -- Set_Profile_Restrictions --
152 ------------------------------
154 procedure Set_Profile_Restrictions (P : Profile_Name) is
155 R : Restriction_Flags renames Profile_Info (P).Set;
156 V : Restriction_Values renames Profile_Info (P).Value;
157 begin
158 for J in R'Range loop
159 if R (J) then
160 Restrictions_On_Target.Set (J) := True;
162 if J in All_Parameter_Restrictions then
163 Restrictions_On_Target.Value (J) := V (J);
164 end if;
165 end if;
166 end loop;
167 end Set_Profile_Restrictions;
169 ---------------------------
170 -- Get_Target_Parameters --
171 ---------------------------
173 -- Version which reads in system.ads
175 procedure Get_Target_Parameters is
176 Text : Source_Buffer_Ptr;
177 Hi : Source_Ptr;
179 begin
180 if Parameters_Obtained then
181 return;
182 end if;
184 Name_Buffer (1 .. 10) := "system.ads";
185 Name_Len := 10;
187 Read_Source_File (Name_Find, Lo => 0, Hi => Hi, Src => Text);
189 if Text = null then
190 Write_Line ("fatal error, run-time library not installed correctly");
191 Write_Line ("cannot locate file system.ads");
192 raise Unrecoverable_Error;
193 end if;
195 Targparm.Get_Target_Parameters
196 (System_Text => Text,
197 Source_First => 0,
198 Source_Last => Hi);
199 end Get_Target_Parameters;
201 -- Version where caller supplies system.ads text
203 procedure Get_Target_Parameters
204 (System_Text : Source_Buffer_Ptr;
205 Source_First : Source_Ptr;
206 Source_Last : Source_Ptr)
208 P : Source_Ptr;
209 -- Scans source buffer containing source of system.ads
211 Fatal : Boolean := False;
212 -- Set True if a fatal error is detected
214 Result : Boolean;
215 -- Records boolean from system line
217 begin
218 if Parameters_Obtained then
219 return;
220 else
221 Parameters_Obtained := True;
222 end if;
224 Opt.Address_Is_Private := False;
226 P := Source_First;
227 Line_Loop : while System_Text (P .. P + 10) /= "end System;" loop
229 -- Skip comments quickly
231 if System_Text (P) = '-' then
232 goto Line_Loop_Continue;
234 -- Test for type Address is private
236 elsif System_Text (P .. P + 26) = " type Address is private;" then
237 Opt.Address_Is_Private := True;
238 P := P + 26;
239 goto Line_Loop_Continue;
241 -- Test for pragma Profile (Ravenscar);
243 elsif System_Text (P .. P + 26) =
244 "pragma Profile (Ravenscar);"
245 then
246 Set_Profile_Restrictions (Ravenscar);
247 Opt.Task_Dispatching_Policy := 'F';
248 Opt.Locking_Policy := 'C';
249 P := P + 27;
250 goto Line_Loop_Continue;
252 -- Test for pragma Profile (Restricted);
254 elsif System_Text (P .. P + 27) =
255 "pragma Profile (Restricted);"
256 then
257 Set_Profile_Restrictions (Restricted);
258 P := P + 28;
259 goto Line_Loop_Continue;
261 -- Test for pragma Restrictions
263 elsif System_Text (P .. P + 20) = "pragma Restrictions (" then
264 P := P + 21;
266 Rloop : for K in All_Boolean_Restrictions loop
267 declare
268 Rname : constant String := Restriction_Id'Image (K);
270 begin
271 for J in Rname'Range loop
272 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
273 /= Rname (J)
274 then
275 goto Rloop_Continue;
276 end if;
277 end loop;
279 if System_Text (P + Rname'Length) = ')' then
280 Restrictions_On_Target.Set (K) := True;
281 goto Line_Loop_Continue;
282 end if;
283 end;
285 <<Rloop_Continue>>
286 null;
287 end loop Rloop;
289 Ploop : for K in All_Parameter_Restrictions loop
290 declare
291 Rname : constant String :=
292 All_Parameter_Restrictions'Image (K);
294 V : Natural;
295 -- Accumulates value
297 begin
298 for J in Rname'Range loop
299 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
300 /= Rname (J)
301 then
302 goto Ploop_Continue;
303 end if;
304 end loop;
306 if System_Text (P + Rname'Length .. P + Rname'Length + 3) =
307 " => "
308 then
309 P := P + Rname'Length + 4;
311 V := 0;
312 loop
313 if System_Text (P) in '0' .. '9' then
314 declare
315 pragma Unsuppress (Overflow_Check);
317 begin
318 -- Accumulate next digit
320 V := 10 * V +
321 Character'Pos (System_Text (P)) -
322 Character'Pos ('0');
324 exception
325 -- On overflow, we just ignore the pragma since
326 -- that is the standard handling in this case.
328 when Constraint_Error =>
329 goto Line_Loop_Continue;
330 end;
332 elsif System_Text (P) = '_' then
333 null;
335 elsif System_Text (P) = ')' then
336 Restrictions_On_Target.Value (K) := V;
337 Restrictions_On_Target.Set (K) := True;
338 goto Line_Loop_Continue;
340 else
341 exit Ploop;
342 end if;
344 P := P + 1;
345 end loop;
347 else
348 exit Ploop;
349 end if;
350 end;
352 <<Ploop_Continue>>
353 null;
354 end loop Ploop;
356 Set_Standard_Error;
357 Write_Line
358 ("fatal error: system.ads is incorrectly formatted");
359 Write_Str ("unrecognized or incorrect restrictions pragma: ");
361 while System_Text (P) /= ')'
362 and then
363 System_Text (P) /= ASCII.LF
364 loop
365 Write_Char (System_Text (P));
366 P := P + 1;
367 end loop;
369 Write_Eol;
370 Fatal := True;
371 Set_Standard_Output;
373 -- Test for pragma Detect_Blocking;
375 elsif System_Text (P .. P + 22) = "pragma Detect_Blocking;" then
376 P := P + 23;
377 Opt.Detect_Blocking := True;
378 goto Line_Loop_Continue;
380 -- Discard_Names
382 elsif System_Text (P .. P + 20) = "pragma Discard_Names;" then
383 P := P + 21;
384 Opt.Global_Discard_Names := True;
385 goto Line_Loop_Continue;
387 -- Locking Policy
389 elsif System_Text (P .. P + 22) = "pragma Locking_Policy (" then
390 P := P + 23;
391 Opt.Locking_Policy := System_Text (P);
392 Opt.Locking_Policy_Sloc := System_Location;
393 goto Line_Loop_Continue;
395 -- Normalize_Scalars
397 elsif System_Text (P .. P + 24) = "pragma Normalize_Scalars;" then
398 P := P + 25;
399 Opt.Normalize_Scalars := True;
400 Opt.Init_Or_Norm_Scalars := True;
401 goto Line_Loop_Continue;
403 -- Polling (On)
405 elsif System_Text (P .. P + 19) = "pragma Polling (On);" then
406 P := P + 20;
407 Opt.Polling_Required := True;
408 goto Line_Loop_Continue;
410 -- Ignore pragma Pure (System)
412 elsif System_Text (P .. P + 20) = "pragma Pure (System);" then
413 P := P + 21;
414 goto Line_Loop_Continue;
416 -- Queuing Policy
418 elsif System_Text (P .. P + 22) = "pragma Queuing_Policy (" then
419 P := P + 23;
420 Opt.Queuing_Policy := System_Text (P);
421 Opt.Queuing_Policy_Sloc := System_Location;
422 goto Line_Loop_Continue;
424 -- Suppress_Exception_Locations
426 elsif System_Text (P .. P + 34) =
427 "pragma Suppress_Exception_Locations;"
428 then
429 P := P + 35;
430 Opt.Exception_Locations_Suppressed := True;
431 goto Line_Loop_Continue;
433 -- Task_Dispatching Policy
435 elsif System_Text (P .. P + 31) =
436 "pragma Task_Dispatching_Policy ("
437 then
438 P := P + 32;
439 Opt.Task_Dispatching_Policy := System_Text (P);
440 Opt.Task_Dispatching_Policy_Sloc := System_Location;
441 goto Line_Loop_Continue;
443 -- No other pragmas are permitted
445 elsif System_Text (P .. P + 6) = "pragma " then
446 Set_Standard_Error;
447 Write_Line ("unrecognized line in system.ads: ");
449 while System_Text (P) /= ')'
450 and then System_Text (P) /= ASCII.LF
451 loop
452 Write_Char (System_Text (P));
453 P := P + 1;
454 end loop;
456 Write_Eol;
457 Set_Standard_Output;
458 Fatal := True;
460 -- See if we have a Run_Time_Name
462 elsif System_Text (P .. P + 38) =
463 " Run_Time_Name : constant String := """
464 then
465 P := P + 39;
467 Name_Len := 0;
468 while System_Text (P) in 'A' .. 'Z'
469 or else
470 System_Text (P) in 'a' .. 'z'
471 or else
472 System_Text (P) in '0' .. '9'
473 or else
474 System_Text (P) = ' '
475 or else
476 System_Text (P) = '_'
477 loop
478 Add_Char_To_Name_Buffer (System_Text (P));
479 P := P + 1;
480 end loop;
482 if System_Text (P) /= '"'
483 or else System_Text (P + 1) /= ';'
484 or else (System_Text (P + 2) /= ASCII.LF
485 and then
486 System_Text (P + 2) /= ASCII.CR)
487 then
488 Set_Standard_Error;
489 Write_Line
490 ("incorrectly formatted Run_Time_Name in system.ads");
491 Set_Standard_Output;
492 Fatal := True;
494 else
495 Run_Time_Name_On_Target := Name_Enter;
496 end if;
498 goto Line_Loop_Continue;
500 -- Next See if we have a configuration parameter
502 else
503 Config_Param_Loop : for K in Targparm_Tags loop
504 if System_Text (P + 3 .. P + 2 + Targparm_Str (K)'Length) =
505 Targparm_Str (K).all
506 then
507 P := P + 3 + Targparm_Str (K)'Length;
509 if Targparm_Flags (K) then
510 Set_Standard_Error;
511 Write_Line
512 ("fatal error: system.ads is incorrectly formatted");
513 Write_Str ("duplicate line for parameter: ");
515 for J in Targparm_Str (K)'Range loop
516 Write_Char (Targparm_Str (K).all (J));
517 end loop;
519 Write_Eol;
520 Set_Standard_Output;
521 Fatal := True;
523 else
524 Targparm_Flags (K) := True;
525 end if;
527 while System_Text (P) /= ':'
528 or else System_Text (P + 1) /= '='
529 loop
530 P := P + 1;
531 end loop;
533 P := P + 2;
535 while System_Text (P) = ' ' loop
536 P := P + 1;
537 end loop;
539 Result := (System_Text (P) = 'T');
541 case K is
542 when AAM => AAMP_On_Target := Result;
543 when BDC => Backend_Divide_Checks_On_Target := Result;
544 when BOC => Backend_Overflow_Checks_On_Target := Result;
545 when CLA => Command_Line_Args_On_Target := Result;
546 when CRT => Configurable_Run_Time_On_Target := Result;
547 when CSV => Compiler_System_Version := Result;
548 when D32 => Duration_32_Bits_On_Target := Result;
549 when DEN => Denorm_On_Target := Result;
550 when DSP => Functions_Return_By_DSP_On_Target := Result;
551 when EXS => Exit_Status_Supported_On_Target := Result;
552 when FEL => Frontend_Layout_On_Target := Result;
553 when FFO => Fractional_Fixed_Ops_On_Target := Result;
554 when MOV => Machine_Overflows_On_Target := Result;
555 when MRN => Machine_Rounds_On_Target := Result;
556 when PAS => Preallocated_Stacks_On_Target := Result;
557 when S64 => Support_64_Bit_Divides_On_Target := Result;
558 when SAG => Support_Aggregates_On_Target := Result;
559 when SCA => Support_Composite_Assign_On_Target := Result;
560 when SCC => Support_Composite_Compare_On_Target := Result;
561 when SCD => Stack_Check_Default_On_Target := Result;
562 when SCP => Stack_Check_Probes_On_Target := Result;
563 when SLS => Support_Long_Shifts_On_Target := Result;
564 when SSL => Suppress_Standard_Library_On_Target := Result;
565 when SNZ => Signed_Zeros_On_Target := Result;
566 when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
567 when VMS => OpenVMS_On_Target := Result;
568 when ZCD => ZCX_By_Default_On_Target := Result;
569 when ZCG => GCC_ZCX_Support_On_Target := Result;
571 goto Line_Loop_Continue;
572 end case;
574 -- Here we are seeing a parameter we do not understand. We
575 -- simply ignore this (will happen when an old compiler is
576 -- used to compile a newer version of GNAT which does not
577 -- support the
578 end if;
579 end loop Config_Param_Loop;
580 end if;
582 -- Here after processing one line of System spec
584 <<Line_Loop_Continue>>
586 while System_Text (P) /= CR and then System_Text (P) /= LF loop
587 P := P + 1;
588 exit when P >= Source_Last;
589 end loop;
591 while System_Text (P) = CR or else System_Text (P) = LF loop
592 P := P + 1;
593 exit when P >= Source_Last;
594 end loop;
596 if P >= Source_Last then
597 Set_Standard_Error;
598 Write_Line ("fatal error, system.ads not formatted correctly");
599 Write_Line ("unexpected end of file");
600 Set_Standard_Output;
601 raise Unrecoverable_Error;
602 end if;
603 end loop Line_Loop;
605 -- Now that OpenVMS_On_Target has been given its definitive value,
606 -- change the multi-unit index character from '~' to '$' for OpenVMS.
608 if OpenVMS_On_Target then
609 Multi_Unit_Index_Character := '$';
610 end if;
612 -- Check no missing target parameter settings (skip for compiler vsn)
614 if not Compiler_System_Version then
615 for K in Targparm_Tags_OK loop
616 if not Targparm_Flags (K) then
617 Set_Standard_Error;
618 Write_Line
619 ("fatal error: system.ads is incorrectly formatted");
620 Write_Str ("missing line for parameter: ");
622 for J in Targparm_Str (K)'Range loop
623 Write_Char (Targparm_Str (K).all (J));
624 end loop;
626 Write_Eol;
627 Set_Standard_Output;
628 Fatal := True;
629 end if;
630 end loop;
631 end if;
633 if Fatal then
634 raise Unrecoverable_Error;
635 end if;
636 end Get_Target_Parameters;
638 end Targparm;