1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2014, 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 ASD
, -- Atomic_Sync_Default
44 BDC
, -- Backend_Divide_Checks
45 BOC
, -- Backend_Overflow_Checks
46 CLA
, -- Command_Line_Args
48 CRT
, -- Configurable_Run_Times
49 D32
, -- Duration_32_Bits
51 EXS
, -- Exit_Status_Supported
52 FEL
, -- Frontend_Layout
53 FFO
, -- Fractional_Fixed_Ops
55 MOV
, -- Machine_Overflows
56 MRN
, -- Machine_Rounds
57 PAS
, -- Preallocated_Stacks
58 SAG
, -- Support_Aggregates
59 SAP
, -- Support_Atomic_Primitives
60 SCA
, -- Support_Composite_Assign
61 SCC
, -- Support_Composite_Compare
62 SCD
, -- Stack_Check_Default
63 SCL
, -- Stack_Check_Limits
64 SCP
, -- Stack_Check_Probes
65 SLS
, -- Support_Long_Shifts
67 SSL
, -- Suppress_Standard_Library
68 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 ASD_Str
: aliased constant Source_Buffer
:= "Atomic_Sync_Default";
79 BDC_Str
: aliased constant Source_Buffer
:= "Backend_Divide_Checks";
80 BOC_Str
: aliased constant Source_Buffer
:= "Backend_Overflow_Checks";
81 CLA_Str
: aliased constant Source_Buffer
:= "Command_Line_Args";
82 CLI_Str
: aliased constant Source_Buffer
:= "CLI";
83 CRT_Str
: aliased constant Source_Buffer
:= "Configurable_Run_Time";
84 D32_Str
: aliased constant Source_Buffer
:= "Duration_32_Bits";
85 DEN_Str
: aliased constant Source_Buffer
:= "Denorm";
86 EXS_Str
: aliased constant Source_Buffer
:= "Exit_Status_Supported";
87 FEL_Str
: aliased constant Source_Buffer
:= "Frontend_Layout";
88 FFO_Str
: aliased constant Source_Buffer
:= "Fractional_Fixed_Ops";
89 JVM_Str
: aliased constant Source_Buffer
:= "JVM";
90 MOV_Str
: aliased constant Source_Buffer
:= "Machine_Overflows";
91 MRN_Str
: aliased constant Source_Buffer
:= "Machine_Rounds";
92 PAS_Str
: aliased constant Source_Buffer
:= "Preallocated_Stacks";
93 SAG_Str
: aliased constant Source_Buffer
:= "Support_Aggregates";
94 SAP_Str
: aliased constant Source_Buffer
:= "Support_Atomic_Primitives";
95 SCA_Str
: aliased constant Source_Buffer
:= "Support_Composite_Assign";
96 SCC_Str
: aliased constant Source_Buffer
:= "Support_Composite_Compare";
97 SCD_Str
: aliased constant Source_Buffer
:= "Stack_Check_Default";
98 SCL_Str
: aliased constant Source_Buffer
:= "Stack_Check_Limits";
99 SCP_Str
: aliased constant Source_Buffer
:= "Stack_Check_Probes";
100 SLS_Str
: aliased constant Source_Buffer
:= "Support_Long_Shifts";
101 SNZ_Str
: aliased constant Source_Buffer
:= "Signed_Zeros";
102 SSL_Str
: aliased constant Source_Buffer
:= "Suppress_Standard_Library";
103 UAM_Str
: aliased constant Source_Buffer
:= "Use_Ada_Main_Program_Name";
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
155 (Make_Id
: Make_Id_Type
:= null;
156 Make_SC
: Make_SC_Type
:= null;
157 Set_RND
: Set_RND_Type
:= null)
159 Text
: Source_Buffer_Ptr
;
163 if Parameters_Obtained
then
167 Name_Buffer
(1 .. 10) := "system.ads";
170 Read_Source_File
(Name_Find
, Lo
=> 0, Hi
=> Hi
, Src
=> Text
);
173 Write_Line
("fatal error, run-time library not installed correctly");
174 Write_Line
("cannot locate file system.ads");
175 raise Unrecoverable_Error
;
178 Get_Target_Parameters
179 (System_Text
=> Text
,
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
;
193 Make_Id
: Make_Id_Type
:= null;
194 Make_SC
: Make_SC_Type
:= null;
195 Set_RND
: Set_RND_Type
:= null)
198 -- Scans source buffer containing source of system.ads
200 Fatal
: Boolean := False;
201 -- Set True if a fatal error is detected
204 -- Records boolean from system line
207 if Parameters_Obtained
then
210 Parameters_Obtained
:= True;
213 Opt
.Address_Is_Private
:= False;
215 -- Loop through source lines
217 -- Note: in the case or pragmas, we are only interested in pragmas that
218 -- appear as configuration pragmas. These are left justified, so they
219 -- do not have three spaces at the start. Pragmas appearing within the
220 -- package (like Pure and No_Elaboration_Code_All) will have the three
221 -- spaces at the start and so will be ignored.
223 -- For a special exception, see processing for pragma Pure below
226 Line_Loop
: while System_Text
(P
.. P
+ 10) /= "end System;" loop
228 -- Skip comments quickly
230 if System_Text
(P
) = '-' then
231 goto Line_Loop_Continue
;
233 -- Test for type Address is private
235 elsif System_Text
(P
.. P
+ 26) = " type Address is private;" then
236 Opt
.Address_Is_Private
:= True;
238 goto Line_Loop_Continue
;
240 -- Test for pragma Profile (Ravenscar);
242 elsif System_Text
(P
.. P
+ 26) =
243 "pragma Profile (Ravenscar);"
245 Set_Profile_Restrictions
(Ravenscar
);
246 Opt
.Task_Dispatching_Policy
:= 'F';
247 Opt
.Locking_Policy
:= 'C';
249 goto Line_Loop_Continue
;
251 -- Test for pragma Profile (Restricted);
253 elsif System_Text
(P
.. P
+ 27) =
254 "pragma Profile (Restricted);"
256 Set_Profile_Restrictions
(Restricted
);
258 goto Line_Loop_Continue
;
260 -- Test for pragma Restrictions
262 elsif System_Text
(P
.. P
+ 20) = "pragma Restrictions (" then
265 Rloop
: for K
in All_Boolean_Restrictions
loop
267 Rname
: constant String := Restriction_Id
'Image (K
);
270 for J
in Rname
'Range loop
271 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
278 if System_Text
(P
+ Rname
'Length) = ')' then
279 Restrictions_On_Target
.Set
(K
) := True;
280 goto Line_Loop_Continue
;
288 Ploop
: for K
in All_Parameter_Restrictions
loop
290 Rname
: constant String :=
291 All_Parameter_Restrictions
'Image (K
);
297 for J
in Rname
'Range loop
298 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
305 if System_Text
(P
+ Rname
'Length .. P
+ Rname
'Length + 3) =
308 P
:= P
+ Rname
'Length + 4;
312 if System_Text
(P
) in '0' .. '9' then
314 pragma Unsuppress
(Overflow_Check
);
317 -- Accumulate next digit
320 Character'Pos (System_Text
(P
)) -
324 -- On overflow, we just ignore the pragma since
325 -- that is the standard handling in this case.
327 when Constraint_Error
=>
328 goto Line_Loop_Continue
;
331 elsif System_Text
(P
) = '_' then
334 elsif System_Text
(P
) = ')' then
335 Restrictions_On_Target
.Value
(K
) := V
;
336 Restrictions_On_Target
.Set
(K
) := True;
337 goto Line_Loop_Continue
;
355 -- No_Dependence case
357 if System_Text
(P
.. P
+ 16) = "No_Dependence => " then
360 -- Skip this processing (and simply ignore No_Dependence lines)
361 -- if caller did not supply the three subprograms we need to
362 -- process these lines.
364 if Make_Id
= null then
365 goto Line_Loop_Continue
;
368 -- We have scanned out "pragma Restrictions (No_Dependence =>"
378 -- Loop through components of name, building up Unit
382 while System_Text
(P
) /= '.'
384 System_Text
(P
) /= ')'
389 Id
:= Make_Id
(System_Text
(Start
.. P
- 1));
391 -- If first name, just capture the identifier
396 Unit
:= Make_SC
(Unit
, Id
);
399 exit when System_Text
(P
) = ')';
404 goto Line_Loop_Continue
;
408 -- Here if unrecognizable restrictions pragma form
412 ("fatal error: system.ads is incorrectly formatted");
413 Write_Str
("unrecognized or incorrect restrictions pragma: ");
415 while System_Text
(P
) /= ')'
417 System_Text
(P
) /= ASCII
.LF
419 Write_Char
(System_Text
(P
));
427 -- Test for pragma Detect_Blocking;
429 elsif System_Text
(P
.. P
+ 22) = "pragma Detect_Blocking;" then
431 Opt
.Detect_Blocking
:= True;
432 goto Line_Loop_Continue
;
436 elsif System_Text
(P
.. P
+ 20) = "pragma Discard_Names;" then
438 Opt
.Global_Discard_Names
:= True;
439 goto Line_Loop_Continue
;
443 elsif System_Text
(P
.. P
+ 22) = "pragma Locking_Policy (" then
445 Opt
.Locking_Policy
:= System_Text
(P
);
446 Opt
.Locking_Policy_Sloc
:= System_Location
;
447 goto Line_Loop_Continue
;
451 elsif System_Text
(P
.. P
+ 24) = "pragma Normalize_Scalars;" then
453 Opt
.Normalize_Scalars
:= True;
454 Opt
.Init_Or_Norm_Scalars
:= True;
455 goto Line_Loop_Continue
;
457 -- Partition_Elaboration_Policy
459 elsif System_Text
(P
.. P
+ 36) =
460 "pragma Partition_Elaboration_Policy ("
463 Opt
.Partition_Elaboration_Policy
:= System_Text
(P
);
464 Opt
.Partition_Elaboration_Policy_Sloc
:= System_Location
;
465 goto Line_Loop_Continue
;
469 elsif System_Text
(P
.. P
+ 19) = "pragma Polling (On);" then
471 Opt
.Polling_Required
:= True;
472 goto Line_Loop_Continue
;
476 elsif System_Text
(P
.. P
+ 22) = "pragma Queuing_Policy (" then
478 Opt
.Queuing_Policy
:= System_Text
(P
);
479 Opt
.Queuing_Policy_Sloc
:= System_Location
;
480 goto Line_Loop_Continue
;
482 -- Suppress_Exception_Locations
484 elsif System_Text
(P
.. P
+ 35) =
485 "pragma Suppress_Exception_Locations;"
488 Opt
.Exception_Locations_Suppressed
:= True;
489 goto Line_Loop_Continue
;
491 -- Task_Dispatching Policy
493 elsif System_Text
(P
.. P
+ 31) =
494 "pragma Task_Dispatching_Policy ("
497 Opt
.Task_Dispatching_Policy
:= System_Text
(P
);
498 Opt
.Task_Dispatching_Policy_Sloc
:= System_Location
;
499 goto Line_Loop_Continue
;
501 -- No other configuration pragmas are permitted
503 elsif System_Text
(P
.. P
+ 6) = "pragma " then
505 -- Special exception, we allow pragma Pure (System) appearing in
506 -- column one. This is an obsolete usage which may show up in old
507 -- tests with an obsolete version of system.ads, so we recognize
508 -- and ignore it to make life easier in handling such tests.
510 if System_Text
(P
.. P
+ 20) = "pragma Pure (System);" then
512 goto Line_Loop_Continue
;
516 Write_Line
("unrecognized line in system.ads: ");
518 while System_Text
(P
) /= ')'
519 and then System_Text
(P
) /= ASCII
.LF
521 Write_Char
(System_Text
(P
));
529 -- See if we have a Run_Time_Name
531 elsif System_Text
(P
.. P
+ 38) =
532 " Run_Time_Name : constant String := """
537 while System_Text
(P
) in 'A' .. 'Z'
539 System_Text
(P
) in 'a' .. 'z'
541 System_Text
(P
) in '0' .. '9'
543 System_Text
(P
) = ' '
545 System_Text
(P
) = '_'
547 Add_Char_To_Name_Buffer
(System_Text
(P
));
551 if System_Text
(P
) /= '"'
552 or else System_Text
(P
+ 1) /= ';'
553 or else (System_Text
(P
+ 2) /= ASCII
.LF
555 System_Text
(P
+ 2) /= ASCII
.CR
)
559 ("incorrectly formatted Run_Time_Name in system.ads");
564 Run_Time_Name_On_Target
:= Name_Enter
;
567 goto Line_Loop_Continue
;
569 -- See if we have an Executable_Extension
571 elsif System_Text
(P
.. P
+ 45) =
572 " Executable_Extension : constant String := """
577 while System_Text
(P
) /= '"'
578 and then System_Text
(P
) /= ASCII
.LF
580 Add_Char_To_Name_Buffer
(System_Text
(P
));
584 if System_Text
(P
) /= '"' or else System_Text
(P
+ 1) /= ';' then
587 ("incorrectly formatted Executable_Extension in system.ads");
592 Executable_Extension_On_Target
:= Name_Enter
;
595 goto Line_Loop_Continue
;
597 -- Next see if we have a configuration parameter
600 Config_Param_Loop
: for K
in Targparm_Tags
loop
601 if System_Text
(P
+ 3 .. P
+ 2 + Targparm_Str
(K
)'Length) =
604 P
:= P
+ 3 + Targparm_Str
(K
)'Length;
606 if Targparm_Flags
(K
) then
609 ("fatal error: system.ads is incorrectly formatted");
610 Write_Str
("duplicate line for parameter: ");
612 for J
in Targparm_Str
(K
)'Range loop
613 Write_Char
(Targparm_Str
(K
).all (J
));
621 Targparm_Flags
(K
) := True;
624 while System_Text
(P
) /= ':'
625 or else System_Text
(P
+ 1) /= '='
632 while System_Text
(P
) = ' ' loop
636 Result
:= (System_Text
(P
) = 'T');
639 when AAM
=> AAMP_On_Target
:= Result
;
640 when ACR
=> Always_Compatible_Rep_On_Target
:= Result
;
641 when ASD
=> Atomic_Sync_Default_On_Target
:= Result
;
642 when BDC
=> Backend_Divide_Checks_On_Target
:= Result
;
643 when BOC
=> Backend_Overflow_Checks_On_Target
:= Result
;
644 when CLA
=> Command_Line_Args_On_Target
:= Result
;
647 VM_Target
:= CLI_Target
;
648 Tagged_Type_Expansion
:= False;
650 -- This is wrong, this processing should be done in
651 -- Gnat1drv.Adjust_Global_Switches. It is not the
652 -- right level for targparm to know about tagged
655 when CRT
=> Configurable_Run_Time_On_Target
:= Result
;
656 when D32
=> Duration_32_Bits_On_Target
:= Result
;
657 when DEN
=> Denorm_On_Target
:= Result
;
658 when EXS
=> Exit_Status_Supported_On_Target
:= Result
;
659 when FEL
=> Frontend_Layout_On_Target
:= Result
;
660 when FFO
=> Fractional_Fixed_Ops_On_Target
:= Result
;
664 VM_Target
:= JVM_Target
;
665 Tagged_Type_Expansion
:= False;
667 -- This is wrong, this processing should be done in
668 -- Gnat1drv.Adjust_Global_Switches. It is not the
669 -- right level for targparm to know about tagged
672 when MOV
=> Machine_Overflows_On_Target
:= Result
;
673 when MRN
=> Machine_Rounds_On_Target
:= Result
;
674 when PAS
=> Preallocated_Stacks_On_Target
:= Result
;
675 when SAG
=> Support_Aggregates_On_Target
:= Result
;
676 when SAP
=> Support_Atomic_Primitives_On_Target
:= Result
;
677 when SCA
=> Support_Composite_Assign_On_Target
:= Result
;
678 when SCC
=> Support_Composite_Compare_On_Target
:= Result
;
679 when SCD
=> Stack_Check_Default_On_Target
:= Result
;
680 when SCL
=> Stack_Check_Limits_On_Target
:= Result
;
681 when SCP
=> Stack_Check_Probes_On_Target
:= Result
;
682 when SLS
=> Support_Long_Shifts_On_Target
:= Result
;
683 when SSL
=> Suppress_Standard_Library_On_Target
:= Result
;
684 when SNZ
=> Signed_Zeros_On_Target
:= Result
;
685 when UAM
=> Use_Ada_Main_Program_Name_On_Target
:= Result
;
686 when ZCD
=> ZCX_By_Default_On_Target
:= Result
;
688 goto Line_Loop_Continue
;
691 -- Here we are seeing a parameter we do not understand. We
692 -- simply ignore this (will happen when an old compiler is
693 -- used to compile a newer version of GNAT which does not
694 -- support the parameter).
696 end loop Config_Param_Loop
;
699 -- Here after processing one line of System spec
701 <<Line_Loop_Continue
>>
703 while System_Text
(P
) /= CR
and then System_Text
(P
) /= LF
loop
705 exit when P
>= Source_Last
;
708 while System_Text
(P
) = CR
or else System_Text
(P
) = LF
loop
710 exit when P
>= Source_Last
;
713 if P
>= Source_Last
then
715 Write_Line
("fatal error, system.ads not formatted correctly");
716 Write_Line
("unexpected end of file");
718 raise Unrecoverable_Error
;
723 raise Unrecoverable_Error
;
725 end Get_Target_Parameters
;
727 ------------------------------
728 -- Set_Profile_Restrictions --
729 ------------------------------
731 procedure Set_Profile_Restrictions
(P
: Profile_Name
) is
732 R
: Restriction_Flags
renames Profile_Info
(P
).Set
;
733 V
: Restriction_Values
renames Profile_Info
(P
).Value
;
735 for J
in R
'Range loop
737 Restrictions_On_Target
.Set
(J
) := True;
739 if J
in All_Parameter_Restrictions
then
740 Restrictions_On_Target
.Value
(J
) := V
(J
);
744 end Set_Profile_Restrictions
;