1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2001 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 ------------------------------------------------------------------------------
29 with Namet
; use Namet
;
31 with Tree_IO
; use Tree_IO
;
33 package body Osint
.C
is
35 Output_Object_File_Name
: String_Ptr
;
36 -- Argument of -o compiler option, if given. This is needed to
37 -- verify consistency with the ALI file name.
39 procedure Adjust_OS_Resource_Limits
;
40 pragma Import
(C
, Adjust_OS_Resource_Limits
,
41 "__gnat_adjust_os_resource_limits");
42 -- Procedure to make system specific adjustments to make GNAT
45 function Create_Auxiliary_File
46 (Src
: File_Name_Type
;
48 return File_Name_Type
;
49 -- Common processing for Creat_Repinfo_File and Create_Debug_File.
50 -- Src is the file name used to create the required output file and
51 -- Suffix is the desired suffic (dg/rep for debug/repinfo file).
53 procedure Set_Library_Info_Name
;
54 -- Sets a default ali file name from the main compiler source name.
55 -- This is used by Create_Output_Library_Info, and by the version of
56 -- Read_Library_Info that takes a default file name.
58 ----------------------
59 -- Close_Debug_File --
60 ----------------------
62 procedure Close_Debug_File
is
67 -------------------------------
68 -- Close_Output_Library_Info --
69 -------------------------------
71 procedure Close_Output_Library_Info
is
74 end Close_Output_Library_Info
;
76 ------------------------
77 -- Close_Repinfo_File --
78 ------------------------
80 procedure Close_Repinfo_File
is
83 end Close_Repinfo_File
;
85 ---------------------------
86 -- Create_Auxiliary_File --
87 ---------------------------
89 function Create_Auxiliary_File
90 (Src
: File_Name_Type
;
94 Result
: File_Name_Type
;
97 Get_Name_String
(Src
);
99 if Hostparm
.OpenVMS
then
100 Name_Buffer
(Name_Len
+ 1) := '_';
102 Name_Buffer
(Name_Len
+ 1) := '.';
105 Name_Len
:= Name_Len
+ 1;
106 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ Suffix
'Length) := Suffix
;
107 Name_Len
:= Name_Len
+ Suffix
'Length;
109 if Output_Object_File_Name
/= null then
111 for Index
in reverse Output_Object_File_Name
'Range loop
113 if Output_Object_File_Name
(Index
) = Directory_Separator
then
115 File_Name
: constant String := Name_Buffer
(1 .. Name_Len
);
118 Name_Len
:= Index
- Output_Object_File_Name
'First + 1;
119 Name_Buffer
(1 .. Name_Len
) :=
120 Output_Object_File_Name
121 (Output_Object_File_Name
'First .. Index
);
122 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ File_Name
'Length) :=
124 Name_Len
:= Name_Len
+ File_Name
'Length;
133 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
134 Create_File_And_Check
(Output_FD
, Text
);
136 end Create_Auxiliary_File
;
138 -----------------------
139 -- Create_Debug_File --
140 -----------------------
142 function Create_Debug_File
(Src
: File_Name_Type
) return File_Name_Type
is
144 return Create_Auxiliary_File
(Src
, "dg");
145 end Create_Debug_File
;
147 --------------------------------
148 -- Create_Output_Library_Info --
149 --------------------------------
151 procedure Create_Output_Library_Info
is
153 Set_Library_Info_Name
;
154 Create_File_And_Check
(Output_FD
, Text
);
155 end Create_Output_Library_Info
;
157 --------------------------
158 -- Creat_Repinfo_File --
159 --------------------------
161 procedure Creat_Repinfo_File
(Src
: File_Name_Type
) is
162 S
: constant File_Name_Type
:= Create_Auxiliary_File
(Src
, "rep");
163 pragma Warnings
(Off
, S
);
167 end Creat_Repinfo_File
;
169 ---------------------------
170 -- Debug_File_Eol_Length --
171 ---------------------------
173 function Debug_File_Eol_Length
return Nat
is
175 -- There has to be a cleaner way to do this! ???
177 if Directory_Separator
= '/' then
182 end Debug_File_Eol_Length
;
184 -----------------------
185 -- More_Source_Files --
186 -----------------------
188 function More_Source_Files
return Boolean renames More_Files
;
190 ----------------------
191 -- Next_Main_Source --
192 ----------------------
194 function Next_Main_Source
return File_Name_Type
renames Next_Main_File
;
196 -----------------------
197 -- Read_Library_Info --
198 -----------------------
200 -- Version with default file name
202 procedure Read_Library_Info
203 (Name
: out File_Name_Type
;
204 Text
: out Text_Buffer_Ptr
)
207 Set_Library_Info_Name
;
209 Text
:= Read_Library_Info
(Name
, Fatal_Err
=> False);
210 end Read_Library_Info
;
212 ---------------------------
213 -- Set_Library_Info_Name --
214 ---------------------------
216 procedure Set_Library_Info_Name
is
220 Get_Name_String
(Current_Main
);
222 -- Find last dot since we replace the existing extension by .ali. The
223 -- initialization to Name_Len + 1 provides for simply adding the .ali
224 -- extension if the source file name has no extension.
226 Dot_Index
:= Name_Len
+ 1;
228 for J
in reverse 1 .. Name_Len
loop
229 if Name_Buffer
(J
) = '.' then
235 -- Make sure that the output file name matches the source file name.
236 -- To compare them, remove file name directories and extensions.
238 if Output_Object_File_Name
/= null then
239 -- Make sure there is a dot at Dot_Index. This may not be the case
240 -- if the source file name has no extension.
242 Name_Buffer
(Dot_Index
) := '.';
245 Name
: constant String := Name_Buffer
(1 .. Dot_Index
);
246 Len
: constant Natural := Dot_Index
;
249 Name_Buffer
(1 .. Output_Object_File_Name
'Length)
250 := Output_Object_File_Name
.all;
253 for J
in reverse Output_Object_File_Name
'Range loop
254 if Name_Buffer
(J
) = '.' then
260 pragma Assert
(Dot_Index
/= 0);
261 -- We check for the extension elsewhere
263 if Name
/= Name_Buffer
(Dot_Index
- Len
+ 1 .. Dot_Index
) then
264 Fail
("incorrect object file name");
269 Name_Buffer
(Dot_Index
) := '.';
270 Name_Buffer
(Dot_Index
+ 1 .. Dot_Index
+ 3) := ALI_Suffix
.all;
271 Name_Buffer
(Dot_Index
+ 4) := ASCII
.NUL
;
272 Name_Len
:= Dot_Index
+ 3;
273 end Set_Library_Info_Name
;
275 ---------------------------------
276 -- Set_Output_Object_File_Name --
277 ---------------------------------
279 procedure Set_Output_Object_File_Name
(Name
: String) is
280 Ext
: constant String := Object_Suffix
;
281 NL
: constant Natural := Name
'Length;
282 EL
: constant Natural := Ext
'Length;
285 -- Make sure that the object file has the expected extension.
289 (Name
(NL
- EL
+ Name
'First .. Name
'Last) /= Ext
290 and then Name
(NL
- 2 + Name
'First .. Name
'Last) /= ".o")
292 Fail
("incorrect object file extension");
295 Output_Object_File_Name
:= new String'(Name);
296 end Set_Output_Object_File_Name;
302 procedure Tree_Close is
304 Tree_Write_Terminate;
312 procedure Tree_Create is
316 Get_Name_String (Current_Main);
318 -- If an object file has been specified, then the ALI file
319 -- will be in the same directory as the object file;
320 -- so, we put the tree file in this same directory,
321 -- even though no object file needs to be generated.
323 if Output_Object_File_Name /= null then
324 Name_Len := Output_Object_File_Name'Length;
325 Name_Buffer (1 .. Name_Len) := Output_Object_File_Name.all;
329 for J in reverse 1 .. Name_Len loop
330 if Name_Buffer (J) = '.' then
336 -- Should be impossible to not have an extension
338 pragma Assert (Dot_Index /= 0);
340 -- Change exctension to adt
342 Name_Buffer (Dot_Index + 1) := 'a
';
343 Name_Buffer (Dot_Index + 2) := 'd
';
344 Name_Buffer (Dot_Index + 3) := 't
';
345 Name_Buffer (Dot_Index + 4) := ASCII.NUL;
346 Name_Len := Dot_Index + 3;
347 Create_File_And_Check (Output_FD, Binary);
349 Tree_Write_Initialize (Output_FD);
352 -----------------------
353 -- Write_Debug_Info --
354 -----------------------
356 procedure Write_Debug_Info (Info : String) renames Write_Info;
358 ------------------------
359 -- Write_Library_Info --
360 ------------------------
362 procedure Write_Library_Info (Info : String) renames Write_Info;
364 ------------------------
365 -- Write_Repinfo_Line --
366 ------------------------
368 procedure Write_Repinfo_Line (Info : String) renames Write_Info;
372 Adjust_OS_Resource_Limits;
373 Opt.Creat_Repinfo_File_Access := Creat_Repinfo_File'Access;
374 Opt.Write_Repinfo_Line_Access := Write_Repinfo_Line'Access;
375 Opt.Close_Repinfo_File_Access := Close_Repinfo_File'Access;
377 Set_Program (Compiler);