1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2015, 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
47 CRT
, -- Configurable_Run_Times
48 D32
, -- Duration_32_Bits
50 EXS
, -- Exit_Status_Supported
51 FEL
, -- Frontend_Layout
52 FEX
, -- Frontend_Exceptions
53 FFO
, -- Fractional_Fixed_Ops
54 MOV
, -- Machine_Overflows
55 MRN
, -- Machine_Rounds
56 PAS
, -- Preallocated_Stacks
57 SAG
, -- Support_Aggregates
58 SAP
, -- Support_Atomic_Primitives
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
68 ZCX
); -- ZCX_By_Default
70 Targparm_Flags
: array (Targparm_Tags
) of Boolean := (others => False);
71 -- Flag is set True if corresponding parameter is scanned
73 -- The following list of string constants gives the parameter names
75 AAM_Str
: aliased constant Source_Buffer
:= "AAMP";
76 ACR_Str
: aliased constant Source_Buffer
:= "Always_Compatible_Rep";
77 ASD_Str
: aliased constant Source_Buffer
:= "Atomic_Sync_Default";
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 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 FEX_Str
: aliased constant Source_Buffer
:= "Frontend_Exceptions";
87 FFO_Str
: aliased constant Source_Buffer
:= "Fractional_Fixed_Ops";
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 SAG_Str
: aliased constant Source_Buffer
:= "Support_Aggregates";
92 SAP_Str
: aliased constant Source_Buffer
:= "Support_Atomic_Primitives";
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 SCL_Str
: aliased constant Source_Buffer
:= "Stack_Check_Limits";
97 SCP_Str
: aliased constant Source_Buffer
:= "Stack_Check_Probes";
98 SLS_Str
: aliased constant Source_Buffer
:= "Support_Long_Shifts";
99 SNZ_Str
: aliased constant Source_Buffer
:= "Signed_Zeros";
100 SSL_Str
: aliased constant Source_Buffer
:= "Suppress_Standard_Library";
101 UAM_Str
: aliased constant Source_Buffer
:= "Use_Ada_Main_Program_Name";
102 ZCX_Str
: aliased constant Source_Buffer
:= "ZCX_By_Default";
104 -- The following defines a set of pointers to the above strings,
105 -- indexed by the tag values.
107 type Buffer_Ptr
is access constant Source_Buffer
;
108 Targparm_Str
: constant array (Targparm_Tags
) of Buffer_Ptr
:=
138 -----------------------
139 -- Local Subprograms --
140 -----------------------
142 procedure Set_Profile_Restrictions
(P
: Profile_Name
);
143 -- Set Restrictions_On_Target for the given profile
145 ---------------------------
146 -- Get_Target_Parameters --
147 ---------------------------
149 -- Version which reads in system.ads
151 procedure Get_Target_Parameters
152 (Make_Id
: Make_Id_Type
:= null;
153 Make_SC
: Make_SC_Type
:= null;
154 Set_NOD
: Set_NOD_Type
:= null;
155 Set_NSA
: Set_NSA_Type
:= null;
156 Set_NUA
: Set_NUA_Type
:= null;
157 Set_NUP
: Set_NUP_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
,
188 end Get_Target_Parameters
;
190 -- Version where caller supplies system.ads text
192 procedure Get_Target_Parameters
193 (System_Text
: Source_Buffer_Ptr
;
194 Source_First
: Source_Ptr
;
195 Source_Last
: Source_Ptr
;
196 Make_Id
: Make_Id_Type
:= null;
197 Make_SC
: Make_SC_Type
:= null;
198 Set_NOD
: Set_NOD_Type
:= null;
199 Set_NSA
: Set_NSA_Type
:= null;
200 Set_NUA
: Set_NUA_Type
:= null;
201 Set_NUP
: Set_NUP_Type
:= null)
204 -- Scans source buffer containing source of system.ads
206 Fatal
: Boolean := False;
207 -- Set True if a fatal error is detected
210 -- Records boolean from system line
213 -- Status result from Set_NUP/NSA/NUA call
215 PR_Start
: Source_Ptr
;
216 -- Pointer to ( following pragma Restrictions
218 procedure Collect_Name
;
219 -- Scan a name starting at System_Text (P), and put Name in Name_Buffer,
220 -- with Name_Len being length, folded to lower case. On return, P points
221 -- just past the last character (which should be a right paren).
227 procedure Collect_Name
is
231 if System_Text
(P
) in 'a' .. 'z'
233 System_Text
(P
) = '_'
235 System_Text
(P
) in '0' .. '9'
237 Name_Buffer
(Name_Len
+ 1) := System_Text
(P
);
239 elsif System_Text
(P
) in 'A' .. 'Z' then
240 Name_Buffer
(Name_Len
+ 1) :=
241 Character'Val (Character'Pos (System_Text
(P
)) + 32);
248 Name_Len
:= Name_Len
+ 1;
252 -- Start of processing for Get_Target_Parameters
255 if Parameters_Obtained
then
258 Parameters_Obtained
:= True;
261 Opt
.Address_Is_Private
:= False;
263 -- Loop through source lines
265 -- Note: in the case or pragmas, we are only interested in pragmas that
266 -- appear as configuration pragmas. These are left justified, so they
267 -- do not have three spaces at the start. Pragmas appearing within the
268 -- package (like Pure and No_Elaboration_Code_All) will have the three
269 -- spaces at the start and so will be ignored.
271 -- For a special exception, see processing for pragma Pure below
274 Line_Loop
: while System_Text
(P
.. P
+ 10) /= "end System;" loop
276 -- Skip comments quickly
278 if System_Text
(P
) = '-' then
279 goto Line_Loop_Continue
;
281 -- Test for type Address is private
283 elsif System_Text
(P
.. P
+ 26) = " type Address is private;" then
284 Opt
.Address_Is_Private
:= True;
286 goto Line_Loop_Continue
;
288 -- Test for pragma Profile (Ravenscar);
290 elsif System_Text
(P
.. P
+ 26) =
291 "pragma Profile (Ravenscar);"
293 Set_Profile_Restrictions
(Ravenscar
);
294 Opt
.Task_Dispatching_Policy
:= 'F';
295 Opt
.Locking_Policy
:= 'C';
297 goto Line_Loop_Continue
;
299 -- Test for pragma Profile (GNAT_Extended_Ravenscar);
301 elsif System_Text
(P
.. P
+ 40) =
302 "pragma Profile (GNAT_Extended_Ravenscar);"
304 Set_Profile_Restrictions
(GNAT_Extended_Ravenscar
);
305 Opt
.Task_Dispatching_Policy
:= 'F';
306 Opt
.Locking_Policy
:= 'C';
308 goto Line_Loop_Continue
;
310 -- Test for pragma Profile (Restricted);
312 elsif System_Text
(P
.. P
+ 27) =
313 "pragma Profile (Restricted);"
315 Set_Profile_Restrictions
(Restricted
);
317 goto Line_Loop_Continue
;
319 -- Test for pragma Restrictions
321 elsif System_Text
(P
.. P
+ 20) = "pragma Restrictions (" then
325 -- Boolean restrictions
327 Rloop
: for K
in All_Boolean_Restrictions
loop
329 Rname
: constant String := Restriction_Id
'Image (K
);
332 for J
in Rname
'Range loop
333 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
340 if System_Text
(P
+ Rname
'Length) = ')' then
341 Restrictions_On_Target
.Set
(K
) := True;
342 goto Line_Loop_Continue
;
350 -- Restrictions taking integer parameter
352 Ploop
: for K
in Integer_Parameter_Restrictions
loop
354 Rname
: constant String :=
355 All_Parameter_Restrictions
'Image (K
);
361 for J
in Rname
'Range loop
362 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
369 if System_Text
(P
+ Rname
'Length .. P
+ Rname
'Length + 3) =
372 P
:= P
+ Rname
'Length + 4;
376 if System_Text
(P
) in '0' .. '9' then
378 pragma Unsuppress
(Overflow_Check
);
381 -- Accumulate next digit
384 Character'Pos (System_Text
(P
)) -
388 -- On overflow, we just ignore the pragma since
389 -- that is the standard handling in this case.
391 when Constraint_Error
=>
392 goto Line_Loop_Continue
;
395 elsif System_Text
(P
) = '_' then
398 elsif System_Text
(P
) = ')' then
399 Restrictions_On_Target
.Value
(K
) := V
;
400 Restrictions_On_Target
.Set
(K
) := True;
401 goto Line_Loop_Continue
;
419 -- No_Dependence case
421 if System_Text
(P
.. P
+ 16) = "No_Dependence => " then
424 -- Skip this processing (and simply ignore No_Dependence lines)
425 -- if caller did not supply the three subprograms we need to
426 -- process these lines.
428 if Make_Id
= null then
429 goto Line_Loop_Continue
;
432 -- We have scanned out "pragma Restrictions (No_Dependence =>"
442 -- Loop through components of name, building up Unit
446 while System_Text
(P
) /= '.'
448 System_Text
(P
) /= ')'
453 Id
:= Make_Id
(System_Text
(Start
.. P
- 1));
455 -- If first name, just capture the identifier
460 Unit
:= Make_SC
(Unit
, Id
);
463 exit when System_Text
(P
) = ')';
468 goto Line_Loop_Continue
;
471 -- No_Specification_Of_Aspect case
473 elsif System_Text
(P
.. P
+ 29) = "No_Specification_Of_Aspect => "
477 -- Skip this processing (and simply ignore the pragma), if
478 -- caller did not supply the subprogram we need to process
481 if Set_NSA
= null then
482 goto Line_Loop_Continue
;
486 -- "pragma Restrictions (No_Specification_Of_Aspect =>"
490 if System_Text
(P
) /= ')' then
491 goto Bad_Restrictions_Pragma
;
494 Set_NSA
(Name_Find
, OK
);
497 goto Line_Loop_Continue
;
499 goto Bad_Restrictions_Pragma
;
503 -- No_Use_Of_Attribute case
505 elsif System_Text
(P
.. P
+ 22) = "No_Use_Of_Attribute => " then
508 -- Skip this processing (and simply ignore No_Use_Of_Attribute
509 -- lines) if caller did not supply the subprogram we need to
510 -- process such lines.
512 if Set_NUA
= null then
513 goto Line_Loop_Continue
;
517 -- "pragma Restrictions (No_Use_Of_Attribute =>"
521 if System_Text
(P
) /= ')' then
522 goto Bad_Restrictions_Pragma
;
525 Set_NUA
(Name_Find
, OK
);
528 goto Line_Loop_Continue
;
530 goto Bad_Restrictions_Pragma
;
534 -- No_Use_Of_Pragma case
536 elsif System_Text
(P
.. P
+ 19) = "No_Use_Of_Pragma => " then
539 -- Skip this processing (and simply ignore No_Use_Of_Pragma
540 -- lines) if caller did not supply the subprogram we need to
541 -- process such lines.
543 if Set_NUP
= null then
544 goto Line_Loop_Continue
;
548 -- "pragma Restrictions (No_Use_Of_Pragma =>"
552 if System_Text
(P
) /= ')' then
553 goto Bad_Restrictions_Pragma
;
556 Set_NUP
(Name_Find
, OK
);
559 goto Line_Loop_Continue
;
561 goto Bad_Restrictions_Pragma
;
566 -- Here if unrecognizable restrictions pragma form
568 <<Bad_Restrictions_Pragma
>>
572 ("fatal error: system.ads is incorrectly formatted");
573 Write_Str
("unrecognized or incorrect restrictions pragma: ");
577 exit when System_Text
(P
) = ASCII
.LF
;
578 Write_Char
(System_Text
(P
));
579 exit when System_Text
(P
) = ')';
587 -- Test for pragma Detect_Blocking;
589 elsif System_Text
(P
.. P
+ 22) = "pragma Detect_Blocking;" then
591 Opt
.Detect_Blocking
:= True;
592 goto Line_Loop_Continue
;
596 elsif System_Text
(P
.. P
+ 20) = "pragma Discard_Names;" then
598 Opt
.Global_Discard_Names
:= True;
599 goto Line_Loop_Continue
;
603 elsif System_Text
(P
.. P
+ 22) = "pragma Locking_Policy (" then
605 Opt
.Locking_Policy
:= System_Text
(P
);
606 Opt
.Locking_Policy_Sloc
:= System_Location
;
607 goto Line_Loop_Continue
;
611 elsif System_Text
(P
.. P
+ 24) = "pragma Normalize_Scalars;" then
613 Opt
.Normalize_Scalars
:= True;
614 Opt
.Init_Or_Norm_Scalars
:= True;
615 goto Line_Loop_Continue
;
617 -- Partition_Elaboration_Policy
619 elsif System_Text
(P
.. P
+ 36) =
620 "pragma Partition_Elaboration_Policy ("
623 Opt
.Partition_Elaboration_Policy
:= System_Text
(P
);
624 Opt
.Partition_Elaboration_Policy_Sloc
:= System_Location
;
625 goto Line_Loop_Continue
;
629 elsif System_Text
(P
.. P
+ 19) = "pragma Polling (On);" then
631 Opt
.Polling_Required
:= True;
632 goto Line_Loop_Continue
;
636 elsif System_Text
(P
.. P
+ 22) = "pragma Queuing_Policy (" then
638 Opt
.Queuing_Policy
:= System_Text
(P
);
639 Opt
.Queuing_Policy_Sloc
:= System_Location
;
640 goto Line_Loop_Continue
;
642 -- Suppress_Exception_Locations
644 elsif System_Text
(P
.. P
+ 35) =
645 "pragma Suppress_Exception_Locations;"
648 Opt
.Exception_Locations_Suppressed
:= True;
649 goto Line_Loop_Continue
;
651 -- Task_Dispatching Policy
653 elsif System_Text
(P
.. P
+ 31) =
654 "pragma Task_Dispatching_Policy ("
657 Opt
.Task_Dispatching_Policy
:= System_Text
(P
);
658 Opt
.Task_Dispatching_Policy_Sloc
:= System_Location
;
659 goto Line_Loop_Continue
;
661 -- No other configuration pragmas are permitted
663 elsif System_Text
(P
.. P
+ 6) = "pragma " then
665 -- Special exception, we allow pragma Pure (System) appearing in
666 -- column one. This is an obsolete usage which may show up in old
667 -- tests with an obsolete version of system.ads, so we recognize
668 -- and ignore it to make life easier in handling such tests.
670 if System_Text
(P
.. P
+ 20) = "pragma Pure (System);" then
672 goto Line_Loop_Continue
;
676 Write_Line
("unrecognized line in system.ads: ");
678 while System_Text
(P
) /= ')'
679 and then System_Text
(P
) /= ASCII
.LF
681 Write_Char
(System_Text
(P
));
689 -- See if we have a Run_Time_Name
691 elsif System_Text
(P
.. P
+ 38) =
692 " Run_Time_Name : constant String := """
697 while System_Text
(P
) in 'A' .. 'Z'
699 System_Text
(P
) in 'a' .. 'z'
701 System_Text
(P
) in '0' .. '9'
703 System_Text
(P
) = ' '
705 System_Text
(P
) = '_'
707 Add_Char_To_Name_Buffer
(System_Text
(P
));
711 if System_Text
(P
) /= '"'
712 or else System_Text
(P
+ 1) /= ';'
713 or else (System_Text
(P
+ 2) /= ASCII
.LF
715 System_Text
(P
+ 2) /= ASCII
.CR
)
719 ("incorrectly formatted Run_Time_Name in system.ads");
724 Run_Time_Name_On_Target
:= Name_Enter
;
727 goto Line_Loop_Continue
;
729 -- See if we have an Executable_Extension
731 elsif System_Text
(P
.. P
+ 45) =
732 " Executable_Extension : constant String := """
737 while System_Text
(P
) /= '"'
738 and then System_Text
(P
) /= ASCII
.LF
740 Add_Char_To_Name_Buffer
(System_Text
(P
));
744 if System_Text
(P
) /= '"' or else System_Text
(P
+ 1) /= ';' then
747 ("incorrectly formatted Executable_Extension in system.ads");
752 Executable_Extension_On_Target
:= Name_Enter
;
755 goto Line_Loop_Continue
;
757 -- Next see if we have a configuration parameter
760 Config_Param_Loop
: for K
in Targparm_Tags
loop
761 if System_Text
(P
+ 3 .. P
+ 2 + Targparm_Str
(K
)'Length) =
764 P
:= P
+ 3 + Targparm_Str
(K
)'Length;
766 if Targparm_Flags
(K
) then
769 ("fatal error: system.ads is incorrectly formatted");
770 Write_Str
("duplicate line for parameter: ");
772 for J
in Targparm_Str
(K
)'Range loop
773 Write_Char
(Targparm_Str
(K
).all (J
));
781 Targparm_Flags
(K
) := True;
784 while System_Text
(P
) /= ':'
785 or else System_Text
(P
+ 1) /= '='
792 while System_Text
(P
) = ' ' loop
796 Result
:= (System_Text
(P
) = 'T');
799 when AAM
=> AAMP_On_Target
:= Result
;
800 when ACR
=> Always_Compatible_Rep_On_Target
:= Result
;
801 when ASD
=> Atomic_Sync_Default_On_Target
:= Result
;
802 when BDC
=> Backend_Divide_Checks_On_Target
:= Result
;
803 when BOC
=> Backend_Overflow_Checks_On_Target
:= Result
;
804 when CLA
=> Command_Line_Args_On_Target
:= Result
;
805 when CRT
=> Configurable_Run_Time_On_Target
:= Result
;
806 when D32
=> Duration_32_Bits_On_Target
:= Result
;
807 when DEN
=> Denorm_On_Target
:= Result
;
808 when EXS
=> Exit_Status_Supported_On_Target
:= Result
;
809 when FEL
=> Frontend_Layout_On_Target
:= Result
;
810 when FEX
=> Frontend_Exceptions_On_Target
:= Result
;
811 when FFO
=> Fractional_Fixed_Ops_On_Target
:= Result
;
812 when MOV
=> Machine_Overflows_On_Target
:= Result
;
813 when MRN
=> Machine_Rounds_On_Target
:= Result
;
814 when PAS
=> Preallocated_Stacks_On_Target
:= Result
;
815 when SAG
=> Support_Aggregates_On_Target
:= Result
;
816 when SAP
=> Support_Atomic_Primitives_On_Target
:= Result
;
817 when SCA
=> Support_Composite_Assign_On_Target
:= Result
;
818 when SCC
=> Support_Composite_Compare_On_Target
:= Result
;
819 when SCD
=> Stack_Check_Default_On_Target
:= Result
;
820 when SCL
=> Stack_Check_Limits_On_Target
:= Result
;
821 when SCP
=> Stack_Check_Probes_On_Target
:= Result
;
822 when SLS
=> Support_Long_Shifts_On_Target
:= Result
;
823 when SSL
=> Suppress_Standard_Library_On_Target
:= Result
;
824 when SNZ
=> Signed_Zeros_On_Target
:= Result
;
825 when UAM
=> Use_Ada_Main_Program_Name_On_Target
:= Result
;
826 when ZCX
=> ZCX_By_Default_On_Target
:= Result
;
828 goto Line_Loop_Continue
;
831 -- Here we are seeing a parameter we do not understand. We
832 -- simply ignore this (will happen when an old compiler is
833 -- used to compile a newer version of GNAT which does not
834 -- support the parameter).
836 end loop Config_Param_Loop
;
839 -- Here after processing one line of System spec
841 <<Line_Loop_Continue
>>
843 while System_Text
(P
) /= CR
and then System_Text
(P
) /= LF
loop
845 exit when P
>= Source_Last
;
848 while System_Text
(P
) = CR
or else System_Text
(P
) = LF
loop
850 exit when P
>= Source_Last
;
853 if P
>= Source_Last
then
855 Write_Line
("fatal error, system.ads not formatted correctly");
856 Write_Line
("unexpected end of file");
858 raise Unrecoverable_Error
;
863 raise Unrecoverable_Error
;
865 end Get_Target_Parameters
;
867 ------------------------------
868 -- Set_Profile_Restrictions --
869 ------------------------------
871 procedure Set_Profile_Restrictions
(P
: Profile_Name
) is
872 R
: Restriction_Flags
renames Profile_Info
(P
).Set
;
873 V
: Restriction_Values
renames Profile_Info
(P
).Value
;
875 for J
in R
'Range loop
877 Restrictions_On_Target
.Set
(J
) := True;
879 if J
in All_Parameter_Restrictions
then
880 Restrictions_On_Target
.Value
(J
) := V
(J
);
884 end Set_Profile_Restrictions
;