1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2006, Free Software Foundation, Inc. --
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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Csets; use Csets;
28 with Namet; use Namet;
30 with Osint; use Osint;
31 with Output; use Output;
33 package body Targparm is
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
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
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
66 SSL, -- Suppress_Standard_Library
67 UAM, -- Use_Ada_Main_Program_Name
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 :=
143 -----------------------
144 -- Local Subprograms --
145 -----------------------
147 procedure Set_Profile_Restrictions (P : Profile_Name);
148 -- Set Restrictions_On_Target for the given profile
150 ---------------------------
151 -- Get_Target_Parameters --
152 ---------------------------
154 -- Version which reads in system.ads
156 procedure Get_Target_Parameters is
157 Text : Source_Buffer_Ptr;
161 if Parameters_Obtained then
165 Name_Buffer (1 .. 10) := "system.ads";
168 Read_Source_File (Name_Find, Lo => 0, Hi => Hi, Src => Text);
171 Write_Line ("fatal error, run-time library not installed correctly");
172 Write_Line ("cannot locate file system.ads");
173 raise Unrecoverable_Error;
176 Targparm.Get_Target_Parameters
177 (System_Text => Text,
180 end Get_Target_Parameters;
182 -- Version where caller supplies system.ads text
184 procedure Get_Target_Parameters
185 (System_Text : Source_Buffer_Ptr;
186 Source_First : Source_Ptr;
187 Source_Last : Source_Ptr)
190 -- Scans source buffer containing source of system.ads
192 Fatal : Boolean := False;
193 -- Set True if a fatal error is detected
196 -- Records boolean from system line
199 if Parameters_Obtained then
202 Parameters_Obtained := True;
205 Opt.Address_Is_Private := False;
208 Line_Loop : while System_Text (P .. P + 10) /= "end System;" loop
210 -- Skip comments quickly
212 if System_Text (P) = '-' then
213 goto Line_Loop_Continue;
215 -- Test for type Address is private
217 elsif System_Text (P .. P + 26) = " type Address is private;" then
218 Opt.Address_Is_Private := True;
220 goto Line_Loop_Continue;
222 -- Test for pragma Profile (Ravenscar);
224 elsif System_Text (P .. P + 26) =
225 "pragma Profile (Ravenscar);"
227 Set_Profile_Restrictions (Ravenscar);
228 Opt.Task_Dispatching_Policy := 'F';
229 Opt.Locking_Policy := 'C';
231 goto Line_Loop_Continue;
233 -- Test for pragma Profile (Restricted);
235 elsif System_Text (P .. P + 27) =
236 "pragma Profile (Restricted);"
238 Set_Profile_Restrictions (Restricted);
240 goto Line_Loop_Continue;
242 -- Test for pragma Restrictions
244 elsif System_Text (P .. P + 20) = "pragma Restrictions (" then
247 Rloop : for K in All_Boolean_Restrictions loop
249 Rname : constant String := Restriction_Id'Image (K);
252 for J in Rname'Range loop
253 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
260 if System_Text (P + Rname'Length) = ')' then
261 Restrictions_On_Target.Set (K) := True;
262 goto Line_Loop_Continue;
270 Ploop : for K in All_Parameter_Restrictions loop
272 Rname : constant String :=
273 All_Parameter_Restrictions'Image (K);
279 for J in Rname'Range loop
280 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
287 if System_Text (P + Rname'Length .. P + Rname'Length + 3) =
290 P := P + Rname'Length + 4;
294 if System_Text (P) in '0' .. '9' then
296 pragma Unsuppress (Overflow_Check);
299 -- Accumulate next digit
302 Character'Pos (System_Text (P)) -
306 -- On overflow, we just ignore the pragma since
307 -- that is the standard handling in this case.
309 when Constraint_Error =>
310 goto Line_Loop_Continue;
313 elsif System_Text (P) = '_' then
316 elsif System_Text (P) = ')' then
317 Restrictions_On_Target.Value (K) := V;
318 Restrictions_On_Target.Set (K) := True;
319 goto Line_Loop_Continue;
339 ("fatal error: system.ads is incorrectly formatted");
340 Write_Str ("unrecognized or incorrect restrictions pragma: ");
342 while System_Text (P) /= ')'
344 System_Text (P) /= ASCII.LF
346 Write_Char (System_Text (P));
354 -- Test for pragma Detect_Blocking;
356 elsif System_Text (P .. P + 22) = "pragma Detect_Blocking;" then
358 Opt.Detect_Blocking := True;
359 goto Line_Loop_Continue;
363 elsif System_Text (P .. P + 20) = "pragma Discard_Names;" then
365 Opt.Global_Discard_Names := True;
366 goto Line_Loop_Continue;
370 elsif System_Text (P .. P + 22) = "pragma Locking_Policy (" then
372 Opt.Locking_Policy := System_Text (P);
373 Opt.Locking_Policy_Sloc := System_Location;
374 goto Line_Loop_Continue;
378 elsif System_Text (P .. P + 24) = "pragma Normalize_Scalars;" then
380 Opt.Normalize_Scalars := True;
381 Opt.Init_Or_Norm_Scalars := True;
382 goto Line_Loop_Continue;
386 elsif System_Text (P .. P + 19) = "pragma Polling (On);" then
388 Opt.Polling_Required := True;
389 goto Line_Loop_Continue;
391 -- Ignore pragma Pure (System)
393 elsif System_Text (P .. P + 20) = "pragma Pure (System);" then
395 goto Line_Loop_Continue;
399 elsif System_Text (P .. P + 22) = "pragma Queuing_Policy (" then
401 Opt.Queuing_Policy := System_Text (P);
402 Opt.Queuing_Policy_Sloc := System_Location;
403 goto Line_Loop_Continue;
405 -- Suppress_Exception_Locations
407 elsif System_Text (P .. P + 34) =
408 "pragma Suppress_Exception_Locations;"
411 Opt.Exception_Locations_Suppressed := True;
412 goto Line_Loop_Continue;
414 -- Task_Dispatching Policy
416 elsif System_Text (P .. P + 31) =
417 "pragma Task_Dispatching_Policy ("
420 Opt.Task_Dispatching_Policy := System_Text (P);
421 Opt.Task_Dispatching_Policy_Sloc := System_Location;
422 goto Line_Loop_Continue;
424 -- No other pragmas are permitted
426 elsif System_Text (P .. P + 6) = "pragma " then
428 Write_Line ("unrecognized line in system.ads: ");
430 while System_Text (P) /= ')'
431 and then System_Text (P) /= ASCII.LF
433 Write_Char (System_Text (P));
441 -- See if we have a Run_Time_Name
443 elsif System_Text (P .. P + 38) =
444 " Run_Time_Name : constant String := """
449 while System_Text (P) in 'A' .. 'Z'
451 System_Text (P) in 'a' .. 'z'
453 System_Text (P) in '0' .. '9'
455 System_Text (P) = ' '
457 System_Text (P) = '_'
459 Add_Char_To_Name_Buffer (System_Text (P));
463 if System_Text (P) /= '"'
464 or else System_Text (P + 1) /= ';'
465 or else (System_Text (P + 2) /= ASCII.LF
467 System_Text (P + 2) /= ASCII.CR)
471 ("incorrectly formatted Run_Time_Name in system.ads");
476 Run_Time_Name_On_Target := Name_Enter;
479 goto Line_Loop_Continue;
481 -- See if we have an Executable_Extension
483 elsif System_Text (P .. P + 45) =
484 " Executable_Extension : constant String := """
489 while System_Text (P) /= '"'
490 and then System_Text (P) /= ASCII.LF
492 Add_Char_To_Name_Buffer (System_Text (P));
496 if System_Text (P) /= '"' or else System_Text (P + 1) /= ';' then
499 ("incorrectly formatted Executable_Extension in system.ads");
504 Executable_Extension_On_Target := Name_Enter;
507 goto Line_Loop_Continue;
509 -- Next See if we have a configuration parameter
512 Config_Param_Loop : for K in Targparm_Tags loop
513 if System_Text (P + 3 .. P + 2 + Targparm_Str (K)'Length) =
516 P := P + 3 + Targparm_Str (K)'Length;
518 if Targparm_Flags (K) then
521 ("fatal error: system.ads is incorrectly formatted");
522 Write_Str ("duplicate line for parameter: ");
524 for J in Targparm_Str (K)'Range loop
525 Write_Char (Targparm_Str (K).all (J));
533 Targparm_Flags (K) := True;
536 while System_Text (P) /= ':'
537 or else System_Text (P + 1) /= '='
544 while System_Text (P) = ' ' loop
548 Result := (System_Text (P) = 'T');
551 when AAM => AAMP_On_Target := Result;
552 when BDC => Backend_Divide_Checks_On_Target := Result;
553 when BOC => Backend_Overflow_Checks_On_Target := Result;
554 when CLA => Command_Line_Args_On_Target := Result;
555 when CRT => Configurable_Run_Time_On_Target := Result;
556 when CSV => Compiler_System_Version := Result;
557 when D32 => Duration_32_Bits_On_Target := Result;
558 when DEN => Denorm_On_Target := Result;
559 when DSP => Functions_Return_By_DSP_On_Target := Result;
560 when EXS => Exit_Status_Supported_On_Target := Result;
561 when FEL => Frontend_Layout_On_Target := Result;
562 when FFO => Fractional_Fixed_Ops_On_Target := Result;
563 when MOV => Machine_Overflows_On_Target := Result;
564 when MRN => Machine_Rounds_On_Target := Result;
565 when PAS => Preallocated_Stacks_On_Target := Result;
566 when S64 => Support_64_Bit_Divides_On_Target := Result;
567 when SAG => Support_Aggregates_On_Target := Result;
568 when SCA => Support_Composite_Assign_On_Target := Result;
569 when SCC => Support_Composite_Compare_On_Target := Result;
570 when SCD => Stack_Check_Default_On_Target := Result;
571 when SCP => Stack_Check_Probes_On_Target := Result;
572 when SLS => Support_Long_Shifts_On_Target := Result;
573 when SSL => Suppress_Standard_Library_On_Target := Result;
574 when SNZ => Signed_Zeros_On_Target := Result;
575 when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
576 when VMS => OpenVMS_On_Target := Result;
577 when ZCD => ZCX_By_Default_On_Target := Result;
578 when ZCG => GCC_ZCX_Support_On_Target := Result;
580 goto Line_Loop_Continue;
583 -- Here we are seeing a parameter we do not understand. We
584 -- simply ignore this (will happen when an old compiler is
585 -- used to compile a newer version of GNAT which does not
588 end loop Config_Param_Loop;
591 -- Here after processing one line of System spec
593 <<Line_Loop_Continue>>
595 while System_Text (P) /= CR and then System_Text (P) /= LF loop
597 exit when P >= Source_Last;
600 while System_Text (P) = CR or else System_Text (P) = LF loop
602 exit when P >= Source_Last;
605 if P >= Source_Last then
607 Write_Line ("fatal error, system.ads not formatted correctly");
608 Write_Line ("unexpected end of file");
610 raise Unrecoverable_Error;
614 -- Now that OpenVMS_On_Target has been given its definitive value,
615 -- change the multi-unit index character from '~' to '$' for OpenVMS.
617 if OpenVMS_On_Target then
618 Multi_Unit_Index_Character := '$';
621 -- Check no missing target parameter settings (skip for compiler vsn)
623 if not Compiler_System_Version then
624 for K in Targparm_Tags_OK loop
625 if not Targparm_Flags (K) then
628 ("fatal error: system.ads is incorrectly formatted");
629 Write_Str ("missing line for parameter: ");
631 for J in Targparm_Str (K)'Range loop
632 Write_Char (Targparm_Str (K).all (J));
643 raise Unrecoverable_Error;
645 end Get_Target_Parameters;
647 ------------------------------
648 -- Set_Profile_Restrictions --
649 ------------------------------
651 procedure Set_Profile_Restrictions (P : Profile_Name) is
652 R : Restriction_Flags renames Profile_Info (P).Set;
653 V : Restriction_Values renames Profile_Info (P).Value;
655 for J in R'Range loop
657 Restrictions_On_Target.Set (J) := True;
659 if J in All_Parameter_Restrictions then
660 Restrictions_On_Target.Value (J) := V (J);
664 end Set_Profile_Restrictions;