1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2007, 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 BDC
, -- Backend_Divide_Checks
43 BOC
, -- Backend_Overflow_Checks
44 CLA
, -- Command_Line_Args
46 CRT
, -- Configurable_Run_Times
47 D32
, -- Duration_32_Bits
49 EXS
, -- Exit_Status_Supported
50 FEL
, -- Frontend_Layout
51 FFO
, -- Fractional_Fixed_Ops
53 MOV
, -- Machine_Overflows
54 MRN
, -- Machine_Rounds
55 PAS
, -- Preallocated_Stacks
56 S64
, -- Support_64_Bit_Divides
57 SAG
, -- Support_Aggregates
58 SCA
, -- Support_Composite_Assign
59 SCC
, -- Support_Composite_Compare
60 SCD
, -- Stack_Check_Default
61 SCP
, -- Stack_Check_Probes
62 SLS
, -- Support_Long_Shifts
64 SSL
, -- Suppress_Standard_Library
65 UAM
, -- Use_Ada_Main_Program_Name
67 ZCD
, -- ZCX_By_Default
68 ZCG
); -- GCC_ZCX_Support
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 BDC_Str
: aliased constant Source_Buffer
:= "Backend_Divide_Checks";
77 BOC_Str
: aliased constant Source_Buffer
:= "Backend_Overflow_Checks";
78 CLA_Str
: aliased constant Source_Buffer
:= "Command_Line_Args";
79 CLI_Str
: aliased constant Source_Buffer
:= "CLI";
80 CRT_Str
: aliased constant Source_Buffer
:= "Configurable_Run_Time";
81 D32_Str
: aliased constant Source_Buffer
:= "Duration_32_Bits";
82 DEN_Str
: aliased constant Source_Buffer
:= "Denorm";
83 EXS_Str
: aliased constant Source_Buffer
:= "Exit_Status_Supported";
84 FEL_Str
: aliased constant Source_Buffer
:= "Frontend_Layout";
85 FFO_Str
: aliased constant Source_Buffer
:= "Fractional_Fixed_Ops";
86 JVM_Str
: aliased constant Source_Buffer
:= "JVM";
87 MOV_Str
: aliased constant Source_Buffer
:= "Machine_Overflows";
88 MRN_Str
: aliased constant Source_Buffer
:= "Machine_Rounds";
89 PAS_Str
: aliased constant Source_Buffer
:= "Preallocated_Stacks";
90 S64_Str
: aliased constant Source_Buffer
:= "Support_64_Bit_Divides";
91 SAG_Str
: aliased constant Source_Buffer
:= "Support_Aggregates";
92 SCA_Str
: aliased constant Source_Buffer
:= "Support_Composite_Assign";
93 SCC_Str
: aliased constant Source_Buffer
:= "Support_Composite_Compare";
94 SCD_Str
: aliased constant Source_Buffer
:= "Stack_Check_Default";
95 SCP_Str
: aliased constant Source_Buffer
:= "Stack_Check_Probes";
96 SLS_Str
: aliased constant Source_Buffer
:= "Support_Long_Shifts";
97 SNZ_Str
: aliased constant Source_Buffer
:= "Signed_Zeros";
98 SSL_Str
: aliased constant Source_Buffer
:= "Suppress_Standard_Library";
99 UAM_Str
: aliased constant Source_Buffer
:= "Use_Ada_Main_Program_Name";
100 VMS_Str
: aliased constant Source_Buffer
:= "OpenVMS";
101 ZCD_Str
: aliased constant Source_Buffer
:= "ZCX_By_Default";
102 ZCG_Str
: aliased constant Source_Buffer
:= "GCC_ZCX_Support";
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
is
152 Text
: Source_Buffer_Ptr
;
156 if Parameters_Obtained
then
160 Name_Buffer
(1 .. 10) := "system.ads";
163 Read_Source_File
(Name_Find
, Lo
=> 0, Hi
=> Hi
, Src
=> Text
);
166 Write_Line
("fatal error, run-time library not installed correctly");
167 Write_Line
("cannot locate file system.ads");
168 raise Unrecoverable_Error
;
171 Targparm
.Get_Target_Parameters
172 (System_Text
=> Text
,
175 end Get_Target_Parameters
;
177 -- Version where caller supplies system.ads text
179 procedure Get_Target_Parameters
180 (System_Text
: Source_Buffer_Ptr
;
181 Source_First
: Source_Ptr
;
182 Source_Last
: Source_Ptr
)
185 -- Scans source buffer containing source of system.ads
187 Fatal
: Boolean := False;
188 -- Set True if a fatal error is detected
191 -- Records boolean from system line
194 if Parameters_Obtained
then
197 Parameters_Obtained
:= True;
200 Opt
.Address_Is_Private
:= False;
203 Line_Loop
: while System_Text
(P
.. P
+ 10) /= "end System;" loop
205 -- Skip comments quickly
207 if System_Text
(P
) = '-' then
208 goto Line_Loop_Continue
;
210 -- Test for type Address is private
212 elsif System_Text
(P
.. P
+ 26) = " type Address is private;" then
213 Opt
.Address_Is_Private
:= True;
215 goto Line_Loop_Continue
;
217 -- Test for pragma Profile (Ravenscar);
219 elsif System_Text
(P
.. P
+ 26) =
220 "pragma Profile (Ravenscar);"
222 Set_Profile_Restrictions
(Ravenscar
);
223 Opt
.Task_Dispatching_Policy
:= 'F';
224 Opt
.Locking_Policy
:= 'C';
226 goto Line_Loop_Continue
;
228 -- Test for pragma Profile (Restricted);
230 elsif System_Text
(P
.. P
+ 27) =
231 "pragma Profile (Restricted);"
233 Set_Profile_Restrictions
(Restricted
);
235 goto Line_Loop_Continue
;
237 -- Test for pragma Restrictions
239 elsif System_Text
(P
.. P
+ 20) = "pragma Restrictions (" then
242 Rloop
: for K
in All_Boolean_Restrictions
loop
244 Rname
: constant String := Restriction_Id
'Image (K
);
247 for J
in Rname
'Range loop
248 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
255 if System_Text
(P
+ Rname
'Length) = ')' then
256 Restrictions_On_Target
.Set
(K
) := True;
257 goto Line_Loop_Continue
;
265 Ploop
: for K
in All_Parameter_Restrictions
loop
267 Rname
: constant String :=
268 All_Parameter_Restrictions
'Image (K
);
274 for J
in Rname
'Range loop
275 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
282 if System_Text
(P
+ Rname
'Length .. P
+ Rname
'Length + 3) =
285 P
:= P
+ Rname
'Length + 4;
289 if System_Text
(P
) in '0' .. '9' then
291 pragma Unsuppress
(Overflow_Check
);
294 -- Accumulate next digit
297 Character'Pos (System_Text
(P
)) -
301 -- On overflow, we just ignore the pragma since
302 -- that is the standard handling in this case.
304 when Constraint_Error
=>
305 goto Line_Loop_Continue
;
308 elsif System_Text
(P
) = '_' then
311 elsif System_Text
(P
) = ')' then
312 Restrictions_On_Target
.Value
(K
) := V
;
313 Restrictions_On_Target
.Set
(K
) := True;
314 goto Line_Loop_Continue
;
334 ("fatal error: system.ads is incorrectly formatted");
335 Write_Str
("unrecognized or incorrect restrictions pragma: ");
337 while System_Text
(P
) /= ')'
339 System_Text
(P
) /= ASCII
.LF
341 Write_Char
(System_Text
(P
));
349 -- Test for pragma Detect_Blocking;
351 elsif System_Text
(P
.. P
+ 22) = "pragma Detect_Blocking;" then
353 Opt
.Detect_Blocking
:= True;
354 goto Line_Loop_Continue
;
358 elsif System_Text
(P
.. P
+ 20) = "pragma Discard_Names;" then
360 Opt
.Global_Discard_Names
:= True;
361 goto Line_Loop_Continue
;
365 elsif System_Text
(P
.. P
+ 22) = "pragma Locking_Policy (" then
367 Opt
.Locking_Policy
:= System_Text
(P
);
368 Opt
.Locking_Policy_Sloc
:= System_Location
;
369 goto Line_Loop_Continue
;
373 elsif System_Text
(P
.. P
+ 24) = "pragma Normalize_Scalars;" then
375 Opt
.Normalize_Scalars
:= True;
376 Opt
.Init_Or_Norm_Scalars
:= True;
377 goto Line_Loop_Continue
;
381 elsif System_Text
(P
.. P
+ 19) = "pragma Polling (On);" then
383 Opt
.Polling_Required
:= True;
384 goto Line_Loop_Continue
;
386 -- Ignore pragma Pure (System)
388 elsif System_Text
(P
.. P
+ 20) = "pragma Pure (System);" then
390 goto Line_Loop_Continue
;
394 elsif System_Text
(P
.. P
+ 22) = "pragma Queuing_Policy (" then
396 Opt
.Queuing_Policy
:= System_Text
(P
);
397 Opt
.Queuing_Policy_Sloc
:= System_Location
;
398 goto Line_Loop_Continue
;
400 -- Suppress_Exception_Locations
402 elsif System_Text
(P
.. P
+ 34) =
403 "pragma Suppress_Exception_Locations;"
406 Opt
.Exception_Locations_Suppressed
:= True;
407 goto Line_Loop_Continue
;
409 -- Task_Dispatching Policy
411 elsif System_Text
(P
.. P
+ 31) =
412 "pragma Task_Dispatching_Policy ("
415 Opt
.Task_Dispatching_Policy
:= System_Text
(P
);
416 Opt
.Task_Dispatching_Policy_Sloc
:= System_Location
;
417 goto Line_Loop_Continue
;
419 -- No other pragmas are permitted
421 elsif System_Text
(P
.. P
+ 6) = "pragma " then
423 Write_Line
("unrecognized line in system.ads: ");
425 while System_Text
(P
) /= ')'
426 and then System_Text
(P
) /= ASCII
.LF
428 Write_Char
(System_Text
(P
));
436 -- See if we have a Run_Time_Name
438 elsif System_Text
(P
.. P
+ 38) =
439 " Run_Time_Name : constant String := """
444 while System_Text
(P
) in 'A' .. 'Z'
446 System_Text
(P
) in 'a' .. 'z'
448 System_Text
(P
) in '0' .. '9'
450 System_Text
(P
) = ' '
452 System_Text
(P
) = '_'
454 Add_Char_To_Name_Buffer
(System_Text
(P
));
458 if System_Text
(P
) /= '"'
459 or else System_Text
(P
+ 1) /= ';'
460 or else (System_Text
(P
+ 2) /= ASCII
.LF
462 System_Text
(P
+ 2) /= ASCII
.CR
)
466 ("incorrectly formatted Run_Time_Name in system.ads");
471 Run_Time_Name_On_Target
:= Name_Enter
;
474 goto Line_Loop_Continue
;
476 -- See if we have an Executable_Extension
478 elsif System_Text
(P
.. P
+ 45) =
479 " Executable_Extension : constant String := """
484 while System_Text
(P
) /= '"'
485 and then System_Text
(P
) /= ASCII
.LF
487 Add_Char_To_Name_Buffer
(System_Text
(P
));
491 if System_Text
(P
) /= '"' or else System_Text
(P
+ 1) /= ';' then
494 ("incorrectly formatted Executable_Extension in system.ads");
499 Executable_Extension_On_Target
:= Name_Enter
;
502 goto Line_Loop_Continue
;
504 -- Next See if we have a configuration parameter
507 Config_Param_Loop
: for K
in Targparm_Tags
loop
508 if System_Text
(P
+ 3 .. P
+ 2 + Targparm_Str
(K
)'Length) =
511 P
:= P
+ 3 + Targparm_Str
(K
)'Length;
513 if Targparm_Flags
(K
) then
516 ("fatal error: system.ads is incorrectly formatted");
517 Write_Str
("duplicate line for parameter: ");
519 for J
in Targparm_Str
(K
)'Range loop
520 Write_Char
(Targparm_Str
(K
).all (J
));
528 Targparm_Flags
(K
) := True;
531 while System_Text
(P
) /= ':'
532 or else System_Text
(P
+ 1) /= '='
539 while System_Text
(P
) = ' ' loop
543 Result
:= (System_Text
(P
) = 'T');
546 when AAM
=> AAMP_On_Target
:= Result
;
547 when BDC
=> Backend_Divide_Checks_On_Target
:= Result
;
548 when BOC
=> Backend_Overflow_Checks_On_Target
:= Result
;
549 when CLA
=> Command_Line_Args_On_Target
:= Result
;
552 VM_Target
:= CLI_Target
;
555 when CRT
=> Configurable_Run_Time_On_Target
:= Result
;
556 when D32
=> Duration_32_Bits_On_Target
:= Result
;
557 when DEN
=> Denorm_On_Target
:= Result
;
558 when EXS
=> Exit_Status_Supported_On_Target
:= Result
;
559 when FEL
=> Frontend_Layout_On_Target
:= Result
;
560 when FFO
=> Fractional_Fixed_Ops_On_Target
:= Result
;
563 VM_Target
:= JVM_Target
;
566 when MOV
=> Machine_Overflows_On_Target
:= Result
;
567 when MRN
=> Machine_Rounds_On_Target
:= Result
;
568 when PAS
=> Preallocated_Stacks_On_Target
:= Result
;
569 when S64
=> Support_64_Bit_Divides_On_Target
:= Result
;
570 when SAG
=> Support_Aggregates_On_Target
:= Result
;
571 when SCA
=> Support_Composite_Assign_On_Target
:= Result
;
572 when SCC
=> Support_Composite_Compare_On_Target
:= Result
;
573 when SCD
=> Stack_Check_Default_On_Target
:= Result
;
574 when SCP
=> Stack_Check_Probes_On_Target
:= Result
;
575 when SLS
=> Support_Long_Shifts_On_Target
:= Result
;
576 when SSL
=> Suppress_Standard_Library_On_Target
:= Result
;
577 when SNZ
=> Signed_Zeros_On_Target
:= Result
;
578 when UAM
=> Use_Ada_Main_Program_Name_On_Target
:= Result
;
579 when VMS
=> OpenVMS_On_Target
:= Result
;
580 when ZCD
=> ZCX_By_Default_On_Target
:= Result
;
581 when ZCG
=> GCC_ZCX_Support_On_Target
:= Result
;
583 goto Line_Loop_Continue
;
586 -- Here we are seeing a parameter we do not understand. We
587 -- simply ignore this (will happen when an old compiler is
588 -- used to compile a newer version of GNAT which does not
591 end loop Config_Param_Loop
;
594 -- Here after processing one line of System spec
596 <<Line_Loop_Continue
>>
598 while System_Text
(P
) /= CR
and then System_Text
(P
) /= LF
loop
600 exit when P
>= Source_Last
;
603 while System_Text
(P
) = CR
or else System_Text
(P
) = LF
loop
605 exit when P
>= Source_Last
;
608 if P
>= Source_Last
then
610 Write_Line
("fatal error, system.ads not formatted correctly");
611 Write_Line
("unexpected end of file");
613 raise Unrecoverable_Error
;
617 -- Now that OpenVMS_On_Target has been given its definitive value,
618 -- change the multi-unit index character from '~' to '$' for OpenVMS.
620 if OpenVMS_On_Target
then
621 Multi_Unit_Index_Character
:= '$';
625 raise Unrecoverable_Error
;
627 end Get_Target_Parameters
;
629 ------------------------------
630 -- Set_Profile_Restrictions --
631 ------------------------------
633 procedure Set_Profile_Restrictions
(P
: Profile_Name
) is
634 R
: Restriction_Flags
renames Profile_Info
(P
).Set
;
635 V
: Restriction_Values
renames Profile_Info
(P
).Value
;
637 for J
in R
'Range loop
639 Restrictions_On_Target
.Set
(J
) := True;
641 if J
in All_Parameter_Restrictions
then
642 Restrictions_On_Target
.Value
(J
) := V
(J
);
646 end Set_Profile_Restrictions
;