1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2005, 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
;
28 with Namet
; use Namet
;
30 with Osint
; use Osint
;
31 with Output
; use Output
;
33 package body Targparm
is
36 Parameters_Obtained
: Boolean := False;
37 -- Set True after first call to Get_Target_Parameters. Used to avoid
38 -- reading system.ads more than once, since it cannot change.
40 -- The following array defines a tag name for each entry
44 BDC
, -- Backend_Divide_Checks
45 BOC
, -- Backend_Overflow_Checks
46 CLA
, -- Command_Line_Args
47 CRT
, -- Configurable_Run_Times
48 CSV
, -- Compiler_System_Version
49 D32
, -- Duration_32_Bits
51 DSP
, -- Functions_Return_By_DSP
52 EXS
, -- Exit_Status_Supported
53 FEL
, -- Frontend_Layout
54 FFO
, -- Fractional_Fixed_Ops
55 MOV
, -- Machine_Overflows
56 MRN
, -- Machine_Rounds
57 PAS
, -- Preallocated_Stacks
58 S64
, -- Support_64_Bit_Divides
59 SAG
, -- Support_Aggregates
60 SCA
, -- Support_Composite_Assign
61 SCC
, -- Support_Composite_Compare
62 SCD
, -- Stack_Check_Default
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
70 ZCG
); -- GCC_ZCX_Support
72 subtype Targparm_Tags_OK
is Targparm_Tags
range AAM
.. ZCG
;
73 -- Range excluding obsolete entries
75 Targparm_Flags
: array (Targparm_Tags
) of Boolean := (others => False);
76 -- Flag is set True if corresponding parameter is scanned
78 -- The following list of string constants gives the parameter names
80 AAM_Str
: aliased constant Source_Buffer
:= "AAMP";
81 BDC_Str
: aliased constant Source_Buffer
:= "Backend_Divide_Checks";
82 BOC_Str
: aliased constant Source_Buffer
:= "Backend_Overflow_Checks";
83 CLA_Str
: aliased constant Source_Buffer
:= "Command_Line_Args";
84 CRT_Str
: aliased constant Source_Buffer
:= "Configurable_Run_Time";
85 CSV_Str
: aliased constant Source_Buffer
:= "Compiler_System_Version";
86 D32_Str
: aliased constant Source_Buffer
:= "Duration_32_Bits";
87 DEN_Str
: aliased constant Source_Buffer
:= "Denorm";
88 DSP_Str
: aliased constant Source_Buffer
:= "Functions_Return_By_DSP";
89 EXS_Str
: aliased constant Source_Buffer
:= "Exit_Status_Supported";
90 FEL_Str
: aliased constant Source_Buffer
:= "Frontend_Layout";
91 FFO_Str
: aliased constant Source_Buffer
:= "Fractional_Fixed_Ops";
92 MOV_Str
: aliased constant Source_Buffer
:= "Machine_Overflows";
93 MRN_Str
: aliased constant Source_Buffer
:= "Machine_Rounds";
94 PAS_Str
: aliased constant Source_Buffer
:= "Preallocated_Stacks";
95 S64_Str
: aliased constant Source_Buffer
:= "Support_64_Bit_Divides";
96 SAG_Str
: aliased constant Source_Buffer
:= "Support_Aggregates";
97 SCA_Str
: aliased constant Source_Buffer
:= "Support_Composite_Assign";
98 SCC_Str
: aliased constant Source_Buffer
:= "Support_Composite_Compare";
99 SCD_Str
: aliased constant Source_Buffer
:= "Stack_Check_Default";
100 SCP_Str
: aliased constant Source_Buffer
:= "Stack_Check_Probes";
101 SLS_Str
: aliased constant Source_Buffer
:= "Support_Long_Shifts";
102 SNZ_Str
: aliased constant Source_Buffer
:= "Signed_Zeros";
103 SSL_Str
: aliased constant Source_Buffer
:= "Suppress_Standard_Library";
104 UAM_Str
: aliased constant Source_Buffer
:= "Use_Ada_Main_Program_Name";
105 VMS_Str
: aliased constant Source_Buffer
:= "OpenVMS";
106 ZCD_Str
: aliased constant Source_Buffer
:= "ZCX_By_Default";
107 ZCG_Str
: aliased constant Source_Buffer
:= "GCC_ZCX_Support";
109 -- The following defines a set of pointers to the above strings,
110 -- indexed by the tag values.
112 type Buffer_Ptr
is access constant Source_Buffer
;
113 Targparm_Str
: constant array (Targparm_Tags
) of Buffer_Ptr
:=
143 -----------------------
144 -- Local Subprograms --
145 -----------------------
147 procedure Set_Profile_Restrictions
(P
: Profile_Name
);
148 -- Set Restrictions_On_Target for the given profile
150 ------------------------------
151 -- Set_Profile_Restrictions --
152 ------------------------------
154 procedure Set_Profile_Restrictions
(P
: Profile_Name
) is
155 R
: Restriction_Flags
renames Profile_Info
(P
).Set
;
156 V
: Restriction_Values
renames Profile_Info
(P
).Value
;
158 for J
in R
'Range loop
160 Restrictions_On_Target
.Set
(J
) := True;
162 if J
in All_Parameter_Restrictions
then
163 Restrictions_On_Target
.Value
(J
) := V
(J
);
167 end Set_Profile_Restrictions
;
169 ---------------------------
170 -- Get_Target_Parameters --
171 ---------------------------
173 -- Version which reads in system.ads
175 procedure Get_Target_Parameters
is
176 Text
: Source_Buffer_Ptr
;
180 if Parameters_Obtained
then
184 Name_Buffer
(1 .. 10) := "system.ads";
187 Read_Source_File
(Name_Find
, Lo
=> 0, Hi
=> Hi
, Src
=> Text
);
190 Write_Line
("fatal error, run-time library not installed correctly");
191 Write_Line
("cannot locate file system.ads");
192 raise Unrecoverable_Error
;
195 Targparm
.Get_Target_Parameters
196 (System_Text
=> Text
,
199 end Get_Target_Parameters
;
201 -- Version where caller supplies system.ads text
203 procedure Get_Target_Parameters
204 (System_Text
: Source_Buffer_Ptr
;
205 Source_First
: Source_Ptr
;
206 Source_Last
: Source_Ptr
)
209 -- Scans source buffer containing source of system.ads
211 Fatal
: Boolean := False;
212 -- Set True if a fatal error is detected
215 -- Records boolean from system line
218 if Parameters_Obtained
then
221 Parameters_Obtained
:= True;
224 Opt
.Address_Is_Private
:= False;
227 Line_Loop
: while System_Text
(P
.. P
+ 10) /= "end System;" loop
229 -- Skip comments quickly
231 if System_Text
(P
) = '-' then
232 goto Line_Loop_Continue
;
234 -- Test for type Address is private
236 elsif System_Text
(P
.. P
+ 26) = " type Address is private;" then
237 Opt
.Address_Is_Private
:= True;
239 goto Line_Loop_Continue
;
241 -- Test for pragma Profile (Ravenscar);
243 elsif System_Text
(P
.. P
+ 26) =
244 "pragma Profile (Ravenscar);"
246 Set_Profile_Restrictions
(Ravenscar
);
247 Opt
.Task_Dispatching_Policy
:= 'F';
248 Opt
.Locking_Policy
:= 'C';
250 goto Line_Loop_Continue
;
252 -- Test for pragma Profile (Restricted);
254 elsif System_Text
(P
.. P
+ 27) =
255 "pragma Profile (Restricted);"
257 Set_Profile_Restrictions
(Restricted
);
259 goto Line_Loop_Continue
;
261 -- Test for pragma Restrictions
263 elsif System_Text
(P
.. P
+ 20) = "pragma Restrictions (" then
266 Rloop
: for K
in All_Boolean_Restrictions
loop
268 Rname
: constant String := Restriction_Id
'Image (K
);
271 for J
in Rname
'Range loop
272 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
279 if System_Text
(P
+ Rname
'Length) = ')' then
280 Restrictions_On_Target
.Set
(K
) := True;
281 goto Line_Loop_Continue
;
289 Ploop
: for K
in All_Parameter_Restrictions
loop
291 Rname
: constant String :=
292 All_Parameter_Restrictions
'Image (K
);
298 for J
in Rname
'Range loop
299 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
306 if System_Text
(P
+ Rname
'Length .. P
+ Rname
'Length + 3) =
309 P
:= P
+ Rname
'Length + 4;
313 if System_Text
(P
) in '0' .. '9' then
315 pragma Unsuppress
(Overflow_Check
);
318 -- Accumulate next digit
321 Character'Pos (System_Text
(P
)) -
325 -- On overflow, we just ignore the pragma since
326 -- that is the standard handling in this case.
328 when Constraint_Error
=>
329 goto Line_Loop_Continue
;
332 elsif System_Text
(P
) = '_' then
335 elsif System_Text
(P
) = ')' then
336 Restrictions_On_Target
.Value
(K
) := V
;
337 Restrictions_On_Target
.Set
(K
) := True;
338 goto Line_Loop_Continue
;
358 ("fatal error: system.ads is incorrectly formatted");
359 Write_Str
("unrecognized or incorrect restrictions pragma: ");
361 while System_Text
(P
) /= ')'
363 System_Text
(P
) /= ASCII
.LF
365 Write_Char
(System_Text
(P
));
373 -- Test for pragma Detect_Blocking;
375 elsif System_Text
(P
.. P
+ 22) = "pragma Detect_Blocking;" then
377 Opt
.Detect_Blocking
:= True;
378 goto Line_Loop_Continue
;
382 elsif System_Text
(P
.. P
+ 20) = "pragma Discard_Names;" then
384 Opt
.Global_Discard_Names
:= True;
385 goto Line_Loop_Continue
;
389 elsif System_Text
(P
.. P
+ 22) = "pragma Locking_Policy (" then
391 Opt
.Locking_Policy
:= System_Text
(P
);
392 Opt
.Locking_Policy_Sloc
:= System_Location
;
393 goto Line_Loop_Continue
;
397 elsif System_Text
(P
.. P
+ 24) = "pragma Normalize_Scalars;" then
399 Opt
.Normalize_Scalars
:= True;
400 Opt
.Init_Or_Norm_Scalars
:= True;
401 goto Line_Loop_Continue
;
405 elsif System_Text
(P
.. P
+ 19) = "pragma Polling (On);" then
407 Opt
.Polling_Required
:= True;
408 goto Line_Loop_Continue
;
410 -- Ignore pragma Pure (System)
412 elsif System_Text
(P
.. P
+ 20) = "pragma Pure (System);" then
414 goto Line_Loop_Continue
;
418 elsif System_Text
(P
.. P
+ 22) = "pragma Queuing_Policy (" then
420 Opt
.Queuing_Policy
:= System_Text
(P
);
421 Opt
.Queuing_Policy_Sloc
:= System_Location
;
422 goto Line_Loop_Continue
;
424 -- Suppress_Exception_Locations
426 elsif System_Text
(P
.. P
+ 34) =
427 "pragma Suppress_Exception_Locations;"
430 Opt
.Exception_Locations_Suppressed
:= True;
431 goto Line_Loop_Continue
;
433 -- Task_Dispatching Policy
435 elsif System_Text
(P
.. P
+ 31) =
436 "pragma Task_Dispatching_Policy ("
439 Opt
.Task_Dispatching_Policy
:= System_Text
(P
);
440 Opt
.Task_Dispatching_Policy_Sloc
:= System_Location
;
441 goto Line_Loop_Continue
;
443 -- No other pragmas are permitted
445 elsif System_Text
(P
.. P
+ 6) = "pragma " then
447 Write_Line
("unrecognized line in system.ads: ");
449 while System_Text
(P
) /= ')'
450 and then System_Text
(P
) /= ASCII
.LF
452 Write_Char
(System_Text
(P
));
460 -- See if we have a Run_Time_Name
462 elsif System_Text
(P
.. P
+ 38) =
463 " Run_Time_Name : constant String := """
468 while System_Text
(P
) in 'A' .. 'Z'
470 System_Text
(P
) in 'a' .. 'z'
472 System_Text
(P
) in '0' .. '9'
474 System_Text
(P
) = ' '
476 System_Text
(P
) = '_'
478 Add_Char_To_Name_Buffer
(System_Text
(P
));
482 if System_Text
(P
) /= '"'
483 or else System_Text
(P
+ 1) /= ';'
484 or else (System_Text
(P
+ 2) /= ASCII
.LF
486 System_Text
(P
+ 2) /= ASCII
.CR
)
490 ("incorrectly formatted Run_Time_Name in system.ads");
495 Run_Time_Name_On_Target
:= Name_Enter
;
498 goto Line_Loop_Continue
;
500 -- Next See if we have a configuration parameter
503 Config_Param_Loop
: for K
in Targparm_Tags
loop
504 if System_Text
(P
+ 3 .. P
+ 2 + Targparm_Str
(K
)'Length) =
507 P
:= P
+ 3 + Targparm_Str
(K
)'Length;
509 if Targparm_Flags
(K
) then
512 ("fatal error: system.ads is incorrectly formatted");
513 Write_Str
("duplicate line for parameter: ");
515 for J
in Targparm_Str
(K
)'Range loop
516 Write_Char
(Targparm_Str
(K
).all (J
));
524 Targparm_Flags
(K
) := True;
527 while System_Text
(P
) /= ':'
528 or else System_Text
(P
+ 1) /= '='
535 while System_Text
(P
) = ' ' loop
539 Result
:= (System_Text
(P
) = 'T');
542 when AAM
=> AAMP_On_Target
:= Result
;
543 when BDC
=> Backend_Divide_Checks_On_Target
:= Result
;
544 when BOC
=> Backend_Overflow_Checks_On_Target
:= Result
;
545 when CLA
=> Command_Line_Args_On_Target
:= Result
;
546 when CRT
=> Configurable_Run_Time_On_Target
:= Result
;
547 when CSV
=> Compiler_System_Version
:= Result
;
548 when D32
=> Duration_32_Bits_On_Target
:= Result
;
549 when DEN
=> Denorm_On_Target
:= Result
;
550 when DSP
=> Functions_Return_By_DSP_On_Target
:= Result
;
551 when EXS
=> Exit_Status_Supported_On_Target
:= Result
;
552 when FEL
=> Frontend_Layout_On_Target
:= Result
;
553 when FFO
=> Fractional_Fixed_Ops_On_Target
:= Result
;
554 when MOV
=> Machine_Overflows_On_Target
:= Result
;
555 when MRN
=> Machine_Rounds_On_Target
:= Result
;
556 when PAS
=> Preallocated_Stacks_On_Target
:= Result
;
557 when S64
=> Support_64_Bit_Divides_On_Target
:= Result
;
558 when SAG
=> Support_Aggregates_On_Target
:= Result
;
559 when SCA
=> Support_Composite_Assign_On_Target
:= Result
;
560 when SCC
=> Support_Composite_Compare_On_Target
:= Result
;
561 when SCD
=> Stack_Check_Default_On_Target
:= Result
;
562 when SCP
=> Stack_Check_Probes_On_Target
:= Result
;
563 when SLS
=> Support_Long_Shifts_On_Target
:= Result
;
564 when SSL
=> Suppress_Standard_Library_On_Target
:= Result
;
565 when SNZ
=> Signed_Zeros_On_Target
:= Result
;
566 when UAM
=> Use_Ada_Main_Program_Name_On_Target
:= Result
;
567 when VMS
=> OpenVMS_On_Target
:= Result
;
568 when ZCD
=> ZCX_By_Default_On_Target
:= Result
;
569 when ZCG
=> GCC_ZCX_Support_On_Target
:= Result
;
571 goto Line_Loop_Continue
;
574 -- Here we are seeing a parameter we do not understand. We
575 -- simply ignore this (will happen when an old compiler is
576 -- used to compile a newer version of GNAT which does not
579 end loop Config_Param_Loop
;
582 -- Here after processing one line of System spec
584 <<Line_Loop_Continue
>>
586 while System_Text
(P
) /= CR
and then System_Text
(P
) /= LF
loop
588 exit when P
>= Source_Last
;
591 while System_Text
(P
) = CR
or else System_Text
(P
) = LF
loop
593 exit when P
>= Source_Last
;
596 if P
>= Source_Last
then
598 Write_Line
("fatal error, system.ads not formatted correctly");
599 Write_Line
("unexpected end of file");
601 raise Unrecoverable_Error
;
605 -- Now that OpenVMS_On_Target has been given its definitive value,
606 -- change the multi-unit index character from '~' to '$' for OpenVMS.
608 if OpenVMS_On_Target
then
609 Multi_Unit_Index_Character
:= '$';
612 -- Check no missing target parameter settings (skip for compiler vsn)
614 if not Compiler_System_Version
then
615 for K
in Targparm_Tags_OK
loop
616 if not Targparm_Flags
(K
) then
619 ("fatal error: system.ads is incorrectly formatted");
620 Write_Str
("missing line for parameter: ");
622 for J
in Targparm_Str
(K
)'Range loop
623 Write_Char
(Targparm_Str
(K
).all (J
));
634 raise Unrecoverable_Error
;
636 end Get_Target_Parameters
;