1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2007, 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;
29 with Osint; use Osint;
30 with Output; use Output;
32 package body Targparm is
35 Parameters_Obtained : Boolean := False;
36 -- Set True after first call to Get_Target_Parameters. Used to avoid
37 -- reading system.ads more than once, since it cannot change.
39 -- The following array defines a tag name for each entry
43 BDC, -- Backend_Divide_Checks
44 BOC, -- Backend_Overflow_Checks
45 CLA, -- Command_Line_Args
47 CRT, -- Configurable_Run_Times
48 D32, -- Duration_32_Bits
50 EXS, -- Exit_Status_Supported
51 FEL, -- Frontend_Layout
52 FFO, -- Fractional_Fixed_Ops
54 MOV, -- Machine_Overflows
55 MRN, -- Machine_Rounds
56 PAS, -- Preallocated_Stacks
57 S64, -- Support_64_Bit_Divides
58 SAG, -- Support_Aggregates
59 SCA, -- Support_Composite_Assign
60 SCC, -- Support_Composite_Compare
61 SCD, -- Stack_Check_Default
62 SCP, -- Stack_Check_Probes
63 SLS, -- Support_Long_Shifts
65 SSL, -- Suppress_Standard_Library
66 UAM, -- Use_Ada_Main_Program_Name
68 ZCD, -- ZCX_By_Default
69 ZCG); -- GCC_ZCX_Support
71 Targparm_Flags : array (Targparm_Tags) of Boolean := (others => False);
72 -- Flag is set True if corresponding parameter is scanned
74 -- The following list of string constants gives the parameter names
76 AAM_Str : aliased constant Source_Buffer := "AAMP";
77 BDC_Str : aliased constant Source_Buffer := "Backend_Divide_Checks";
78 BOC_Str : aliased constant Source_Buffer := "Backend_Overflow_Checks";
79 CLA_Str : aliased constant Source_Buffer := "Command_Line_Args";
80 CLI_Str : aliased constant Source_Buffer := "CLI";
81 CRT_Str : aliased constant Source_Buffer := "Configurable_Run_Time";
82 D32_Str : aliased constant Source_Buffer := "Duration_32_Bits";
83 DEN_Str : aliased constant Source_Buffer := "Denorm";
84 EXS_Str : aliased constant Source_Buffer := "Exit_Status_Supported";
85 FEL_Str : aliased constant Source_Buffer := "Frontend_Layout";
86 FFO_Str : aliased constant Source_Buffer := "Fractional_Fixed_Ops";
87 JVM_Str : aliased constant Source_Buffer := "JVM";
88 MOV_Str : aliased constant Source_Buffer := "Machine_Overflows";
89 MRN_Str : aliased constant Source_Buffer := "Machine_Rounds";
90 PAS_Str : aliased constant Source_Buffer := "Preallocated_Stacks";
91 S64_Str : aliased constant Source_Buffer := "Support_64_Bit_Divides";
92 SAG_Str : aliased constant Source_Buffer := "Support_Aggregates";
93 SCA_Str : aliased constant Source_Buffer := "Support_Composite_Assign";
94 SCC_Str : aliased constant Source_Buffer := "Support_Composite_Compare";
95 SCD_Str : aliased constant Source_Buffer := "Stack_Check_Default";
96 SCP_Str : aliased constant Source_Buffer := "Stack_Check_Probes";
97 SLS_Str : aliased constant Source_Buffer := "Support_Long_Shifts";
98 SNZ_Str : aliased constant Source_Buffer := "Signed_Zeros";
99 SSL_Str : aliased constant Source_Buffer := "Suppress_Standard_Library";
100 UAM_Str : aliased constant Source_Buffer := "Use_Ada_Main_Program_Name";
101 VMS_Str : aliased constant Source_Buffer := "OpenVMS";
102 ZCD_Str : aliased constant Source_Buffer := "ZCX_By_Default";
103 ZCG_Str : aliased constant Source_Buffer := "GCC_ZCX_Support";
105 -- The following defines a set of pointers to the above strings,
106 -- indexed by the tag values.
108 type Buffer_Ptr is access constant Source_Buffer;
109 Targparm_Str : constant array (Targparm_Tags) of Buffer_Ptr :=
139 -----------------------
140 -- Local Subprograms --
141 -----------------------
143 procedure Set_Profile_Restrictions (P : Profile_Name);
144 -- Set Restrictions_On_Target for the given profile
146 ---------------------------
147 -- Get_Target_Parameters --
148 ---------------------------
150 -- Version which reads in system.ads
152 procedure Get_Target_Parameters is
153 Text : Source_Buffer_Ptr;
157 if Parameters_Obtained then
161 Name_Buffer (1 .. 10) := "system.ads";
164 Read_Source_File (Name_Find, Lo => 0, Hi => Hi, Src => Text);
167 Write_Line ("fatal error, run-time library not installed correctly");
168 Write_Line ("cannot locate file system.ads");
169 raise Unrecoverable_Error;
172 Targparm.Get_Target_Parameters
173 (System_Text => Text,
176 end Get_Target_Parameters;
178 -- Version where caller supplies system.ads text
180 procedure Get_Target_Parameters
181 (System_Text : Source_Buffer_Ptr;
182 Source_First : Source_Ptr;
183 Source_Last : Source_Ptr)
186 -- Scans source buffer containing source of system.ads
188 Fatal : Boolean := False;
189 -- Set True if a fatal error is detected
192 -- Records boolean from system line
195 if Parameters_Obtained then
198 Parameters_Obtained := True;
201 Opt.Address_Is_Private := False;
204 Line_Loop : while System_Text (P .. P + 10) /= "end System;" loop
206 -- Skip comments quickly
208 if System_Text (P) = '-' then
209 goto Line_Loop_Continue;
211 -- Test for type Address is private
213 elsif System_Text (P .. P + 26) = " type Address is private;" then
214 Opt.Address_Is_Private := True;
216 goto Line_Loop_Continue;
218 -- Test for pragma Profile (Ravenscar);
220 elsif System_Text (P .. P + 26) =
221 "pragma Profile (Ravenscar);"
223 Set_Profile_Restrictions (Ravenscar);
224 Opt.Task_Dispatching_Policy := 'F';
225 Opt.Locking_Policy := 'C';
227 goto Line_Loop_Continue;
229 -- Test for pragma Profile (Restricted);
231 elsif System_Text (P .. P + 27) =
232 "pragma Profile (Restricted);"
234 Set_Profile_Restrictions (Restricted);
236 goto Line_Loop_Continue;
238 -- Test for pragma Restrictions
240 elsif System_Text (P .. P + 20) = "pragma Restrictions (" then
243 Rloop : for K in All_Boolean_Restrictions loop
245 Rname : constant String := Restriction_Id'Image (K);
248 for J in Rname'Range loop
249 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
256 if System_Text (P + Rname'Length) = ')' then
257 Restrictions_On_Target.Set (K) := True;
258 goto Line_Loop_Continue;
266 Ploop : for K in All_Parameter_Restrictions loop
268 Rname : constant String :=
269 All_Parameter_Restrictions'Image (K);
275 for J in Rname'Range loop
276 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
283 if System_Text (P + Rname'Length .. P + Rname'Length + 3) =
286 P := P + Rname'Length + 4;
290 if System_Text (P) in '0' .. '9' then
292 pragma Unsuppress (Overflow_Check);
295 -- Accumulate next digit
298 Character'Pos (System_Text (P)) -
302 -- On overflow, we just ignore the pragma since
303 -- that is the standard handling in this case.
305 when Constraint_Error =>
306 goto Line_Loop_Continue;
309 elsif System_Text (P) = '_' then
312 elsif System_Text (P) = ')' then
313 Restrictions_On_Target.Value (K) := V;
314 Restrictions_On_Target.Set (K) := True;
315 goto Line_Loop_Continue;
335 ("fatal error: system.ads is incorrectly formatted");
336 Write_Str ("unrecognized or incorrect restrictions pragma: ");
338 while System_Text (P) /= ')'
340 System_Text (P) /= ASCII.LF
342 Write_Char (System_Text (P));
350 -- Test for pragma Detect_Blocking;
352 elsif System_Text (P .. P + 22) = "pragma Detect_Blocking;" then
354 Opt.Detect_Blocking := True;
355 goto Line_Loop_Continue;
359 elsif System_Text (P .. P + 20) = "pragma Discard_Names;" then
361 Opt.Global_Discard_Names := True;
362 goto Line_Loop_Continue;
366 elsif System_Text (P .. P + 22) = "pragma Locking_Policy (" then
368 Opt.Locking_Policy := System_Text (P);
369 Opt.Locking_Policy_Sloc := System_Location;
370 goto Line_Loop_Continue;
374 elsif System_Text (P .. P + 24) = "pragma Normalize_Scalars;" then
376 Opt.Normalize_Scalars := True;
377 Opt.Init_Or_Norm_Scalars := True;
378 goto Line_Loop_Continue;
382 elsif System_Text (P .. P + 19) = "pragma Polling (On);" then
384 Opt.Polling_Required := True;
385 goto Line_Loop_Continue;
387 -- Ignore pragma Pure (System)
389 elsif System_Text (P .. P + 20) = "pragma Pure (System);" then
391 goto Line_Loop_Continue;
395 elsif System_Text (P .. P + 22) = "pragma Queuing_Policy (" then
397 Opt.Queuing_Policy := System_Text (P);
398 Opt.Queuing_Policy_Sloc := System_Location;
399 goto Line_Loop_Continue;
401 -- Suppress_Exception_Locations
403 elsif System_Text (P .. P + 34) =
404 "pragma Suppress_Exception_Locations;"
407 Opt.Exception_Locations_Suppressed := True;
408 goto Line_Loop_Continue;
410 -- Task_Dispatching Policy
412 elsif System_Text (P .. P + 31) =
413 "pragma Task_Dispatching_Policy ("
416 Opt.Task_Dispatching_Policy := System_Text (P);
417 Opt.Task_Dispatching_Policy_Sloc := System_Location;
418 goto Line_Loop_Continue;
420 -- No other pragmas are permitted
422 elsif System_Text (P .. P + 6) = "pragma " then
424 Write_Line ("unrecognized line in system.ads: ");
426 while System_Text (P) /= ')'
427 and then System_Text (P) /= ASCII.LF
429 Write_Char (System_Text (P));
437 -- See if we have a Run_Time_Name
439 elsif System_Text (P .. P + 38) =
440 " Run_Time_Name : constant String := """
445 while System_Text (P) in 'A' .. 'Z'
447 System_Text (P) in 'a' .. 'z'
449 System_Text (P) in '0' .. '9'
451 System_Text (P) = ' '
453 System_Text (P) = '_'
455 Add_Char_To_Name_Buffer (System_Text (P));
459 if System_Text (P) /= '"'
460 or else System_Text (P + 1) /= ';'
461 or else (System_Text (P + 2) /= ASCII.LF
463 System_Text (P + 2) /= ASCII.CR)
467 ("incorrectly formatted Run_Time_Name in system.ads");
472 Run_Time_Name_On_Target := Name_Enter;
475 goto Line_Loop_Continue;
477 -- See if we have an Executable_Extension
479 elsif System_Text (P .. P + 45) =
480 " Executable_Extension : constant String := """
485 while System_Text (P) /= '"'
486 and then System_Text (P) /= ASCII.LF
488 Add_Char_To_Name_Buffer (System_Text (P));
492 if System_Text (P) /= '"' or else System_Text (P + 1) /= ';' then
495 ("incorrectly formatted Executable_Extension in system.ads");
500 Executable_Extension_On_Target := Name_Enter;
503 goto Line_Loop_Continue;
505 -- Next See if we have a configuration parameter
508 Config_Param_Loop : for K in Targparm_Tags loop
509 if System_Text (P + 3 .. P + 2 + Targparm_Str (K)'Length) =
512 P := P + 3 + Targparm_Str (K)'Length;
514 if Targparm_Flags (K) then
517 ("fatal error: system.ads is incorrectly formatted");
518 Write_Str ("duplicate line for parameter: ");
520 for J in Targparm_Str (K)'Range loop
521 Write_Char (Targparm_Str (K).all (J));
529 Targparm_Flags (K) := True;
532 while System_Text (P) /= ':'
533 or else System_Text (P + 1) /= '='
540 while System_Text (P) = ' ' loop
544 Result := (System_Text (P) = 'T');
547 when AAM => AAMP_On_Target := Result;
548 when BDC => Backend_Divide_Checks_On_Target := Result;
549 when BOC => Backend_Overflow_Checks_On_Target := Result;
550 when CLA => Command_Line_Args_On_Target := Result;
553 VM_Target := CLI_Target;
556 when CRT => Configurable_Run_Time_On_Target := Result;
557 when D32 => Duration_32_Bits_On_Target := Result;
558 when DEN => Denorm_On_Target := Result;
559 when EXS => Exit_Status_Supported_On_Target := Result;
560 when FEL => Frontend_Layout_On_Target := Result;
561 when FFO => Fractional_Fixed_Ops_On_Target := Result;
564 VM_Target := JVM_Target;
567 when MOV => Machine_Overflows_On_Target := Result;
568 when MRN => Machine_Rounds_On_Target := Result;
569 when PAS => Preallocated_Stacks_On_Target := Result;
570 when S64 => Support_64_Bit_Divides_On_Target := Result;
571 when SAG => Support_Aggregates_On_Target := Result;
572 when SCA => Support_Composite_Assign_On_Target := Result;
573 when SCC => Support_Composite_Compare_On_Target := Result;
574 when SCD => Stack_Check_Default_On_Target := Result;
575 when SCP => Stack_Check_Probes_On_Target := Result;
576 when SLS => Support_Long_Shifts_On_Target := Result;
577 when SSL => Suppress_Standard_Library_On_Target := Result;
578 when SNZ => Signed_Zeros_On_Target := Result;
579 when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
580 when VMS => OpenVMS_On_Target := Result;
581 when ZCD => ZCX_By_Default_On_Target := Result;
582 when ZCG => GCC_ZCX_Support_On_Target := Result;
584 goto Line_Loop_Continue;
587 -- Here we are seeing a parameter we do not understand. We
588 -- simply ignore this (will happen when an old compiler is
589 -- used to compile a newer version of GNAT which does not
592 end loop Config_Param_Loop;
595 -- Here after processing one line of System spec
597 <<Line_Loop_Continue>>
599 while System_Text (P) /= CR and then System_Text (P) /= LF loop
601 exit when P >= Source_Last;
604 while System_Text (P) = CR or else System_Text (P) = LF loop
606 exit when P >= Source_Last;
609 if P >= Source_Last then
611 Write_Line ("fatal error, system.ads not formatted correctly");
612 Write_Line ("unexpected end of file");
614 raise Unrecoverable_Error;
618 -- Now that OpenVMS_On_Target has been given its definitive value,
619 -- change the multi-unit index character from '~' to '$' for OpenVMS.
621 if OpenVMS_On_Target then
622 Multi_Unit_Index_Character := '$';
626 raise Unrecoverable_Error;
628 end Get_Target_Parameters;
630 ------------------------------
631 -- Set_Profile_Restrictions --
632 ------------------------------
634 procedure Set_Profile_Restrictions (P : Profile_Name) is
635 R : Restriction_Flags renames Profile_Info (P).Set;
636 V : Restriction_Values renames Profile_Info (P).Value;
638 for J in R'Range loop
640 Restrictions_On_Target.Set (J) := True;
642 if J in All_Parameter_Restrictions then
643 Restrictions_On_Target.Value (J) := V (J);
647 end Set_Profile_Restrictions;