1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1999-2004 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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;
32 with Uintp; use Uintp;
34 package body Targparm is
37 Parameters_Obtained : Boolean := False;
38 -- Set True after first call to Get_Target_Parameters. Used to avoid
39 -- reading system.ads more than once, since it cannot change.
41 -- The following array defines a tag name for each entry
45 BDC, -- Backend_Divide_Checks
46 BOC, -- Backend_Overflow_Checks
47 CLA, -- Command_Line_Args
48 CRT, -- Configurable_Run_Time
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 S64, -- Support_64_Bit_Divides
58 SAG, -- Support_Aggregates
59 SCA, -- Support_Composite_Assign
60 SCC, -- Support_Composite_Compare
61 SCD, -- Stack_Check_Default
62 SCP, -- Stack_Check_Probes
63 SLS, -- Support_Long_Shifts
65 SSL, -- Suppress_Standard_Library
66 UAM, -- Use_Ada_Main_Program_Name
68 ZCD, -- ZCX_By_Default
69 ZCG, -- GCC_ZCX_Support
70 ZCF, -- Front_End_ZCX_Support
72 -- The following entries are obsolete and can eventually be removed
74 HIM, -- High_Integrity_Mode
75 LSI); -- Long_Shifts_Inlined
77 subtype Targparm_Tags_OK is Targparm_Tags range AAM .. ZCF;
78 -- Range excluding obsolete entries
80 Targparm_Flags : array (Targparm_Tags) of Boolean := (others => False);
81 -- Flag is set True if corresponding parameter is scanned
83 -- The following list of string constants gives the parameter names
85 AAM_Str : aliased constant Source_Buffer := "AAMP";
86 BDC_Str : aliased constant Source_Buffer := "Backend_Divide_Checks";
87 BOC_Str : aliased constant Source_Buffer := "Backend_Overflow_Checks";
88 CLA_Str : aliased constant Source_Buffer := "Command_Line_Args";
89 CRT_Str : aliased constant Source_Buffer := "Configurable_Run_Time";
90 D32_Str : aliased constant Source_Buffer := "Duration_32_Bits";
91 DEN_Str : aliased constant Source_Buffer := "Denorm";
92 DSP_Str : aliased constant Source_Buffer := "Functions_Return_By_DSP";
93 EXS_Str : aliased constant Source_Buffer := "Exit_Status_Supported";
94 FEL_Str : aliased constant Source_Buffer := "Frontend_Layout";
95 FFO_Str : aliased constant Source_Buffer := "Fractional_Fixed_Ops";
96 MOV_Str : aliased constant Source_Buffer := "Machine_Overflows";
97 MRN_Str : aliased constant Source_Buffer := "Machine_Rounds";
98 S64_Str : aliased constant Source_Buffer := "Support_64_Bit_Divides";
99 SAG_Str : aliased constant Source_Buffer := "Support_Aggregates";
100 SCA_Str : aliased constant Source_Buffer := "Support_Composite_Assign";
101 SCC_Str : aliased constant Source_Buffer := "Support_Composite_Compare";
102 SCD_Str : aliased constant Source_Buffer := "Stack_Check_Default";
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 ZCD_Str : aliased constant Source_Buffer := "ZCX_By_Default";
110 ZCG_Str : aliased constant Source_Buffer := "GCC_ZCX_Support";
111 ZCF_Str : aliased constant Source_Buffer := "Front_End_ZCX_Support";
115 HIM_Str : aliased constant Source_Buffer := "High_Integrity_Mode";
116 LSI_Str : aliased constant Source_Buffer := "Long_Shifts_Inlined";
118 -- The following defines a set of pointers to the above strings,
119 -- indexed by the tag values.
121 type Buffer_Ptr is access constant Source_Buffer;
122 Targparm_Str : constant array (Targparm_Tags) of Buffer_Ptr :=
156 ---------------------------
157 -- Get_Target_Parameters --
158 ---------------------------
160 -- Version which reads in system.ads
162 procedure Get_Target_Parameters is
163 Text : Source_Buffer_Ptr;
167 if Parameters_Obtained then
171 Name_Buffer (1 .. 10) := "system.ads";
174 Read_Source_File (Name_Find, Lo => 0, Hi => Hi, Src => Text);
177 Write_Line ("fatal error, run-time library not installed correctly");
178 Write_Line ("cannot locate file system.ads");
179 raise Unrecoverable_Error;
182 Targparm.Get_Target_Parameters
183 (System_Text => Text,
186 end Get_Target_Parameters;
188 -- Version where caller supplies system.ads text
190 procedure Get_Target_Parameters
191 (System_Text : Source_Buffer_Ptr;
192 Source_First : Source_Ptr;
193 Source_Last : Source_Ptr)
198 Fatal : Boolean := False;
199 -- Set True if a fatal error is detected
202 -- Records boolean from system line
205 if Parameters_Obtained then
208 Parameters_Obtained := True;
212 Line_Loop : while System_Text (P .. P + 10) /= "end System;" loop
214 -- Skip comments quickly
216 if System_Text (P) = '-' then
217 goto Line_Loop_Continue;
219 -- Test for pragma Restrictions
221 elsif System_Text (P .. P + 20) = "pragma Restrictions (" then
224 Rloop : for K in Partition_Boolean_Restrictions loop
226 Rname : constant String := Restriction_Id'Image (K);
229 for J in Rname'Range loop
230 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
237 if System_Text (P + Rname'Length) = ')' then
238 Restrictions_On_Target.Set (K) := True;
239 goto Line_Loop_Continue;
247 Ploop : for K in All_Parameter_Restrictions loop
249 Rname : constant String :=
250 All_Parameter_Restrictions'Image (K);
253 for J in Rname'Range loop
254 if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
261 if System_Text (P + Rname'Length .. P + Rname'Length + 3) =
264 P := P + Rname'Length + 4;
268 if System_Text (P) in '0' .. '9' then
269 V := 10 * V + Character'Pos (System_Text (P)) - 48;
270 elsif System_Text (P) = '_' then
272 elsif System_Text (P) = ')' then
273 if UI_Is_In_Int_Range (V) then
274 Restrictions_On_Target.Value (K) :=
275 Integer (UI_To_Int (V));
276 Restrictions_On_Target.Set (K) := True;
277 goto Line_Loop_Continue;
299 ("fatal error: system.ads is incorrectly formatted");
300 Write_Str ("unrecognized or incorrect restrictions pragma: ");
302 while System_Text (P) /= ')'
304 System_Text (P) /= ASCII.LF
306 Write_Char (System_Text (P));
316 elsif System_Text (P .. P + 20) = "pragma Discard_Names;" then
318 Opt.Global_Discard_Names := True;
319 goto Line_Loop_Continue;
323 elsif System_Text (P .. P + 22) = "pragma Locking_Policy (" then
325 Opt.Locking_Policy := System_Text (P);
326 Opt.Locking_Policy_Sloc := System_Location;
327 goto Line_Loop_Continue;
331 elsif System_Text (P .. P + 24) = "pragma Normalize_Scalars;" then
333 Opt.Normalize_Scalars := True;
334 Opt.Init_Or_Norm_Scalars := True;
335 goto Line_Loop_Continue;
339 elsif System_Text (P .. P + 19) = "pragma Polling (On);" then
341 Opt.Polling_Required := True;
342 goto Line_Loop_Continue;
344 -- Ignore pragma Pure (System)
346 elsif System_Text (P .. P + 20) = "pragma Pure (System);" then
348 goto Line_Loop_Continue;
352 elsif System_Text (P .. P + 22) = "pragma Queuing_Policy (" then
354 Opt.Queuing_Policy := System_Text (P);
355 Opt.Queuing_Policy_Sloc := System_Location;
356 goto Line_Loop_Continue;
358 -- Suppress_Exception_Locations
360 elsif System_Text (P .. P + 34) =
361 "pragma Suppress_Exception_Locations;"
364 Opt.Exception_Locations_Suppressed := True;
365 goto Line_Loop_Continue;
367 -- Task_Dispatching Policy
369 elsif System_Text (P .. P + 31) =
370 "pragma Task_Dispatching_Policy ("
373 Opt.Task_Dispatching_Policy := System_Text (P);
374 Opt.Task_Dispatching_Policy_Sloc := System_Location;
375 goto Line_Loop_Continue;
377 -- No other pragmas are permitted
379 elsif System_Text (P .. P + 6) = "pragma " then
381 Write_Line ("unrecognized line in system.ads: ");
383 while System_Text (P) /= ')'
384 and then System_Text (P) /= ASCII.LF
386 Write_Char (System_Text (P));
394 -- See if we have a Run_Time_Name
396 elsif System_Text (P .. P + 38) =
397 " Run_Time_Name : constant String := """
402 while System_Text (P) in 'A' .. 'Z'
404 System_Text (P) in 'a' .. 'z'
406 System_Text (P) in '0' .. '9'
408 System_Text (P) = ' '
410 System_Text (P) = '_'
412 Add_Char_To_Name_Buffer (System_Text (P));
416 if System_Text (P) /= '"'
417 or else System_Text (P + 1) /= ';'
418 or else (System_Text (P + 2) /= ASCII.LF
420 System_Text (P + 2) /= ASCII.CR)
424 ("incorrectly formatted Run_Time_Name in system.ads");
429 Run_Time_Name_On_Target := Name_Enter;
432 goto Line_Loop_Continue;
434 -- Next See if we have a configuration parameter
437 Config_Param_Loop : for K in Targparm_Tags loop
438 if System_Text (P + 3 .. P + 2 + Targparm_Str (K)'Length) =
441 P := P + 3 + Targparm_Str (K)'Length;
444 if Targparm_Flags (K) then
447 ("fatal error: system.ads is incorrectly formatted");
448 Write_Str ("duplicate line for parameter: ");
450 for J in Targparm_Str (K)'Range loop
451 Write_Char (Targparm_Str (K).all (J));
459 Targparm_Flags (K) := True;
462 while System_Text (P) /= ':'
463 or else System_Text (P + 1) /= '='
470 while System_Text (P) = ' ' loop
474 Result := (System_Text (P) = 'T');
477 when AAM => AAMP_On_Target := Result;
478 when BDC => Backend_Divide_Checks_On_Target := Result;
479 when BOC => Backend_Overflow_Checks_On_Target := Result;
480 when CLA => Command_Line_Args_On_Target := Result;
481 when CRT => Configurable_Run_Time_On_Target := Result;
482 when D32 => Duration_32_Bits_On_Target := Result;
483 when DEN => Denorm_On_Target := Result;
484 when DSP => Functions_Return_By_DSP_On_Target := Result;
485 when EXS => Exit_Status_Supported_On_Target := Result;
486 when FEL => Frontend_Layout_On_Target := Result;
487 when FFO => Fractional_Fixed_Ops_On_Target := Result;
488 when MOV => Machine_Overflows_On_Target := Result;
489 when MRN => Machine_Rounds_On_Target := Result;
490 when S64 => Support_64_Bit_Divides_On_Target := Result;
491 when SAG => Support_Aggregates_On_Target := Result;
492 when SCA => Support_Composite_Assign_On_Target := Result;
493 when SCC => Support_Composite_Compare_On_Target := Result;
494 when SCD => Stack_Check_Default_On_Target := Result;
495 when SCP => Stack_Check_Probes_On_Target := Result;
496 when SLS => Support_Long_Shifts_On_Target := Result;
497 when SSL => Suppress_Standard_Library_On_Target := Result;
498 when SNZ => Signed_Zeros_On_Target := Result;
499 when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
500 when VMS => OpenVMS_On_Target := Result;
501 when ZCD => ZCX_By_Default_On_Target := Result;
502 when ZCG => GCC_ZCX_Support_On_Target := Result;
503 when ZCF => Front_End_ZCX_Support_On_Target := Result;
510 goto Line_Loop_Continue;
513 end loop Config_Param_Loop;
516 -- Here after processing one line of System spec
518 <<Line_Loop_Continue>>
520 while System_Text (P) /= CR and then System_Text (P) /= LF loop
522 exit when P >= Source_Last;
525 while System_Text (P) = CR or else System_Text (P) = LF loop
527 exit when P >= Source_Last;
530 if P >= Source_Last then
532 Write_Line ("fatal error, system.ads not formatted correctly");
533 Write_Line ("unexpected end of file");
535 raise Unrecoverable_Error;
539 -- Check no missing target parameter settings
541 for K in Targparm_Tags_OK loop
542 if not Targparm_Flags (K) then
545 ("fatal error: system.ads is incorrectly formatted");
546 Write_Str ("missing line for parameter: ");
548 for J in Targparm_Str (K)'Range loop
549 Write_Char (Targparm_Str (K).all (J));
559 raise Unrecoverable_Error;
561 end Get_Target_Parameters;