1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2011, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Csets; use Csets;
28 with Osint; use Osint;
29 with Output; use Output;
31 package body Targparm is
34 Parameters_Obtained : Boolean := False;
35 -- Set True after first call to Get_Target_Parameters. Used to avoid
36 -- reading system.ads more than once, since it cannot change.
38 -- The following array defines a tag name for each entry
42 ACR, -- Always_Compatible_Rep
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 RTX, -- RTX_RTSS_Kernel_Module
58 SAG, -- Support_Aggregates
59 SCA, -- Support_Composite_Assign
60 SCC, -- Support_Composite_Compare
61 SCD, -- Stack_Check_Default
62 SCL, -- Stack_Check_Limits
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
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 ACR_Str : aliased constant Source_Buffer := "Always_Compatible_Rep";
78 BDC_Str : aliased constant Source_Buffer := "Backend_Divide_Checks";
79 BOC_Str : aliased constant Source_Buffer := "Backend_Overflow_Checks";
80 CLA_Str : aliased constant Source_Buffer := "Command_Line_Args";
81 CLI_Str : aliased constant Source_Buffer := "CLI";
82 CRT_Str : aliased constant Source_Buffer := "Configurable_Run_Time";
83 D32_Str : aliased constant Source_Buffer := "Duration_32_Bits";
84 DEN_Str : aliased constant Source_Buffer := "Denorm";
85 EXS_Str : aliased constant Source_Buffer := "Exit_Status_Supported";
86 FEL_Str : aliased constant Source_Buffer := "Frontend_Layout";
87 FFO_Str : aliased constant Source_Buffer := "Fractional_Fixed_Ops";
88 JVM_Str : aliased constant Source_Buffer := "JVM";
89 MOV_Str : aliased constant Source_Buffer := "Machine_Overflows";
90 MRN_Str : aliased constant Source_Buffer := "Machine_Rounds";
91 PAS_Str : aliased constant Source_Buffer := "Preallocated_Stacks";
92 RTX_Str : aliased constant Source_Buffer := "RTX_RTSS_Kernel_Module";
93 SAG_Str : aliased constant Source_Buffer := "Support_Aggregates";
94 SCA_Str : aliased constant Source_Buffer := "Support_Composite_Assign";
95 SCC_Str : aliased constant Source_Buffer := "Support_Composite_Compare";
96 SCD_Str : aliased constant Source_Buffer := "Stack_Check_Default";
97 SCL_Str : aliased constant Source_Buffer := "Stack_Check_Limits";
98 SCP_Str : aliased constant Source_Buffer := "Stack_Check_Probes";
99 SLS_Str : aliased constant Source_Buffer := "Support_Long_Shifts";
100 SNZ_Str : aliased constant Source_Buffer := "Signed_Zeros";
101 SSL_Str : aliased constant Source_Buffer := "Suppress_Standard_Library";
102 UAM_Str : aliased constant Source_Buffer := "Use_Ada_Main_Program_Name";
103 VMS_Str : aliased constant Source_Buffer := "OpenVMS";
104 ZCD_Str : aliased constant Source_Buffer := "ZCX_By_Default";
106 -- The following defines a set of pointers to the above strings,
107 -- indexed by the tag values.
109 type Buffer_Ptr is access constant Source_Buffer;
110 Targparm_Str : constant array (Targparm_Tags) of Buffer_Ptr :=
141 -----------------------
142 -- Local Subprograms --
143 -----------------------
145 procedure Set_Profile_Restrictions (P : Profile_Name);
146 -- Set Restrictions_On_Target for the given profile
148 ---------------------------
149 -- Get_Target_Parameters --
150 ---------------------------
152 -- Version which reads in system.ads
154 procedure Get_Target_Parameters is
155 Text : Source_Buffer_Ptr;
159 if Parameters_Obtained then
163 Name_Buffer (1 .. 10) := "system.ads";
166 Read_Source_File (Name_Find, Lo => 0, Hi => Hi, Src => Text);
169 Write_Line ("fatal error, run-time library not installed correctly");
170 Write_Line ("cannot locate file system.ads");
171 raise Unrecoverable_Error;
174 Get_Target_Parameters
175 (System_Text => Text,
178 end Get_Target_Parameters;
180 -- Version where caller supplies system.ads text
182 procedure Get_Target_Parameters
183 (System_Text : Source_Buffer_Ptr;
184 Source_First : Source_Ptr;
185 Source_Last : Source_Ptr)
188 -- Scans source buffer containing source of system.ads
190 Fatal : Boolean := False;
191 -- Set True if a fatal error is detected
194 -- Records boolean from system line
197 if Parameters_Obtained then
200 Parameters_Obtained := True;
203 Opt.Address_Is_Private := False;
206 Line_Loop : while System_Text (P .. P + 10) /= "end System;" loop
208 -- Skip comments quickly
210 if System_Text (P) = '-' then
211 goto Line_Loop_Continue;
213 -- Test for type Address is private
215 elsif System_Text (P .. P + 26) = " type Address is private;" then
216 Opt.Address_Is_Private := True;
218 goto Line_Loop_Continue;
220 -- Test for pragma Profile (Ravenscar);
222 elsif System_Text (P .. P + 26) =
223 "pragma Profile (Ravenscar);"
225 Set_Profile_Restrictions (Ravenscar);
226 Opt.Task_Dispatching_Policy := 'F';
227 Opt.Locking_Policy := 'C';
229 goto Line_Loop_Continue;
231 -- Test for pragma Profile (Restricted);
233 elsif System_Text (P .. P + 27) =
234 "pragma Profile (Restricted);"
236 Set_Profile_Restrictions (Restricted);
238 goto Line_Loop_Continue;
240 -- Test for pragma Restrictions
242 elsif System_Text (P .. P + 20) = "pragma Restrictions (" then
245 Rloop : for K in All_Boolean_Restrictions loop
247 Rname : constant String := Restriction_Id'Image (K);
250 for J in Rname'Range loop
251 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
258 if System_Text (P + Rname'Length) = ')' then
259 Restrictions_On_Target.Set (K) := True;
260 goto Line_Loop_Continue;
268 Ploop : for K in All_Parameter_Restrictions loop
270 Rname : constant String :=
271 All_Parameter_Restrictions'Image (K);
277 for J in Rname'Range loop
278 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
285 if System_Text (P + Rname'Length .. P + Rname'Length + 3) =
288 P := P + Rname'Length + 4;
292 if System_Text (P) in '0' .. '9' then
294 pragma Unsuppress (Overflow_Check);
297 -- Accumulate next digit
300 Character'Pos (System_Text (P)) -
304 -- On overflow, we just ignore the pragma since
305 -- that is the standard handling in this case.
307 when Constraint_Error =>
308 goto Line_Loop_Continue;
311 elsif System_Text (P) = '_' then
314 elsif System_Text (P) = ')' then
315 Restrictions_On_Target.Value (K) := V;
316 Restrictions_On_Target.Set (K) := True;
317 goto Line_Loop_Continue;
337 ("fatal error: system.ads is incorrectly formatted");
338 Write_Str ("unrecognized or incorrect restrictions pragma: ");
340 while System_Text (P) /= ')'
342 System_Text (P) /= ASCII.LF
344 Write_Char (System_Text (P));
352 -- Test for pragma Detect_Blocking;
354 elsif System_Text (P .. P + 22) = "pragma Detect_Blocking;" then
356 Opt.Detect_Blocking := True;
357 goto Line_Loop_Continue;
361 elsif System_Text (P .. P + 20) = "pragma Discard_Names;" then
363 Opt.Global_Discard_Names := True;
364 goto Line_Loop_Continue;
368 elsif System_Text (P .. P + 22) = "pragma Locking_Policy (" then
370 Opt.Locking_Policy := System_Text (P);
371 Opt.Locking_Policy_Sloc := System_Location;
372 goto Line_Loop_Continue;
376 elsif System_Text (P .. P + 24) = "pragma Normalize_Scalars;" then
378 Opt.Normalize_Scalars := True;
379 Opt.Init_Or_Norm_Scalars := True;
380 goto Line_Loop_Continue;
384 elsif System_Text (P .. P + 19) = "pragma Polling (On);" then
386 Opt.Polling_Required := True;
387 goto Line_Loop_Continue;
389 -- Ignore pragma Pure (System)
391 elsif System_Text (P .. P + 20) = "pragma Pure (System);" then
393 goto Line_Loop_Continue;
397 elsif System_Text (P .. P + 22) = "pragma Queuing_Policy (" then
399 Opt.Queuing_Policy := System_Text (P);
400 Opt.Queuing_Policy_Sloc := System_Location;
401 goto Line_Loop_Continue;
403 -- Suppress_Exception_Locations
405 elsif System_Text (P .. P + 35) =
406 "pragma Suppress_Exception_Locations;"
409 Opt.Exception_Locations_Suppressed := True;
410 goto Line_Loop_Continue;
412 -- Task_Dispatching Policy
414 elsif System_Text (P .. P + 31) =
415 "pragma Task_Dispatching_Policy ("
418 Opt.Task_Dispatching_Policy := System_Text (P);
419 Opt.Task_Dispatching_Policy_Sloc := System_Location;
420 goto Line_Loop_Continue;
422 -- No other pragmas are permitted
424 elsif System_Text (P .. P + 6) = "pragma " then
426 Write_Line ("unrecognized line in system.ads: ");
428 while System_Text (P) /= ')'
429 and then System_Text (P) /= ASCII.LF
431 Write_Char (System_Text (P));
439 -- See if we have a Run_Time_Name
441 elsif System_Text (P .. P + 38) =
442 " Run_Time_Name : constant String := """
447 while System_Text (P) in 'A' .. 'Z'
449 System_Text (P) in 'a' .. 'z'
451 System_Text (P) in '0' .. '9'
453 System_Text (P) = ' '
455 System_Text (P) = '_'
457 Add_Char_To_Name_Buffer (System_Text (P));
461 if System_Text (P) /= '"'
462 or else System_Text (P + 1) /= ';'
463 or else (System_Text (P + 2) /= ASCII.LF
465 System_Text (P + 2) /= ASCII.CR)
469 ("incorrectly formatted Run_Time_Name in system.ads");
474 Run_Time_Name_On_Target := Name_Enter;
477 goto Line_Loop_Continue;
479 -- See if we have an Executable_Extension
481 elsif System_Text (P .. P + 45) =
482 " Executable_Extension : constant String := """
487 while System_Text (P) /= '"'
488 and then System_Text (P) /= ASCII.LF
490 Add_Char_To_Name_Buffer (System_Text (P));
494 if System_Text (P) /= '"' or else System_Text (P + 1) /= ';' then
497 ("incorrectly formatted Executable_Extension in system.ads");
502 Executable_Extension_On_Target := Name_Enter;
505 goto Line_Loop_Continue;
507 -- Next see if we have a configuration parameter
510 Config_Param_Loop : for K in Targparm_Tags loop
511 if System_Text (P + 3 .. P + 2 + Targparm_Str (K)'Length) =
514 P := P + 3 + Targparm_Str (K)'Length;
516 if Targparm_Flags (K) then
519 ("fatal error: system.ads is incorrectly formatted");
520 Write_Str ("duplicate line for parameter: ");
522 for J in Targparm_Str (K)'Range loop
523 Write_Char (Targparm_Str (K).all (J));
531 Targparm_Flags (K) := True;
534 while System_Text (P) /= ':'
535 or else System_Text (P + 1) /= '='
542 while System_Text (P) = ' ' loop
546 Result := (System_Text (P) = 'T');
549 when AAM => AAMP_On_Target := Result;
550 when ACR => Always_Compatible_Rep_On_Target := Result;
551 when BDC => Backend_Divide_Checks_On_Target := Result;
552 when BOC => Backend_Overflow_Checks_On_Target := Result;
553 when CLA => Command_Line_Args_On_Target := Result;
556 VM_Target := CLI_Target;
557 Tagged_Type_Expansion := False;
560 when CRT => Configurable_Run_Time_On_Target := Result;
561 when D32 => Duration_32_Bits_On_Target := Result;
562 when DEN => Denorm_On_Target := Result;
563 when EXS => Exit_Status_Supported_On_Target := Result;
564 when FEL => Frontend_Layout_On_Target := Result;
565 when FFO => Fractional_Fixed_Ops_On_Target := Result;
568 VM_Target := JVM_Target;
569 Tagged_Type_Expansion := False;
572 when MOV => Machine_Overflows_On_Target := Result;
573 when MRN => Machine_Rounds_On_Target := Result;
574 when PAS => Preallocated_Stacks_On_Target := Result;
575 when RTX => RTX_RTSS_Kernel_Module_On_Target := Result;
576 when SAG => Support_Aggregates_On_Target := Result;
577 when SCA => Support_Composite_Assign_On_Target := Result;
578 when SCC => Support_Composite_Compare_On_Target := Result;
579 when SCD => Stack_Check_Default_On_Target := Result;
580 when SCL => Stack_Check_Limits_On_Target := Result;
581 when SCP => Stack_Check_Probes_On_Target := Result;
582 when SLS => Support_Long_Shifts_On_Target := Result;
583 when SSL => Suppress_Standard_Library_On_Target := Result;
584 when SNZ => Signed_Zeros_On_Target := Result;
585 when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
586 when VMS => OpenVMS_On_Target := Result;
587 when ZCD => ZCX_By_Default_On_Target := Result;
589 goto Line_Loop_Continue;
592 -- Here we are seeing a parameter we do not understand. We
593 -- simply ignore this (will happen when an old compiler is
594 -- used to compile a newer version of GNAT which does not
595 -- support the parameter).
597 end loop Config_Param_Loop;
600 -- Here after processing one line of System spec
602 <<Line_Loop_Continue>>
604 while System_Text (P) /= CR and then System_Text (P) /= LF loop
606 exit when P >= Source_Last;
609 while System_Text (P) = CR or else System_Text (P) = LF loop
611 exit when P >= Source_Last;
614 if P >= Source_Last then
616 Write_Line ("fatal error, system.ads not formatted correctly");
617 Write_Line ("unexpected end of file");
619 raise Unrecoverable_Error;
623 -- Now that OpenVMS_On_Target has been given its definitive value,
624 -- change the multi-unit index character from '~' to '$' for OpenVMS.
626 if OpenVMS_On_Target then
627 Multi_Unit_Index_Character := '$';
631 raise Unrecoverable_Error;
633 end Get_Target_Parameters;
635 ------------------------------
636 -- Set_Profile_Restrictions --
637 ------------------------------
639 procedure Set_Profile_Restrictions (P : Profile_Name) is
640 R : Restriction_Flags renames Profile_Info (P).Set;
641 V : Restriction_Values renames Profile_Info (P).Value;
643 for J in R'Range loop
645 Restrictions_On_Target.Set (J) := True;
647 if J in All_Parameter_Restrictions then
648 Restrictions_On_Target.Value (J) := V (J);
652 end Set_Profile_Restrictions;