1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
30 with Namet; use Namet;
32 with Tree_IO; use Tree_IO;
34 package body Osint.C is
36 Output_Object_File_Name : String_Ptr;
37 -- Argument of -o compiler option, if given. This is needed to
38 -- verify consistency with the ALI file name.
40 procedure Adjust_OS_Resource_Limits;
41 pragma Import (C, Adjust_OS_Resource_Limits,
42 "__gnat_adjust_os_resource_limits");
43 -- Procedure to make system specific adjustments to make GNAT
46 function Create_Auxiliary_File
47 (Src : File_Name_Type;
49 return File_Name_Type;
50 -- Common processing for Creat_Repinfo_File and Create_Debug_File.
51 -- Src is the file name used to create the required output file and
52 -- Suffix is the desired suffic (dg/rep for debug/repinfo file).
54 procedure Set_Library_Info_Name;
55 -- Sets a default ali file name from the main compiler source name.
56 -- This is used by Create_Output_Library_Info, and by the version of
57 -- Read_Library_Info that takes a default file name.
59 ----------------------
60 -- Close_Debug_File --
61 ----------------------
63 procedure Close_Debug_File is
68 -------------------------------
69 -- Close_Output_Library_Info --
70 -------------------------------
72 procedure Close_Output_Library_Info is
75 end Close_Output_Library_Info;
77 ------------------------
78 -- Close_Repinfo_File --
79 ------------------------
81 procedure Close_Repinfo_File is
84 end Close_Repinfo_File;
86 ---------------------------
87 -- Create_Auxiliary_File --
88 ---------------------------
90 function Create_Auxiliary_File
91 (Src : File_Name_Type;
95 Result : File_Name_Type;
98 Get_Name_String (Src);
100 if Hostparm.OpenVMS then
101 Name_Buffer (Name_Len + 1) := '_';
103 Name_Buffer (Name_Len + 1) := '.';
106 Name_Len := Name_Len + 1;
107 Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix;
108 Name_Len := Name_Len + Suffix'Length;
110 if Output_Object_File_Name /= null then
112 for Index in reverse Output_Object_File_Name'Range loop
114 if Output_Object_File_Name (Index) = Directory_Separator then
116 File_Name : constant String := Name_Buffer (1 .. Name_Len);
119 Name_Len := Index - Output_Object_File_Name'First + 1;
120 Name_Buffer (1 .. Name_Len) :=
121 Output_Object_File_Name
122 (Output_Object_File_Name'First .. Index);
123 Name_Buffer (Name_Len + 1 .. Name_Len + File_Name'Length) :=
125 Name_Len := Name_Len + File_Name'Length;
134 Name_Buffer (Name_Len + 1) := ASCII.NUL;
135 Create_File_And_Check (Output_FD, Text);
137 end Create_Auxiliary_File;
139 -----------------------
140 -- Create_Debug_File --
141 -----------------------
143 function Create_Debug_File (Src : File_Name_Type) return File_Name_Type is
145 return Create_Auxiliary_File (Src, "dg");
146 end Create_Debug_File;
148 --------------------------------
149 -- Create_Output_Library_Info --
150 --------------------------------
152 procedure Create_Output_Library_Info is
154 Set_Library_Info_Name;
155 Create_File_And_Check (Output_FD, Text);
156 end Create_Output_Library_Info;
158 --------------------------
159 -- Creat_Repinfo_File --
160 --------------------------
162 procedure Creat_Repinfo_File (Src : File_Name_Type) is
163 S : constant File_Name_Type := Create_Auxiliary_File (Src, "rep");
164 pragma Warnings (Off, S);
168 end Creat_Repinfo_File;
170 ---------------------------
171 -- Debug_File_Eol_Length --
172 ---------------------------
174 function Debug_File_Eol_Length return Nat is
176 -- There has to be a cleaner way to do this! ???
178 if Directory_Separator = '/' then
183 end Debug_File_Eol_Length;
185 -----------------------
186 -- More_Source_Files --
187 -----------------------
189 function More_Source_Files return Boolean renames More_Files;
191 ----------------------
192 -- Next_Main_Source --
193 ----------------------
195 function Next_Main_Source return File_Name_Type renames Next_Main_File;
197 -----------------------
198 -- Read_Library_Info --
199 -----------------------
201 -- Version with default file name
203 procedure Read_Library_Info
204 (Name : out File_Name_Type;
205 Text : out Text_Buffer_Ptr)
208 Set_Library_Info_Name;
210 Text := Read_Library_Info (Name, Fatal_Err => False);
211 end Read_Library_Info;
213 ---------------------------
214 -- Set_Library_Info_Name --
215 ---------------------------
217 procedure Set_Library_Info_Name is
221 Get_Name_String (Current_Main);
223 -- Find last dot since we replace the existing extension by .ali. The
224 -- initialization to Name_Len + 1 provides for simply adding the .ali
225 -- extension if the source file name has no extension.
227 Dot_Index := Name_Len + 1;
229 for J in reverse 1 .. Name_Len loop
230 if Name_Buffer (J) = '.' then
236 -- Make sure that the output file name matches the source file name.
237 -- To compare them, remove file name directories and extensions.
239 if Output_Object_File_Name /= null then
240 -- Make sure there is a dot at Dot_Index. This may not be the case
241 -- if the source file name has no extension.
243 Name_Buffer (Dot_Index) := '.';
246 Name : constant String := Name_Buffer (1 .. Dot_Index);
247 Len : constant Natural := Dot_Index;
250 Name_Buffer (1 .. Output_Object_File_Name'Length)
251 := Output_Object_File_Name.all;
254 for J in reverse Output_Object_File_Name'Range loop
255 if Name_Buffer (J) = '.' then
261 pragma Assert (Dot_Index /= 0);
262 -- We check for the extension elsewhere
264 if Name /= Name_Buffer (Dot_Index - Len + 1 .. Dot_Index) then
265 Fail ("incorrect object file name");
270 Name_Buffer (Dot_Index) := '.';
271 Name_Buffer (Dot_Index + 1 .. Dot_Index + 3) := ALI_Suffix.all;
272 Name_Buffer (Dot_Index + 4) := ASCII.NUL;
273 Name_Len := Dot_Index + 3;
274 end Set_Library_Info_Name;
276 ---------------------------------
277 -- Set_Output_Object_File_Name --
278 ---------------------------------
280 procedure Set_Output_Object_File_Name (Name : String) is
281 Ext : constant String := Object_Suffix;
282 NL : constant Natural := Name'Length;
283 EL : constant Natural := Ext'Length;
286 -- Make sure that the object file has the expected extension.
290 (Name (NL - EL + Name'First .. Name'Last) /= Ext
291 and then Name (NL - 2 + Name'First .. Name'Last) /= ".o")
293 Fail ("incorrect object file extension");
296 Output_Object_File_Name := new String'(Name);
297 end Set_Output_Object_File_Name;
303 procedure Tree_Close is
305 Tree_Write_Terminate;
313 procedure Tree_Create is
317 Get_Name_String (Current_Main);
319 -- If an object file has been specified, then the ALI file
320 -- will be in the same directory as the object file;
321 -- so, we put the tree file in this same directory,
322 -- even though no object file needs to be generated.
324 if Output_Object_File_Name /= null then
325 Name_Len := Output_Object_File_Name'Length;
326 Name_Buffer (1 .. Name_Len) := Output_Object_File_Name.all;
330 for J in reverse 1 .. Name_Len loop
331 if Name_Buffer (J) = '.' then
337 -- Should be impossible to not have an extension
339 pragma Assert (Dot_Index /= 0);
341 -- Change exctension to adt
343 Name_Buffer (Dot_Index + 1) := 'a';
344 Name_Buffer (Dot_Index + 2) := 'd';
345 Name_Buffer (Dot_Index + 3) := 't';
346 Name_Buffer (Dot_Index + 4) := ASCII.NUL;
347 Name_Len := Dot_Index + 3;
348 Create_File_And_Check (Output_FD, Binary);
350 Tree_Write_Initialize (Output_FD);
353 -----------------------
354 -- Write_Debug_Info --
355 -----------------------
357 procedure Write_Debug_Info (Info : String) renames Write_Info;
359 ------------------------
360 -- Write_Library_Info --
361 ------------------------
363 procedure Write_Library_Info (Info : String) renames Write_Info;
365 ------------------------
366 -- Write_Repinfo_Line --
367 ------------------------
369 procedure Write_Repinfo_Line (Info : String) renames Write_Info;
373 Adjust_OS_Resource_Limits;
374 Opt.Creat_Repinfo_File_Access := Creat_Repinfo_File'Access;
375 Opt.Write_Repinfo_Line_Access := Write_Repinfo_Line'Access;
376 Opt.Close_Repinfo_File_Access := Close_Repinfo_File'Access;
378 Set_Program (Compiler);