OSDN Git Service

* config/vax/vax.h (target_flags, MASK_UNIX_ASM, MASK_VAXC_ALIGNMENT)
[pf3gnuchains/gcc-fork.git] / gcc / ada / targparm.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                        GNAT RUN-TIME COMPONENTS                          --
4 --                                                                          --
5 --                             T A R G P A R M                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1999-2005 Free Software Foundation, Inc.          --
10 --                                                                          --
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.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Csets;  use Csets;
28 with Namet;  use Namet;
29 with Opt;    use Opt;
30 with Osint;  use Osint;
31 with Output; use Output;
32
33 package body Targparm is
34    use ASCII;
35
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.
39
40    --  The following array defines a tag name for each entry
41
42    type Targparm_Tags is
43      (AAM,  --   AAMP
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
50       DEN,  --   Denorm
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
65       SNZ,  --   Signed_Zeros
66       SSL,  --   Suppress_Standard_Library
67       UAM,  --   Use_Ada_Main_Program_Name
68       VMS,  --   OpenVMS
69       ZCD,  --   ZCX_By_Default
70       ZCG,  --   GCC_ZCX_Support
71       ZCF); --   Front_End_ZCX_Support
72
73    subtype Targparm_Tags_OK is Targparm_Tags range AAM .. ZCF;
74    --  Range excluding obsolete entries
75
76    Targparm_Flags : array (Targparm_Tags) of Boolean := (others => False);
77    --  Flag is set True if corresponding parameter is scanned
78
79    --  The following list of string constants gives the parameter names
80
81    AAM_Str : aliased constant Source_Buffer := "AAMP";
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    CRT_Str : aliased constant Source_Buffer := "Configurable_Run_Time";
86    CSV_Str : aliased constant Source_Buffer := "Compiler_System_Version";
87    D32_Str : aliased constant Source_Buffer := "Duration_32_Bits";
88    DEN_Str : aliased constant Source_Buffer := "Denorm";
89    DSP_Str : aliased constant Source_Buffer := "Functions_Return_By_DSP";
90    EXS_Str : aliased constant Source_Buffer := "Exit_Status_Supported";
91    FEL_Str : aliased constant Source_Buffer := "Frontend_Layout";
92    FFO_Str : aliased constant Source_Buffer := "Fractional_Fixed_Ops";
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    S64_Str : aliased constant Source_Buffer := "Support_64_Bit_Divides";
97    SAG_Str : aliased constant Source_Buffer := "Support_Aggregates";
98    SCA_Str : aliased constant Source_Buffer := "Support_Composite_Assign";
99    SCC_Str : aliased constant Source_Buffer := "Support_Composite_Compare";
100    SCD_Str : aliased constant Source_Buffer := "Stack_Check_Default";
101    SCP_Str : aliased constant Source_Buffer := "Stack_Check_Probes";
102    SLS_Str : aliased constant Source_Buffer := "Support_Long_Shifts";
103    SNZ_Str : aliased constant Source_Buffer := "Signed_Zeros";
104    SSL_Str : aliased constant Source_Buffer := "Suppress_Standard_Library";
105    UAM_Str : aliased constant Source_Buffer := "Use_Ada_Main_Program_Name";
106    VMS_Str : aliased constant Source_Buffer := "OpenVMS";
107    ZCD_Str : aliased constant Source_Buffer := "ZCX_By_Default";
108    ZCG_Str : aliased constant Source_Buffer := "GCC_ZCX_Support";
109    ZCF_Str : aliased constant Source_Buffer := "Front_End_ZCX_Support";
110
111    --  The following defines a set of pointers to the above strings,
112    --  indexed by the tag values.
113
114    type Buffer_Ptr is access constant Source_Buffer;
115    Targparm_Str : constant array (Targparm_Tags) of Buffer_Ptr :=
116      (AAM_Str'Access,
117       BDC_Str'Access,
118       BOC_Str'Access,
119       CLA_Str'Access,
120       CRT_Str'Access,
121       CSV_Str'Access,
122       D32_Str'Access,
123       DEN_Str'Access,
124       DSP_Str'Access,
125       EXS_Str'Access,
126       FEL_Str'Access,
127       FFO_Str'Access,
128       MOV_Str'Access,
129       MRN_Str'Access,
130       PAS_Str'Access,
131       S64_Str'Access,
132       SAG_Str'Access,
133       SCA_Str'Access,
134       SCC_Str'Access,
135       SCD_Str'Access,
136       SCP_Str'Access,
137       SLS_Str'Access,
138       SNZ_Str'Access,
139       SSL_Str'Access,
140       UAM_Str'Access,
141       VMS_Str'Access,
142       ZCD_Str'Access,
143       ZCG_Str'Access,
144       ZCF_Str'Access);
145
146    -----------------------
147    -- Local Subprograms --
148    -----------------------
149
150    procedure Set_Profile_Restrictions (P : Profile_Name);
151    --  Set Restrictions_On_Target for the given profile
152
153    ------------------------------
154    -- Set_Profile_Restrictions --
155    ------------------------------
156
157    procedure Set_Profile_Restrictions (P : Profile_Name) is
158       R : Restriction_Flags  renames Profile_Info (P).Set;
159       V : Restriction_Values renames Profile_Info (P).Value;
160
161    begin
162       for J in R'Range loop
163          if R (J) then
164             Restrictions_On_Target.Set (J) := True;
165
166             if J in All_Parameter_Restrictions then
167                Restrictions_On_Target.Value (J) := V (J);
168             end if;
169          end if;
170       end loop;
171    end Set_Profile_Restrictions;
172
173    ---------------------------
174    -- Get_Target_Parameters --
175    ---------------------------
176
177    --  Version which reads in system.ads
178
179    procedure Get_Target_Parameters is
180       Text : Source_Buffer_Ptr;
181       Hi   : Source_Ptr;
182
183    begin
184       if Parameters_Obtained then
185          return;
186       end if;
187
188       Name_Buffer (1 .. 10) := "system.ads";
189       Name_Len := 10;
190
191       Read_Source_File (Name_Find, Lo => 0, Hi => Hi, Src => Text);
192
193       if Text = null then
194          Write_Line ("fatal error, run-time library not installed correctly");
195          Write_Line ("cannot locate file system.ads");
196          raise Unrecoverable_Error;
197       end if;
198
199       Targparm.Get_Target_Parameters
200         (System_Text  => Text,
201          Source_First => 0,
202          Source_Last  => Hi);
203    end Get_Target_Parameters;
204
205    --  Version where caller supplies system.ads text
206
207    procedure Get_Target_Parameters
208      (System_Text  : Source_Buffer_Ptr;
209       Source_First : Source_Ptr;
210       Source_Last  : Source_Ptr)
211    is
212       P : Source_Ptr;
213       --  Scans source buffer containing source of system.ads
214
215       Fatal : Boolean := False;
216       --  Set True if a fatal error is detected
217
218       Result : Boolean;
219       --  Records boolean from system line
220
221    begin
222       if Parameters_Obtained then
223          return;
224       else
225          Parameters_Obtained := True;
226       end if;
227
228       Opt.Address_Is_Private := False;
229
230       P := Source_First;
231       Line_Loop : while System_Text (P .. P + 10) /= "end System;" loop
232
233          --  Skip comments quickly
234
235          if System_Text (P) = '-' then
236             goto Line_Loop_Continue;
237
238          --  Test for type Address is private
239
240          elsif System_Text (P .. P + 26) = "   type Address is private;" then
241             Opt.Address_Is_Private := True;
242             P := P + 26;
243             goto Line_Loop_Continue;
244
245          --  Test for pragma Profile (Ravenscar);
246
247          elsif System_Text (P .. P + 26) =
248                  "pragma Profile (Ravenscar);"
249          then
250             Set_Profile_Restrictions (Ravenscar);
251             Opt.Task_Dispatching_Policy := 'F';
252             Opt.Locking_Policy          := 'C';
253             P := P + 27;
254             goto Line_Loop_Continue;
255
256          --  Test for pragma Profile (Restricted);
257
258          elsif System_Text (P .. P + 27) =
259                  "pragma Profile (Restricted);"
260          then
261             Set_Profile_Restrictions (Restricted);
262             P := P + 28;
263             goto Line_Loop_Continue;
264
265          --  Test for pragma Restrictions
266
267          elsif System_Text (P .. P + 20) = "pragma Restrictions (" then
268             P := P + 21;
269
270             Rloop : for K in All_Boolean_Restrictions loop
271                declare
272                   Rname : constant String := Restriction_Id'Image (K);
273
274                begin
275                   for J in Rname'Range loop
276                      if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
277                                                         /= Rname (J)
278                      then
279                         goto Rloop_Continue;
280                      end if;
281                   end loop;
282
283                   if System_Text (P + Rname'Length) = ')' then
284                      Restrictions_On_Target.Set (K) := True;
285                      goto Line_Loop_Continue;
286                   end if;
287                end;
288
289             <<Rloop_Continue>>
290                null;
291             end loop Rloop;
292
293             Ploop : for K in All_Parameter_Restrictions loop
294                declare
295                   Rname : constant String :=
296                             All_Parameter_Restrictions'Image (K);
297
298                   V : Natural;
299                   --  Accumulates value
300
301                begin
302                   for J in Rname'Range loop
303                      if Fold_Upper (System_Text (P + Source_Ptr (J - 1)))
304                                                         /= Rname (J)
305                      then
306                         goto Ploop_Continue;
307                      end if;
308                   end loop;
309
310                   if System_Text (P + Rname'Length .. P + Rname'Length + 3) =
311                                                       " => "
312                   then
313                      P := P + Rname'Length + 4;
314
315                      V := 0;
316                      loop
317                         if System_Text (P) in '0' .. '9' then
318                            declare
319                               pragma Unsuppress (Overflow_Check);
320
321                            begin
322                               --  Accumulate next digit
323
324                               V := 10 * V +
325                                    Character'Pos (System_Text (P)) -
326                                    Character'Pos ('0');
327
328                            exception
329                               --  On overflow, we just ignore the pragma since
330                               --  that is the standard handling in this case.
331
332                               when Constraint_Error =>
333                                  goto Line_Loop_Continue;
334                            end;
335
336                         elsif System_Text (P) = '_' then
337                            null;
338
339                         elsif System_Text (P) = ')' then
340                            Restrictions_On_Target.Value (K) := V;
341                            Restrictions_On_Target.Set (K) := True;
342                            goto Line_Loop_Continue;
343
344                         else
345                            exit Ploop;
346                         end if;
347
348                         P := P + 1;
349                      end loop;
350
351                   else
352                      exit Ploop;
353                   end if;
354                end;
355
356             <<Ploop_Continue>>
357                null;
358             end loop Ploop;
359
360             Set_Standard_Error;
361             Write_Line
362                ("fatal error: system.ads is incorrectly formatted");
363             Write_Str ("unrecognized or incorrect restrictions pragma: ");
364
365             while System_Text (P) /= ')'
366                     and then
367                   System_Text (P) /= ASCII.LF
368             loop
369                Write_Char (System_Text (P));
370                P := P + 1;
371             end loop;
372
373             Write_Eol;
374             Fatal := True;
375             Set_Standard_Output;
376
377          --  Test for pragma Detect_Blocking;
378
379          elsif System_Text (P .. P + 22) = "pragma Detect_Blocking;" then
380             P := P + 23;
381             Opt.Detect_Blocking := True;
382             goto Line_Loop_Continue;
383
384          --  Discard_Names
385
386          elsif System_Text (P .. P + 20) = "pragma Discard_Names;" then
387             P := P + 21;
388             Opt.Global_Discard_Names := True;
389             goto Line_Loop_Continue;
390
391          --  Locking Policy
392
393          elsif System_Text (P .. P + 22) = "pragma Locking_Policy (" then
394             P := P + 23;
395             Opt.Locking_Policy := System_Text (P);
396             Opt.Locking_Policy_Sloc := System_Location;
397             goto Line_Loop_Continue;
398
399          --  Normalize_Scalars
400
401          elsif System_Text (P .. P + 24) = "pragma Normalize_Scalars;" then
402             P := P + 25;
403             Opt.Normalize_Scalars := True;
404             Opt.Init_Or_Norm_Scalars := True;
405             goto Line_Loop_Continue;
406
407          --  Polling (On)
408
409          elsif System_Text (P .. P + 19) = "pragma Polling (On);" then
410             P := P + 20;
411             Opt.Polling_Required := True;
412             goto Line_Loop_Continue;
413
414          --  Ignore pragma Pure (System)
415
416          elsif System_Text (P .. P + 20) = "pragma Pure (System);" then
417             P := P + 21;
418             goto Line_Loop_Continue;
419
420          --  Queuing Policy
421
422          elsif System_Text (P .. P + 22) = "pragma Queuing_Policy (" then
423             P := P + 23;
424             Opt.Queuing_Policy := System_Text (P);
425             Opt.Queuing_Policy_Sloc := System_Location;
426             goto Line_Loop_Continue;
427
428          --  Suppress_Exception_Locations
429
430          elsif System_Text (P .. P + 34) =
431                                 "pragma Suppress_Exception_Locations;"
432          then
433             P := P + 35;
434             Opt.Exception_Locations_Suppressed := True;
435             goto Line_Loop_Continue;
436
437          --  Task_Dispatching Policy
438
439          elsif System_Text (P .. P + 31) =
440                                    "pragma Task_Dispatching_Policy ("
441          then
442             P := P + 32;
443             Opt.Task_Dispatching_Policy := System_Text (P);
444             Opt.Task_Dispatching_Policy_Sloc := System_Location;
445             goto Line_Loop_Continue;
446
447          --  No other pragmas are permitted
448
449          elsif System_Text (P .. P + 6) = "pragma " then
450             Set_Standard_Error;
451             Write_Line ("unrecognized line in system.ads: ");
452
453             while System_Text (P) /= ')'
454               and then System_Text (P) /= ASCII.LF
455             loop
456                Write_Char (System_Text (P));
457                P := P + 1;
458             end loop;
459
460             Write_Eol;
461             Set_Standard_Output;
462             Fatal := True;
463
464          --  See if we have a Run_Time_Name
465
466          elsif System_Text (P .. P + 38) =
467                   "   Run_Time_Name : constant String := """
468          then
469             P := P + 39;
470
471             Name_Len := 0;
472             while System_Text (P) in 'A' .. 'Z'
473                     or else
474                   System_Text (P) in 'a' .. 'z'
475                     or else
476                   System_Text (P) in '0' .. '9'
477                     or else
478                   System_Text (P) = ' '
479                     or else
480                   System_Text (P) = '_'
481             loop
482                Add_Char_To_Name_Buffer (System_Text (P));
483                P := P + 1;
484             end loop;
485
486             if System_Text (P) /= '"'
487               or else System_Text (P + 1) /= ';'
488               or else (System_Text (P + 2) /= ASCII.LF
489                          and then
490                        System_Text (P + 2) /= ASCII.CR)
491             then
492                Set_Standard_Error;
493                Write_Line
494                  ("incorrectly formatted Run_Time_Name in system.ads");
495                Set_Standard_Output;
496                Fatal := True;
497
498             else
499                Run_Time_Name_On_Target := Name_Enter;
500             end if;
501
502             goto Line_Loop_Continue;
503
504          --  Next See if we have a configuration parameter
505
506          else
507             Config_Param_Loop : for K in Targparm_Tags loop
508                if System_Text (P + 3 .. P + 2 + Targparm_Str (K)'Length) =
509                                                       Targparm_Str (K).all
510                then
511                   P := P + 3 + Targparm_Str (K)'Length;
512
513                   if Targparm_Flags (K) then
514                      Set_Standard_Error;
515                      Write_Line
516                        ("fatal error: system.ads is incorrectly formatted");
517                      Write_Str ("duplicate line for parameter: ");
518
519                      for J in Targparm_Str (K)'Range loop
520                         Write_Char (Targparm_Str (K).all (J));
521                      end loop;
522
523                      Write_Eol;
524                      Set_Standard_Output;
525                      Fatal := True;
526
527                   else
528                      Targparm_Flags (K) := True;
529                   end if;
530
531                   while System_Text (P) /= ':'
532                      or else System_Text (P + 1) /= '='
533                   loop
534                      P := P + 1;
535                   end loop;
536
537                   P := P + 2;
538
539                   while System_Text (P) = ' ' loop
540                      P := P + 1;
541                   end loop;
542
543                   Result := (System_Text (P) = 'T');
544
545                   case K is
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;
550                      when CRT => Configurable_Run_Time_On_Target     := Result;
551                      when CSV => Compiler_System_Version             := Result;
552                      when D32 => Duration_32_Bits_On_Target          := Result;
553                      when DEN => Denorm_On_Target                    := Result;
554                      when DSP => Functions_Return_By_DSP_On_Target   := Result;
555                      when EXS => Exit_Status_Supported_On_Target     := Result;
556                      when FEL => Frontend_Layout_On_Target           := Result;
557                      when FFO => Fractional_Fixed_Ops_On_Target      := Result;
558                      when MOV => Machine_Overflows_On_Target         := Result;
559                      when MRN => Machine_Rounds_On_Target            := Result;
560                      when PAS => Preallocated_Stacks_On_Target       := Result;
561                      when S64 => Support_64_Bit_Divides_On_Target    := Result;
562                      when SAG => Support_Aggregates_On_Target        := Result;
563                      when SCA => Support_Composite_Assign_On_Target  := Result;
564                      when SCC => Support_Composite_Compare_On_Target := Result;
565                      when SCD => Stack_Check_Default_On_Target       := Result;
566                      when SCP => Stack_Check_Probes_On_Target        := Result;
567                      when SLS => Support_Long_Shifts_On_Target       := Result;
568                      when SSL => Suppress_Standard_Library_On_Target := Result;
569                      when SNZ => Signed_Zeros_On_Target              := Result;
570                      when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
571                      when VMS => OpenVMS_On_Target                   := Result;
572                      when ZCD => ZCX_By_Default_On_Target            := Result;
573                      when ZCG => GCC_ZCX_Support_On_Target           := Result;
574                      when ZCF => Front_End_ZCX_Support_On_Target     := Result;
575
576                      goto Line_Loop_Continue;
577                   end case;
578
579                   --  Here we are seeing a parameter we do not understand. We
580                   --  simply ignore this (will happen when an old compiler is
581                   --  used to compile a newer version of GNAT which does not
582                   --  support the
583                end if;
584             end loop Config_Param_Loop;
585          end if;
586
587          --  Here after processing one line of System spec
588
589          <<Line_Loop_Continue>>
590
591          while System_Text (P) /= CR and then System_Text (P) /= LF loop
592             P := P + 1;
593             exit when P >= Source_Last;
594          end loop;
595
596          while System_Text (P) = CR or else System_Text (P) = LF loop
597             P := P + 1;
598             exit when P >= Source_Last;
599          end loop;
600
601          if P >= Source_Last then
602             Set_Standard_Error;
603             Write_Line ("fatal error, system.ads not formatted correctly");
604             Write_Line ("unexpected end of file");
605             Set_Standard_Output;
606             raise Unrecoverable_Error;
607          end if;
608       end loop Line_Loop;
609
610       --  Check no missing target parameter settings (skip for compiler vsn)
611
612       if not Compiler_System_Version then
613          for K in Targparm_Tags_OK loop
614             if not Targparm_Flags (K) then
615                Set_Standard_Error;
616                Write_Line
617                  ("fatal error: system.ads is incorrectly formatted");
618                Write_Str ("missing line for parameter: ");
619
620                for J in Targparm_Str (K)'Range loop
621                   Write_Char (Targparm_Str (K).all (J));
622                end loop;
623
624                Write_Eol;
625                Set_Standard_Output;
626                Fatal := True;
627             end if;
628          end loop;
629       end if;
630
631
632       if Fatal then
633          raise Unrecoverable_Error;
634       end if;
635    end Get_Target_Parameters;
636
637 end Targparm;