1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2013, 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 RTX
, -- RTX_RTSS_Kernel_Module
59 SAG
, -- Support_Aggregates
60 SAP
, -- Support_Atomic_Primitives
61 SCA
, -- Support_Composite_Assign
62 SCC
, -- Support_Composite_Compare
63 SCD
, -- Stack_Check_Default
64 SCL
, -- Stack_Check_Limits
65 SCP
, -- Stack_Check_Probes
66 SLS
, -- Support_Long_Shifts
68 SSL
, -- Suppress_Standard_Library
69 UAM
, -- Use_Ada_Main_Program_Name
72 ZCD
); -- ZCX_By_Default
74 Targparm_Flags
: array (Targparm_Tags
) of Boolean := (others => False);
75 -- Flag is set True if corresponding parameter is scanned
77 -- The following list of string constants gives the parameter names
79 AAM_Str
: aliased constant Source_Buffer
:= "AAMP";
80 ACR_Str
: aliased constant Source_Buffer
:= "Always_Compatible_Rep";
81 ASD_Str
: aliased constant Source_Buffer
:= "Atomic_Sync_Default";
82 BDC_Str
: aliased constant Source_Buffer
:= "Backend_Divide_Checks";
83 BOC_Str
: aliased constant Source_Buffer
:= "Backend_Overflow_Checks";
84 CLA_Str
: aliased constant Source_Buffer
:= "Command_Line_Args";
85 CLI_Str
: aliased constant Source_Buffer
:= "CLI";
86 CRT_Str
: aliased constant Source_Buffer
:= "Configurable_Run_Time";
87 D32_Str
: aliased constant Source_Buffer
:= "Duration_32_Bits";
88 DEN_Str
: aliased constant Source_Buffer
:= "Denorm";
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 JVM_Str
: aliased constant Source_Buffer
:= "JVM";
93 MOV_Str
: aliased constant Source_Buffer
:= "Machine_Overflows";
94 MRN_Str
: aliased constant Source_Buffer
:= "Machine_Rounds";
95 PAS_Str
: aliased constant Source_Buffer
:= "Preallocated_Stacks";
96 RTX_Str
: aliased constant Source_Buffer
:= "RTX_RTSS_Kernel_Module";
97 SAG_Str
: aliased constant Source_Buffer
:= "Support_Aggregates";
98 SAP_Str
: aliased constant Source_Buffer
:= "Support_Atomic_Primitives";
99 SCA_Str
: aliased constant Source_Buffer
:= "Support_Composite_Assign";
100 SCC_Str
: aliased constant Source_Buffer
:= "Support_Composite_Compare";
101 SCD_Str
: aliased constant Source_Buffer
:= "Stack_Check_Default";
102 SCL_Str
: aliased constant Source_Buffer
:= "Stack_Check_Limits";
103 SCP_Str
: aliased constant Source_Buffer
:= "Stack_Check_Probes";
104 SLS_Str
: aliased constant Source_Buffer
:= "Support_Long_Shifts";
105 SNZ_Str
: aliased constant Source_Buffer
:= "Signed_Zeros";
106 SSL_Str
: aliased constant Source_Buffer
:= "Suppress_Standard_Library";
107 UAM_Str
: aliased constant Source_Buffer
:= "Use_Ada_Main_Program_Name";
108 VMS_Str
: aliased constant Source_Buffer
:= "OpenVMS";
109 VXF_Str
: aliased constant Source_Buffer
:= "VAX_Float";
110 ZCD_Str
: aliased constant Source_Buffer
:= "ZCX_By_Default";
112 -- The following defines a set of pointers to the above strings,
113 -- indexed by the tag values.
115 type Buffer_Ptr
is access constant Source_Buffer
;
116 Targparm_Str
: constant array (Targparm_Tags
) of Buffer_Ptr
:=
150 -----------------------
151 -- Local Subprograms --
152 -----------------------
154 procedure Set_Profile_Restrictions
(P
: Profile_Name
);
155 -- Set Restrictions_On_Target for the given profile
157 ---------------------------
158 -- Get_Target_Parameters --
159 ---------------------------
161 -- Version which reads in system.ads
163 procedure Get_Target_Parameters
is
164 Text
: Source_Buffer_Ptr
;
168 if Parameters_Obtained
then
172 Name_Buffer
(1 .. 10) := "system.ads";
175 Read_Source_File
(Name_Find
, Lo
=> 0, Hi
=> Hi
, Src
=> Text
);
178 Write_Line
("fatal error, run-time library not installed correctly");
179 Write_Line
("cannot locate file system.ads");
180 raise Unrecoverable_Error
;
183 Get_Target_Parameters
184 (System_Text
=> Text
,
187 end Get_Target_Parameters
;
189 -- Version where caller supplies system.ads text
191 procedure Get_Target_Parameters
192 (System_Text
: Source_Buffer_Ptr
;
193 Source_First
: Source_Ptr
;
194 Source_Last
: Source_Ptr
)
197 -- Scans source buffer containing source of system.ads
199 Fatal
: Boolean := False;
200 -- Set True if a fatal error is detected
203 -- Records boolean from system line
206 if Parameters_Obtained
then
209 Parameters_Obtained
:= True;
212 Opt
.Address_Is_Private
:= False;
215 Line_Loop
: while System_Text
(P
.. P
+ 10) /= "end System;" loop
217 -- Skip comments quickly
219 if System_Text
(P
) = '-' then
220 goto Line_Loop_Continue
;
222 -- Test for type Address is private
224 elsif System_Text
(P
.. P
+ 26) = " type Address is private;" then
225 Opt
.Address_Is_Private
:= True;
227 goto Line_Loop_Continue
;
229 -- Test for pragma Profile (Ravenscar);
231 elsif System_Text
(P
.. P
+ 26) =
232 "pragma Profile (Ravenscar);"
234 Set_Profile_Restrictions
(Ravenscar
);
235 Opt
.Task_Dispatching_Policy
:= 'F';
236 Opt
.Locking_Policy
:= 'C';
238 goto Line_Loop_Continue
;
240 -- Test for pragma Profile (Restricted);
242 elsif System_Text
(P
.. P
+ 27) =
243 "pragma Profile (Restricted);"
245 Set_Profile_Restrictions
(Restricted
);
247 goto Line_Loop_Continue
;
249 -- Test for pragma Restrictions
251 elsif System_Text
(P
.. P
+ 20) = "pragma Restrictions (" then
254 Rloop
: for K
in All_Boolean_Restrictions
loop
256 Rname
: constant String := Restriction_Id
'Image (K
);
259 for J
in Rname
'Range loop
260 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
267 if System_Text
(P
+ Rname
'Length) = ')' then
268 Restrictions_On_Target
.Set
(K
) := True;
269 goto Line_Loop_Continue
;
277 Ploop
: for K
in All_Parameter_Restrictions
loop
279 Rname
: constant String :=
280 All_Parameter_Restrictions
'Image (K
);
286 for J
in Rname
'Range loop
287 if Fold_Upper
(System_Text
(P
+ Source_Ptr
(J
- 1)))
294 if System_Text
(P
+ Rname
'Length .. P
+ Rname
'Length + 3) =
297 P
:= P
+ Rname
'Length + 4;
301 if System_Text
(P
) in '0' .. '9' then
303 pragma Unsuppress
(Overflow_Check
);
306 -- Accumulate next digit
309 Character'Pos (System_Text
(P
)) -
313 -- On overflow, we just ignore the pragma since
314 -- that is the standard handling in this case.
316 when Constraint_Error
=>
317 goto Line_Loop_Continue
;
320 elsif System_Text
(P
) = '_' then
323 elsif System_Text
(P
) = ')' then
324 Restrictions_On_Target
.Value
(K
) := V
;
325 Restrictions_On_Target
.Set
(K
) := True;
326 goto Line_Loop_Continue
;
346 ("fatal error: system.ads is incorrectly formatted");
347 Write_Str
("unrecognized or incorrect restrictions pragma: ");
349 while System_Text
(P
) /= ')'
351 System_Text
(P
) /= ASCII
.LF
353 Write_Char
(System_Text
(P
));
361 -- Test for pragma Detect_Blocking;
363 elsif System_Text
(P
.. P
+ 22) = "pragma Detect_Blocking;" then
365 Opt
.Detect_Blocking
:= True;
366 goto Line_Loop_Continue
;
370 elsif System_Text
(P
.. P
+ 20) = "pragma Discard_Names;" then
372 Opt
.Global_Discard_Names
:= True;
373 goto Line_Loop_Continue
;
377 elsif System_Text
(P
.. P
+ 22) = "pragma Locking_Policy (" then
379 Opt
.Locking_Policy
:= System_Text
(P
);
380 Opt
.Locking_Policy_Sloc
:= System_Location
;
381 goto Line_Loop_Continue
;
385 elsif System_Text
(P
.. P
+ 24) = "pragma Normalize_Scalars;" then
387 Opt
.Normalize_Scalars
:= True;
388 Opt
.Init_Or_Norm_Scalars
:= True;
389 goto Line_Loop_Continue
;
391 -- Partition_Elaboration_Policy
393 elsif System_Text
(P
.. P
+ 36) =
394 "pragma Partition_Elaboration_Policy ("
397 Opt
.Partition_Elaboration_Policy
:= System_Text
(P
);
398 Opt
.Partition_Elaboration_Policy_Sloc
:= System_Location
;
399 goto Line_Loop_Continue
;
403 elsif System_Text
(P
.. P
+ 19) = "pragma Polling (On);" then
405 Opt
.Polling_Required
:= True;
406 goto Line_Loop_Continue
;
408 -- Ignore pragma Pure (System)
410 elsif System_Text
(P
.. P
+ 20) = "pragma Pure (System);" then
412 goto Line_Loop_Continue
;
416 elsif System_Text
(P
.. P
+ 22) = "pragma Queuing_Policy (" then
418 Opt
.Queuing_Policy
:= System_Text
(P
);
419 Opt
.Queuing_Policy_Sloc
:= System_Location
;
420 goto Line_Loop_Continue
;
422 -- Suppress_Exception_Locations
424 elsif System_Text
(P
.. P
+ 35) =
425 "pragma Suppress_Exception_Locations;"
428 Opt
.Exception_Locations_Suppressed
:= True;
429 goto Line_Loop_Continue
;
431 -- Task_Dispatching Policy
433 elsif System_Text
(P
.. P
+ 31) =
434 "pragma Task_Dispatching_Policy ("
437 Opt
.Task_Dispatching_Policy
:= System_Text
(P
);
438 Opt
.Task_Dispatching_Policy_Sloc
:= System_Location
;
439 goto Line_Loop_Continue
;
441 -- No other pragmas are permitted
443 elsif System_Text
(P
.. P
+ 6) = "pragma " then
445 Write_Line
("unrecognized line in system.ads: ");
447 while System_Text
(P
) /= ')'
448 and then System_Text
(P
) /= ASCII
.LF
450 Write_Char
(System_Text
(P
));
458 -- See if we have a Run_Time_Name
460 elsif System_Text
(P
.. P
+ 38) =
461 " Run_Time_Name : constant String := """
466 while System_Text
(P
) in 'A' .. 'Z'
468 System_Text
(P
) in 'a' .. 'z'
470 System_Text
(P
) in '0' .. '9'
472 System_Text
(P
) = ' '
474 System_Text
(P
) = '_'
476 Add_Char_To_Name_Buffer
(System_Text
(P
));
480 if System_Text
(P
) /= '"'
481 or else System_Text
(P
+ 1) /= ';'
482 or else (System_Text
(P
+ 2) /= ASCII
.LF
484 System_Text
(P
+ 2) /= ASCII
.CR
)
488 ("incorrectly formatted Run_Time_Name in system.ads");
493 Run_Time_Name_On_Target
:= Name_Enter
;
496 goto Line_Loop_Continue
;
498 -- See if we have an Executable_Extension
500 elsif System_Text
(P
.. P
+ 45) =
501 " Executable_Extension : constant String := """
506 while System_Text
(P
) /= '"'
507 and then System_Text
(P
) /= ASCII
.LF
509 Add_Char_To_Name_Buffer
(System_Text
(P
));
513 if System_Text
(P
) /= '"' or else System_Text
(P
+ 1) /= ';' then
516 ("incorrectly formatted Executable_Extension in system.ads");
521 Executable_Extension_On_Target
:= Name_Enter
;
524 goto Line_Loop_Continue
;
526 -- Next see if we have a configuration parameter
529 Config_Param_Loop
: for K
in Targparm_Tags
loop
530 if System_Text
(P
+ 3 .. P
+ 2 + Targparm_Str
(K
)'Length) =
533 P
:= P
+ 3 + Targparm_Str
(K
)'Length;
535 if Targparm_Flags
(K
) then
538 ("fatal error: system.ads is incorrectly formatted");
539 Write_Str
("duplicate line for parameter: ");
541 for J
in Targparm_Str
(K
)'Range loop
542 Write_Char
(Targparm_Str
(K
).all (J
));
550 Targparm_Flags
(K
) := True;
553 while System_Text
(P
) /= ':'
554 or else System_Text
(P
+ 1) /= '='
561 while System_Text
(P
) = ' ' loop
565 Result
:= (System_Text
(P
) = 'T');
568 when AAM
=> AAMP_On_Target
:= Result
;
569 when ACR
=> Always_Compatible_Rep_On_Target
:= Result
;
570 when ASD
=> Atomic_Sync_Default_On_Target
:= Result
;
571 when BDC
=> Backend_Divide_Checks_On_Target
:= Result
;
572 when BOC
=> Backend_Overflow_Checks_On_Target
:= Result
;
573 when CLA
=> Command_Line_Args_On_Target
:= Result
;
576 VM_Target
:= CLI_Target
;
577 Tagged_Type_Expansion
:= False;
579 -- This is wrong, this processing should be done in
580 -- Gnat1drv.Adjust_Global_Switches. It is not the
581 -- right level for targparm to know about tagged
584 when CRT
=> Configurable_Run_Time_On_Target
:= Result
;
585 when D32
=> Duration_32_Bits_On_Target
:= Result
;
586 when DEN
=> Denorm_On_Target
:= Result
;
587 when EXS
=> Exit_Status_Supported_On_Target
:= Result
;
588 when FEL
=> Frontend_Layout_On_Target
:= Result
;
589 when FFO
=> Fractional_Fixed_Ops_On_Target
:= Result
;
592 VM_Target
:= JVM_Target
;
593 Tagged_Type_Expansion
:= False;
595 -- This is wrong, this processing should be done in
596 -- Gnat1drv.Adjust_Global_Switches. It is not the
597 -- right level for targparm to know about tagged
600 when MOV
=> Machine_Overflows_On_Target
:= Result
;
601 when MRN
=> Machine_Rounds_On_Target
:= Result
;
602 when PAS
=> Preallocated_Stacks_On_Target
:= Result
;
603 when RTX
=> RTX_RTSS_Kernel_Module_On_Target
:= Result
;
604 when SAG
=> Support_Aggregates_On_Target
:= Result
;
605 when SAP
=> Support_Atomic_Primitives_On_Target
:= Result
;
606 when SCA
=> Support_Composite_Assign_On_Target
:= Result
;
607 when SCC
=> Support_Composite_Compare_On_Target
:= Result
;
608 when SCD
=> Stack_Check_Default_On_Target
:= Result
;
609 when SCL
=> Stack_Check_Limits_On_Target
:= Result
;
610 when SCP
=> Stack_Check_Probes_On_Target
:= Result
;
611 when SLS
=> Support_Long_Shifts_On_Target
:= Result
;
612 when SSL
=> Suppress_Standard_Library_On_Target
:= Result
;
613 when SNZ
=> Signed_Zeros_On_Target
:= Result
;
614 when UAM
=> Use_Ada_Main_Program_Name_On_Target
:= Result
;
615 when VMS
=> OpenVMS_On_Target
:= Result
;
616 when VXF
=> VAX_Float_On_Target
:= Result
;
617 when ZCD
=> ZCX_By_Default_On_Target
:= Result
;
619 goto Line_Loop_Continue
;
622 -- Here we are seeing a parameter we do not understand. We
623 -- simply ignore this (will happen when an old compiler is
624 -- used to compile a newer version of GNAT which does not
625 -- support the parameter).
627 end loop Config_Param_Loop
;
630 -- Here after processing one line of System spec
632 <<Line_Loop_Continue
>>
634 while System_Text
(P
) /= CR
and then System_Text
(P
) /= LF
loop
636 exit when P
>= Source_Last
;
639 while System_Text
(P
) = CR
or else System_Text
(P
) = LF
loop
641 exit when P
>= Source_Last
;
644 if P
>= Source_Last
then
646 Write_Line
("fatal error, system.ads not formatted correctly");
647 Write_Line
("unexpected end of file");
649 raise Unrecoverable_Error
;
653 -- Now that OpenVMS_On_Target has been given its definitive value,
654 -- change the multi-unit index character from '~' to '$' for OpenVMS.
656 if OpenVMS_On_Target
then
657 Multi_Unit_Index_Character
:= '$';
661 raise Unrecoverable_Error
;
663 end Get_Target_Parameters
;
665 ------------------------------
666 -- Set_Profile_Restrictions --
667 ------------------------------
669 procedure Set_Profile_Restrictions
(P
: Profile_Name
) is
670 R
: Restriction_Flags
renames Profile_Info
(P
).Set
;
671 V
: Restriction_Values
renames Profile_Info
(P
).Value
;
673 for J
in R
'Range loop
675 Restrictions_On_Target
.Set
(J
) := True;
677 if J
in All_Parameter_Restrictions
then
678 Restrictions_On_Target
.Value
(J
) := V
(J
);
682 end Set_Profile_Restrictions
;