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
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_NOD
: Set_NOD_Type
:= null;
158 Set_NSA
: Set_NSA_Type
:= null;
159 Set_NUA
: Set_NUA_Type
:= null;
160 Set_NUP
: Set_NUP_Type
:= null)
162 Text
: Source_Buffer_Ptr
;
166 if Parameters_Obtained
then
170 Name_Buffer
(1 .. 10) := "system.ads";
173 Read_Source_File
(Name_Find
, Lo
=> 0, Hi
=> Hi
, Src
=> Text
);
176 Write_Line
("fatal error, run-time library not installed correctly");
177 Write_Line
("cannot locate file system.ads");
178 raise Unrecoverable_Error
;
181 Get_Target_Parameters
182 (System_Text
=> Text
,
191 end Get_Target_Parameters
;
193 -- Version where caller supplies system.ads text
195 procedure Get_Target_Parameters
196 (System_Text
: Source_Buffer_Ptr
;
197 Source_First
: Source_Ptr
;
198 Source_Last
: Source_Ptr
;
199 Make_Id
: Make_Id_Type
:= null;
200 Make_SC
: Make_SC_Type
:= null;
201 Set_NOD
: Set_NOD_Type
:= null;
202 Set_NSA
: Set_NSA_Type
:= null;
203 Set_NUA
: Set_NUA_Type
:= null;
204 Set_NUP
: Set_NUP_Type
:= null)
207 -- Scans source buffer containing source of system.ads
209 Fatal
: Boolean := False;
210 -- Set True if a fatal error is detected
213 -- Records boolean from system line
216 -- Status result from Set_NUP/NSA/NUA call
218 PR_Start
: Source_Ptr
;
219 -- Pointer to ( following pragma Restrictions
221 procedure Collect_Name
;
222 -- Scan a name starting at System_Text (P), and put Name in Name_Buffer,
223 -- with Name_Len being length, folded to lower case. On return, P points
224 -- just past the last character (which should be a right paren).
230 procedure Collect_Name
is
234 if System_Text
(P
) in 'a' .. 'z'
236 System_Text
(P
) = '_'
238 System_Text
(P
) in '0' .. '9'
240 Name_Buffer
(Name_Len
+ 1) := System_Text
(P
);
242 elsif System_Text
(P
) in 'A' .. 'Z' then
243 Name_Buffer
(Name_Len
+ 1) :=
244 Character'Val (Character'Pos (System_Text
(P
)) + 32);
251 Name_Len
:= Name_Len
+ 1;
255 -- Start of processing for Get_Target_Parameters
258 if Parameters_Obtained
then
261 Parameters_Obtained
:= True;
264 Opt
.Address_Is_Private
:= False;
266 -- Loop through source lines
268 -- Note: in the case or pragmas, we are only interested in pragmas that
269 -- appear as configuration pragmas. These are left justified, so they
270 -- do not have three spaces at the start. Pragmas appearing within the
271 -- package (like Pure and No_Elaboration_Code_All) will have the three
272 -- spaces at the start and so will be ignored.
274 -- For a special exception, see processing for pragma Pure below
277 Line_Loop
: while System_Text
(P
.. P
+ 10) /= "end System;" loop
279 -- Skip comments quickly
281 if System_Text
(P
) = '-' then
282 goto Line_Loop_Continue
;
284 -- Test for type Address is private
286 elsif System_Text
(P
.. P
+ 26) = " type Address is private;" then
287 Opt
.Address_Is_Private
:= True;
289 goto Line_Loop_Continue
;
291 -- Test for pragma Profile (Ravenscar);
293 elsif System_Text
(P
.. P
+ 26) =
294 "pragma Profile (Ravenscar);"
296 Set_Profile_Restrictions
(Ravenscar
);
297 Opt
.Task_Dispatching_Policy
:= 'F';
298 Opt
.Locking_Policy
:= 'C';
300 goto Line_Loop_Continue
;
302 -- Test for pragma Profile (Restricted);
304 elsif System_Text
(P
.. P
+ 27) =
305 "pragma Profile (Restricted);"
307 Set_Profile_Restrictions
(Restricted
);
309 goto Line_Loop_Continue
;
311 -- Test for pragma Restrictions
313 elsif System_Text
(P
.. P
+ 20) = "pragma Restrictions (" then
317 -- Boolean restrictions
319 Rloop
: for K
in All_Boolean_Restrictions
loop
321 Rname
: constant String := Restriction_Id
'Image (K
);
324 for J
in Rname
'Range loop
325 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
332 if System_Text
(P
+ Rname
'Length) = ')' then
333 Restrictions_On_Target
.Set
(K
) := True;
334 goto Line_Loop_Continue
;
342 -- Restrictions taking integer parameter
344 Ploop
: for K
in Integer_Parameter_Restrictions
loop
346 Rname
: constant String :=
347 All_Parameter_Restrictions
'Image (K
);
353 for J
in Rname
'Range loop
354 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
361 if System_Text
(P
+ Rname
'Length .. P
+ Rname
'Length + 3) =
364 P
:= P
+ Rname
'Length + 4;
368 if System_Text
(P
) in '0' .. '9' then
370 pragma Unsuppress
(Overflow_Check
);
373 -- Accumulate next digit
376 Character'Pos (System_Text
(P
)) -
380 -- On overflow, we just ignore the pragma since
381 -- that is the standard handling in this case.
383 when Constraint_Error
=>
384 goto Line_Loop_Continue
;
387 elsif System_Text
(P
) = '_' then
390 elsif System_Text
(P
) = ')' then
391 Restrictions_On_Target
.Value
(K
) := V
;
392 Restrictions_On_Target
.Set
(K
) := True;
393 goto Line_Loop_Continue
;
411 -- No_Dependence case
413 if System_Text
(P
.. P
+ 16) = "No_Dependence => " then
416 -- Skip this processing (and simply ignore No_Dependence lines)
417 -- if caller did not supply the three subprograms we need to
418 -- process these lines.
420 if Make_Id
= null then
421 goto Line_Loop_Continue
;
424 -- We have scanned out "pragma Restrictions (No_Dependence =>"
434 -- Loop through components of name, building up Unit
438 while System_Text
(P
) /= '.'
440 System_Text
(P
) /= ')'
445 Id
:= Make_Id
(System_Text
(Start
.. P
- 1));
447 -- If first name, just capture the identifier
452 Unit
:= Make_SC
(Unit
, Id
);
455 exit when System_Text
(P
) = ')';
460 goto Line_Loop_Continue
;
463 -- No_Specification_Of_Aspect case
465 elsif System_Text
(P
.. P
+ 29) = "No_Specification_Of_Aspect => "
469 -- Skip this processing (and simply ignore the pragma), if
470 -- caller did not supply the subprogram we need to process
473 if Set_NSA
= null then
474 goto Line_Loop_Continue
;
478 -- "pragma Restrictions (No_Specification_Of_Aspect =>"
482 if System_Text
(P
) /= ')' then
483 goto Bad_Restrictions_Pragma
;
486 Set_NSA
(Name_Find
, OK
);
489 goto Line_Loop_Continue
;
491 goto Bad_Restrictions_Pragma
;
495 -- No_Use_Of_Attribute case
497 elsif System_Text
(P
.. P
+ 22) = "No_Use_Of_Attribute => " then
500 -- Skip this processing (and simply ignore No_Use_Of_Attribute
501 -- lines) if caller did not supply the subprogram we need to
502 -- process such lines.
504 if Set_NUA
= null then
505 goto Line_Loop_Continue
;
509 -- "pragma Restrictions (No_Use_Of_Attribute =>"
513 if System_Text
(P
) /= ')' then
514 goto Bad_Restrictions_Pragma
;
517 Set_NUA
(Name_Find
, OK
);
520 goto Line_Loop_Continue
;
522 goto Bad_Restrictions_Pragma
;
526 -- No_Use_Of_Pragma case
528 elsif System_Text
(P
.. P
+ 19) = "No_Use_Of_Pragma => " then
531 -- Skip this processing (and simply ignore No_Use_Of_Pragma
532 -- lines) if caller did not supply the subprogram we need to
533 -- process such lines.
535 if Set_NUP
= null then
536 goto Line_Loop_Continue
;
540 -- "pragma Restrictions (No_Use_Of_Pragma =>"
544 if System_Text
(P
) /= ')' then
545 goto Bad_Restrictions_Pragma
;
548 Set_NUP
(Name_Find
, OK
);
551 goto Line_Loop_Continue
;
553 goto Bad_Restrictions_Pragma
;
558 -- Here if unrecognizable restrictions pragma form
560 <<Bad_Restrictions_Pragma
>>
564 ("fatal error: system.ads is incorrectly formatted");
565 Write_Str
("unrecognized or incorrect restrictions pragma: ");
569 exit when System_Text
(P
) = ASCII
.LF
;
570 Write_Char
(System_Text
(P
));
571 exit when System_Text
(P
) = ')';
579 -- Test for pragma Detect_Blocking;
581 elsif System_Text
(P
.. P
+ 22) = "pragma Detect_Blocking;" then
583 Opt
.Detect_Blocking
:= True;
584 goto Line_Loop_Continue
;
588 elsif System_Text
(P
.. P
+ 20) = "pragma Discard_Names;" then
590 Opt
.Global_Discard_Names
:= True;
591 goto Line_Loop_Continue
;
595 elsif System_Text
(P
.. P
+ 22) = "pragma Locking_Policy (" then
597 Opt
.Locking_Policy
:= System_Text
(P
);
598 Opt
.Locking_Policy_Sloc
:= System_Location
;
599 goto Line_Loop_Continue
;
603 elsif System_Text
(P
.. P
+ 24) = "pragma Normalize_Scalars;" then
605 Opt
.Normalize_Scalars
:= True;
606 Opt
.Init_Or_Norm_Scalars
:= True;
607 goto Line_Loop_Continue
;
609 -- Partition_Elaboration_Policy
611 elsif System_Text
(P
.. P
+ 36) =
612 "pragma Partition_Elaboration_Policy ("
615 Opt
.Partition_Elaboration_Policy
:= System_Text
(P
);
616 Opt
.Partition_Elaboration_Policy_Sloc
:= System_Location
;
617 goto Line_Loop_Continue
;
621 elsif System_Text
(P
.. P
+ 19) = "pragma Polling (On);" then
623 Opt
.Polling_Required
:= True;
624 goto Line_Loop_Continue
;
628 elsif System_Text
(P
.. P
+ 22) = "pragma Queuing_Policy (" then
630 Opt
.Queuing_Policy
:= System_Text
(P
);
631 Opt
.Queuing_Policy_Sloc
:= System_Location
;
632 goto Line_Loop_Continue
;
634 -- Suppress_Exception_Locations
636 elsif System_Text
(P
.. P
+ 35) =
637 "pragma Suppress_Exception_Locations;"
640 Opt
.Exception_Locations_Suppressed
:= True;
641 goto Line_Loop_Continue
;
643 -- Task_Dispatching Policy
645 elsif System_Text
(P
.. P
+ 31) =
646 "pragma Task_Dispatching_Policy ("
649 Opt
.Task_Dispatching_Policy
:= System_Text
(P
);
650 Opt
.Task_Dispatching_Policy_Sloc
:= System_Location
;
651 goto Line_Loop_Continue
;
653 -- No other configuration pragmas are permitted
655 elsif System_Text
(P
.. P
+ 6) = "pragma " then
657 -- Special exception, we allow pragma Pure (System) appearing in
658 -- column one. This is an obsolete usage which may show up in old
659 -- tests with an obsolete version of system.ads, so we recognize
660 -- and ignore it to make life easier in handling such tests.
662 if System_Text
(P
.. P
+ 20) = "pragma Pure (System);" then
664 goto Line_Loop_Continue
;
668 Write_Line
("unrecognized line in system.ads: ");
670 while System_Text
(P
) /= ')'
671 and then System_Text
(P
) /= ASCII
.LF
673 Write_Char
(System_Text
(P
));
681 -- See if we have a Run_Time_Name
683 elsif System_Text
(P
.. P
+ 38) =
684 " Run_Time_Name : constant String := """
689 while System_Text
(P
) in 'A' .. 'Z'
691 System_Text
(P
) in 'a' .. 'z'
693 System_Text
(P
) in '0' .. '9'
695 System_Text
(P
) = ' '
697 System_Text
(P
) = '_'
699 Add_Char_To_Name_Buffer
(System_Text
(P
));
703 if System_Text
(P
) /= '"'
704 or else System_Text
(P
+ 1) /= ';'
705 or else (System_Text
(P
+ 2) /= ASCII
.LF
707 System_Text
(P
+ 2) /= ASCII
.CR
)
711 ("incorrectly formatted Run_Time_Name in system.ads");
716 Run_Time_Name_On_Target
:= Name_Enter
;
719 goto Line_Loop_Continue
;
721 -- See if we have an Executable_Extension
723 elsif System_Text
(P
.. P
+ 45) =
724 " Executable_Extension : constant String := """
729 while System_Text
(P
) /= '"'
730 and then System_Text
(P
) /= ASCII
.LF
732 Add_Char_To_Name_Buffer
(System_Text
(P
));
736 if System_Text
(P
) /= '"' or else System_Text
(P
+ 1) /= ';' then
739 ("incorrectly formatted Executable_Extension in system.ads");
744 Executable_Extension_On_Target
:= Name_Enter
;
747 goto Line_Loop_Continue
;
749 -- Next see if we have a configuration parameter
752 Config_Param_Loop
: for K
in Targparm_Tags
loop
753 if System_Text
(P
+ 3 .. P
+ 2 + Targparm_Str
(K
)'Length) =
756 P
:= P
+ 3 + Targparm_Str
(K
)'Length;
758 if Targparm_Flags
(K
) then
761 ("fatal error: system.ads is incorrectly formatted");
762 Write_Str
("duplicate line for parameter: ");
764 for J
in Targparm_Str
(K
)'Range loop
765 Write_Char
(Targparm_Str
(K
).all (J
));
773 Targparm_Flags
(K
) := True;
776 while System_Text
(P
) /= ':'
777 or else System_Text
(P
+ 1) /= '='
784 while System_Text
(P
) = ' ' loop
788 Result
:= (System_Text
(P
) = 'T');
791 when AAM
=> AAMP_On_Target
:= Result
;
792 when ACR
=> Always_Compatible_Rep_On_Target
:= Result
;
793 when ASD
=> Atomic_Sync_Default_On_Target
:= Result
;
794 when BDC
=> Backend_Divide_Checks_On_Target
:= Result
;
795 when BOC
=> Backend_Overflow_Checks_On_Target
:= Result
;
796 when CLA
=> Command_Line_Args_On_Target
:= Result
;
799 VM_Target
:= CLI_Target
;
800 Tagged_Type_Expansion
:= False;
802 -- This is wrong, this processing should be done in
803 -- Gnat1drv.Adjust_Global_Switches. It is not the
804 -- right level for targparm to know about tagged
807 when CRT
=> Configurable_Run_Time_On_Target
:= Result
;
808 when D32
=> Duration_32_Bits_On_Target
:= Result
;
809 when DEN
=> Denorm_On_Target
:= Result
;
810 when EXS
=> Exit_Status_Supported_On_Target
:= Result
;
811 when FEL
=> Frontend_Layout_On_Target
:= Result
;
812 when FFO
=> Fractional_Fixed_Ops_On_Target
:= Result
;
816 VM_Target
:= JVM_Target
;
817 Tagged_Type_Expansion
:= False;
819 -- This is wrong, this processing should be done in
820 -- Gnat1drv.Adjust_Global_Switches. It is not the
821 -- right level for targparm to know about tagged
824 when MOV
=> Machine_Overflows_On_Target
:= Result
;
825 when MRN
=> Machine_Rounds_On_Target
:= Result
;
826 when PAS
=> Preallocated_Stacks_On_Target
:= Result
;
827 when SAG
=> Support_Aggregates_On_Target
:= Result
;
828 when SAP
=> Support_Atomic_Primitives_On_Target
:= Result
;
829 when SCA
=> Support_Composite_Assign_On_Target
:= Result
;
830 when SCC
=> Support_Composite_Compare_On_Target
:= Result
;
831 when SCD
=> Stack_Check_Default_On_Target
:= Result
;
832 when SCL
=> Stack_Check_Limits_On_Target
:= Result
;
833 when SCP
=> Stack_Check_Probes_On_Target
:= Result
;
834 when SLS
=> Support_Long_Shifts_On_Target
:= Result
;
835 when SSL
=> Suppress_Standard_Library_On_Target
:= Result
;
836 when SNZ
=> Signed_Zeros_On_Target
:= Result
;
837 when UAM
=> Use_Ada_Main_Program_Name_On_Target
:= Result
;
838 when ZCD
=> ZCX_By_Default_On_Target
:= Result
;
840 goto Line_Loop_Continue
;
843 -- Here we are seeing a parameter we do not understand. We
844 -- simply ignore this (will happen when an old compiler is
845 -- used to compile a newer version of GNAT which does not
846 -- support the parameter).
848 end loop Config_Param_Loop
;
851 -- Here after processing one line of System spec
853 <<Line_Loop_Continue
>>
855 while System_Text
(P
) /= CR
and then System_Text
(P
) /= LF
loop
857 exit when P
>= Source_Last
;
860 while System_Text
(P
) = CR
or else System_Text
(P
) = LF
loop
862 exit when P
>= Source_Last
;
865 if P
>= Source_Last
then
867 Write_Line
("fatal error, system.ads not formatted correctly");
868 Write_Line
("unexpected end of file");
870 raise Unrecoverable_Error
;
875 raise Unrecoverable_Error
;
877 end Get_Target_Parameters
;
879 ------------------------------
880 -- Set_Profile_Restrictions --
881 ------------------------------
883 procedure Set_Profile_Restrictions
(P
: Profile_Name
) is
884 R
: Restriction_Flags
renames Profile_Info
(P
).Set
;
885 V
: Restriction_Values
renames Profile_Info
(P
).Value
;
887 for J
in R
'Range loop
889 Restrictions_On_Target
.Set
(J
) := True;
891 if J
in All_Parameter_Restrictions
then
892 Restrictions_On_Target
.Value
(J
) := V
(J
);
896 end Set_Profile_Restrictions
;