summaryrefslogtreecommitdiff
path: root/gcc/ada/targparm.adb
blob: 9e823d89971180c6dd06c680b91e8efa65e0d774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
------------------------------------------------------------------------------
--                                                                          --
--                        GNAT RUN-TIME COMPONENTS                          --
--                                                                          --
--                             T A R G P A R M                              --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--                            $Revision: 1.15 $
--                                                                          --
--          Copyright (C) 1999-2001 Free Software Foundation, Inc.          --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License  distributed with GNAT;  see file COPYING.  If not, write --
-- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
-- MA 02111-1307, USA.                                                      --
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
-- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
--                                                                          --
------------------------------------------------------------------------------

with Namet;    use Namet;
with Output;   use Output;
with Sinput;   use Sinput;
with Sinput.L; use Sinput.L;
with Fname.UF; use Fname.UF;
with Types;    use Types;

package body Targparm is

   type Targparm_Tags is
     (AAM, CLA, DEN, DSP, FEL, HIM, LSI, MOV,
      MRN, SCD, SCP, SNZ, UAM, VMS, ZCD, ZCG, ZCF);

   Targparm_Flags : array (Targparm_Tags) of Boolean := (others => False);
   --  Flag is set True if corresponding parameter is scanned

   AAM_Str : aliased constant Source_Buffer := "AAMP";
   CLA_Str : aliased constant Source_Buffer := "Command_Line_Args";
   DEN_Str : aliased constant Source_Buffer := "Denorm";
   DSP_Str : aliased constant Source_Buffer := "Functions_Return_By_DSP";
   FEL_Str : aliased constant Source_Buffer := "Frontend_Layout";
   HIM_Str : aliased constant Source_Buffer := "High_Integrity_Mode";
   LSI_Str : aliased constant Source_Buffer := "Long_Shifts_Inlined";
   MOV_Str : aliased constant Source_Buffer := "Machine_Overflows";
   MRN_Str : aliased constant Source_Buffer := "Machine_Rounds";
   SCD_Str : aliased constant Source_Buffer := "Stack_Check_Default";
   SCP_Str : aliased constant Source_Buffer := "Stack_Check_Probes";
   SNZ_Str : aliased constant Source_Buffer := "Signed_Zeros";
   UAM_Str : aliased constant Source_Buffer := "Use_Ada_Main_Program_Name";
   VMS_Str : aliased constant Source_Buffer := "OpenVMS";
   ZCD_Str : aliased constant Source_Buffer := "ZCX_By_Default";
   ZCG_Str : aliased constant Source_Buffer := "GCC_ZCX_Support";
   ZCF_Str : aliased constant Source_Buffer := "Front_End_ZCX_Support";

   type Buffer_Ptr is access constant Source_Buffer;
   Targparm_Str : array (Targparm_Tags) of Buffer_Ptr :=
     (AAM_Str'Access,
      CLA_Str'Access,
      DEN_Str'Access,
      DSP_Str'Access,
      FEL_Str'Access,
      HIM_Str'Access,
      LSI_Str'Access,
      MOV_Str'Access,
      MRN_Str'Access,
      SCD_Str'Access,
      SCP_Str'Access,
      SNZ_Str'Access,
      UAM_Str'Access,
      VMS_Str'Access,
      ZCD_Str'Access,
      ZCG_Str'Access,
      ZCF_Str'Access);

   ---------------------------
   -- Get_Target_Parameters --
   ---------------------------

   procedure Get_Target_Parameters is
      use ASCII;

      S : Source_File_Index;
      N : Name_Id;
      T : Source_Buffer_Ptr;
      P : Source_Ptr;
      Z : Source_Ptr;

      Fatal : Boolean := False;
      --  Set True if a fatal error is detected

      Result : Boolean;
      --  Records boolean from system line

   begin
      Name_Buffer (1 .. 6) := "system";
      Name_Len := 6;
      N := File_Name_Of_Spec (Name_Find);
      S := Load_Source_File (N);

      if S = No_Source_File then
         Write_Line ("fatal error, run-time library not installed correctly");
         Write_Str ("cannot locate file ");
         Write_Line (Name_Buffer (1 .. Name_Len));
         raise Unrecoverable_Error;

      --  This must always be the first source file read, and we have defined
      --  a constant Types.System_Source_File_Index as 1 to reflect this.

      else
         pragma Assert (S = System_Source_File_Index);
         null;
      end if;

      P := Source_First (S);
      Z := Source_Last  (S);
      T := Source_Text  (S);

      while T (P .. P + 10) /= "end System;" loop

         for K in Targparm_Tags loop
            if T (P + 3 .. P + 2 + Targparm_Str (K)'Length) =
                                                   Targparm_Str (K).all
            then
               P := P + 3 + Targparm_Str (K)'Length;

               if Targparm_Flags (K) then
                  Set_Standard_Error;
                  Write_Line
                    ("fatal error: system.ads is incorrectly formatted");
                  Write_Str ("duplicate line for parameter: ");

                  for J in Targparm_Str (K)'Range loop
                     Write_Char (Targparm_Str (K).all (J));
                  end loop;

                  Write_Eol;
                  Set_Standard_Output;
                  Fatal := True;

               else
                  Targparm_Flags (K) := True;
               end if;

               while T (P) /= ':' or else T (P + 1) /= '=' loop
                  P := P + 1;
               end loop;

               P := P + 2;

               while T (P) = ' ' loop
                  P := P + 1;
               end loop;

               Result := (T (P) = 'T');

               case K is
                  when AAM => AAMP_On_Target                      := Result;
                  when CLA => Command_Line_Args_On_Target         := Result;
                  when DEN => Denorm_On_Target                    := Result;
                  when DSP => Functions_Return_By_DSP_On_Target   := Result;
                  when FEL => Frontend_Layout_On_Target           := Result;
                  when HIM => High_Integrity_Mode_On_Target       := Result;
                  when LSI => Long_Shifts_Inlined_On_Target       := Result;
                  when MOV => Machine_Overflows_On_Target         := Result;
                  when MRN => Machine_Rounds_On_Target            := Result;
                  when SCD => Stack_Check_Default_On_Target       := Result;
                  when SCP => Stack_Check_Probes_On_Target        := Result;
                  when SNZ => Signed_Zeros_On_Target              := Result;
                  when UAM => Use_Ada_Main_Program_Name_On_Target := Result;
                  when VMS => OpenVMS_On_Target                   := Result;
                  when ZCD => ZCX_By_Default_On_Target            := Result;
                  when ZCG => GCC_ZCX_Support_On_Target           := Result;
                  when ZCF => Front_End_ZCX_Support_On_Target     := Result;
               end case;

               exit;
            end if;
         end loop;

         while T (P) /= CR and then T (P) /= LF loop
            P := P + 1;
            exit when P >= Z;
         end loop;

         while T (P) = CR or else T (P) = LF loop
            P := P + 1;
            exit when P >= Z;
         end loop;

         if P >= Z then
            Set_Standard_Error;
            Write_Line ("fatal error, system.ads not formatted correctly");
            Set_Standard_Output;
            raise Unrecoverable_Error;
         end if;
      end loop;

      for K in Targparm_Tags loop
         if not Targparm_Flags (K) then
            Set_Standard_Error;
            Write_Line
              ("fatal error: system.ads is incorrectly formatted");
            Write_Str ("missing line for parameter: ");

            for J in Targparm_Str (K)'Range loop
               Write_Char (Targparm_Str (K).all (J));
            end loop;

            Write_Eol;
            Set_Standard_Output;
            Fatal := True;
         end if;
      end loop;

      if Fatal then
         raise Unrecoverable_Error;
      end if;
   end Get_Target_Parameters;

end Targparm;