1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2006, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 ------------------------------------------------------------------------------
28 with Namet
; use Namet
;
30 with Tree_IO
; use Tree_IO
;
32 package body Osint
.C
is
34 Output_Object_File_Name
: String_Ptr
;
35 -- Argument of -o compiler option, if given. This is needed to verify
36 -- consistency with the ALI file name.
38 procedure Adjust_OS_Resource_Limits
;
39 pragma Import
(C
, Adjust_OS_Resource_Limits
,
40 "__gnat_adjust_os_resource_limits");
41 -- Procedure to make system specific adjustments to make GNAT run better
43 function Create_Auxiliary_File
44 (Src
: File_Name_Type
;
45 Suffix
: String) return File_Name_Type
;
46 -- Common processing for Create_List_File, Create_Repinfo_File and
47 -- Create_Debug_File. Src is the file name used to create the required
48 -- output file and Suffix is the desired suffic (dg/rep/xxx for debug/
49 -- repinfo/list file where xxx is specified extension.
51 procedure Set_Library_Info_Name
;
52 -- Sets a default ali file name from the main compiler source name.
53 -- This is used by Create_Output_Library_Info, and by the version of
54 -- Read_Library_Info that takes a default file name. The name is in
55 -- Name_Buffer (with length in Name_Len) on return from the call
57 ----------------------
58 -- Close_Debug_File --
59 ----------------------
61 procedure Close_Debug_File
is
65 Close
(Output_FD
, Status
);
69 ("error while closing expanded source file ",
70 Get_Name_String
(Output_File_Name
));
78 procedure Close_List_File
is
82 Close
(Output_FD
, Status
);
86 ("error while closing list file ",
87 Get_Name_String
(Output_File_Name
));
91 -------------------------------
92 -- Close_Output_Library_Info --
93 -------------------------------
95 procedure Close_Output_Library_Info
is
99 Close
(Output_FD
, Status
);
103 ("error while closing ALI file ",
104 Get_Name_String
(Output_File_Name
));
106 end Close_Output_Library_Info
;
108 ------------------------
109 -- Close_Repinfo_File --
110 ------------------------
112 procedure Close_Repinfo_File
is
116 Close
(Output_FD
, Status
);
120 ("error while closing representation info file ",
121 Get_Name_String
(Output_File_Name
));
123 end Close_Repinfo_File
;
125 ---------------------------
126 -- Create_Auxiliary_File --
127 ---------------------------
129 function Create_Auxiliary_File
130 (Src
: File_Name_Type
;
131 Suffix
: String) return File_Name_Type
133 Result
: File_Name_Type
;
136 Get_Name_String
(Src
);
138 if Hostparm
.OpenVMS
then
139 Name_Buffer
(Name_Len
+ 1) := '_';
141 Name_Buffer
(Name_Len
+ 1) := '.';
144 Name_Len
:= Name_Len
+ 1;
145 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ Suffix
'Length) := Suffix
;
146 Name_Len
:= Name_Len
+ Suffix
'Length;
148 if Output_Object_File_Name
/= null then
149 for Index
in reverse Output_Object_File_Name
'Range loop
150 if Output_Object_File_Name
(Index
) = Directory_Separator
then
152 File_Name
: constant String := Name_Buffer
(1 .. Name_Len
);
154 Name_Len
:= Index
- Output_Object_File_Name
'First + 1;
155 Name_Buffer
(1 .. Name_Len
) :=
156 Output_Object_File_Name
157 (Output_Object_File_Name
'First .. Index
);
158 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ File_Name
'Length) :=
160 Name_Len
:= Name_Len
+ File_Name
'Length;
169 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
170 Create_File_And_Check
(Output_FD
, Text
);
172 end Create_Auxiliary_File
;
174 -----------------------
175 -- Create_Debug_File --
176 -----------------------
178 function Create_Debug_File
(Src
: File_Name_Type
) return File_Name_Type
is
180 return Create_Auxiliary_File
(Src
, "dg");
181 end Create_Debug_File
;
183 ----------------------
184 -- Create_List_File --
185 ----------------------
187 procedure Create_List_File
(S
: String) is
189 pragma Warnings
(Off
, F
);
191 if S
(S
'First) = '.' then
192 F
:= Create_Auxiliary_File
(Current_Main
, S
(S
'First + 1 .. S
'Last));
194 Name_Buffer
(1 .. S
'Length) := S
;
195 Name_Len
:= S
'Length + 1;
196 Name_Buffer
(Name_Len
) := ASCII
.NUL
;
197 Create_File_And_Check
(Output_FD
, Text
);
199 end Create_List_File
;
201 --------------------------------
202 -- Create_Output_Library_Info --
203 --------------------------------
205 procedure Create_Output_Library_Info
is
207 Set_Library_Info_Name
;
208 Create_File_And_Check
(Output_FD
, Text
);
209 end Create_Output_Library_Info
;
211 -------------------------
212 -- Create_Repinfo_File --
213 -------------------------
215 procedure Create_Repinfo_File
(Src
: File_Name_Type
) is
216 S
: constant File_Name_Type
:= Create_Auxiliary_File
(Src
, "rep");
217 pragma Warnings
(Off
, S
);
220 end Create_Repinfo_File
;
222 ---------------------------
223 -- Debug_File_Eol_Length --
224 ---------------------------
226 function Debug_File_Eol_Length
return Nat
is
228 -- There has to be a cleaner way to do this! ???
230 if Directory_Separator
= '/' then
235 end Debug_File_Eol_Length
;
237 -----------------------
238 -- More_Source_Files --
239 -----------------------
241 function More_Source_Files
return Boolean renames More_Files
;
243 ----------------------
244 -- Next_Main_Source --
245 ----------------------
247 function Next_Main_Source
return File_Name_Type
renames Next_Main_File
;
249 -----------------------
250 -- Read_Library_Info --
251 -----------------------
253 -- Version with default file name
255 procedure Read_Library_Info
256 (Name
: out File_Name_Type
;
257 Text
: out Text_Buffer_Ptr
)
260 Set_Library_Info_Name
;
262 Text
:= Read_Library_Info
(Name
, Fatal_Err
=> False);
263 end Read_Library_Info
;
265 ---------------------------
266 -- Set_Library_Info_Name --
267 ---------------------------
269 procedure Set_Library_Info_Name
is
273 Get_Name_String
(Current_Main
);
275 -- Find last dot since we replace the existing extension by .ali. The
276 -- initialization to Name_Len + 1 provides for simply adding the .ali
277 -- extension if the source file name has no extension.
279 Dot_Index
:= Name_Len
+ 1;
281 for J
in reverse 1 .. Name_Len
loop
282 if Name_Buffer
(J
) = '.' then
288 -- Make sure that the output file name matches the source file name.
289 -- To compare them, remove file name directories and extensions.
291 if Output_Object_File_Name
/= null then
293 -- Make sure there is a dot at Dot_Index. This may not be the case
294 -- if the source file name has no extension.
296 Name_Buffer
(Dot_Index
) := '.';
298 -- If we are in multiple unit per file mode, then add ~nnn
299 -- extension to the name before doing the comparison.
301 if Multiple_Unit_Index
/= 0 then
303 Exten
: constant String := Name_Buffer
(Dot_Index
.. Name_Len
);
305 Name_Len
:= Dot_Index
- 1;
306 Add_Char_To_Name_Buffer
(Multi_Unit_Index_Character
);
307 Add_Nat_To_Name_Buffer
(Multiple_Unit_Index
);
308 Dot_Index
:= Name_Len
+ 1;
309 Add_Str_To_Name_Buffer
(Exten
);
313 -- Remove extension preparing to replace it
316 Name
: constant String := Name_Buffer
(1 .. Dot_Index
);
317 Len
: constant Natural := Dot_Index
;
320 Name_Buffer
(1 .. Output_Object_File_Name
'Length) :=
321 Output_Object_File_Name
.all;
324 for J
in reverse Output_Object_File_Name
'Range loop
325 if Name_Buffer
(J
) = '.' then
331 -- Dot_Index should be zero now (we check for extension elsewhere)
333 pragma Assert
(Dot_Index
/= 0);
335 -- Check name of object file is what we expect
337 if Name
/= Name_Buffer
(Dot_Index
- Len
+ 1 .. Dot_Index
) then
338 Fail
("incorrect object file name");
343 Name_Buffer
(Dot_Index
) := '.';
344 Name_Buffer
(Dot_Index
+ 1 .. Dot_Index
+ 3) := ALI_Suffix
.all;
345 Name_Buffer
(Dot_Index
+ 4) := ASCII
.NUL
;
346 Name_Len
:= Dot_Index
+ 3;
347 end Set_Library_Info_Name
;
349 ---------------------------------
350 -- Set_Output_Object_File_Name --
351 ---------------------------------
353 procedure Set_Output_Object_File_Name
(Name
: String) is
354 Ext
: constant String := Target_Object_Suffix
;
355 NL
: constant Natural := Name
'Length;
356 EL
: constant Natural := Ext
'Length;
359 -- Make sure that the object file has the expected extension
363 (Name
(NL
- EL
+ Name
'First .. Name
'Last) /= Ext
364 and then Name
(NL
- 2 + Name
'First .. Name
'Last) /= ".o")
366 Fail
("incorrect object file extension");
369 Output_Object_File_Name
:= new String'(Name);
370 end Set_Output_Object_File_Name;
376 procedure Tree_Close is
379 Tree_Write_Terminate;
380 Close (Output_FD, Status);
384 ("error while closing tree file ",
385 Get_Name_String (Output_File_Name));
393 procedure Tree_Create is
397 Get_Name_String (Current_Main);
399 -- If an object file has been specified, then the ALI file
400 -- will be in the same directory as the object file;
401 -- so, we put the tree file in this same directory,
402 -- even though no object file needs to be generated.
404 if Output_Object_File_Name /= null then
405 Name_Len := Output_Object_File_Name'Length;
406 Name_Buffer (1 .. Name_Len) := Output_Object_File_Name.all;
409 Dot_Index := Name_Len + 1;
411 for J in reverse 1 .. Name_Len loop
412 if Name_Buffer (J) = '.' then
418 -- Should be impossible to not have an extension
420 pragma Assert (Dot_Index /= 0);
422 -- Change exctension to adt
424 Name_Buffer (Dot_Index) := '.';
425 Name_Buffer (Dot_Index + 1) := 'a
';
426 Name_Buffer (Dot_Index + 2) := 'd
';
427 Name_Buffer (Dot_Index + 3) := 't
';
428 Name_Buffer (Dot_Index + 4) := ASCII.NUL;
429 Name_Len := Dot_Index + 3;
430 Create_File_And_Check (Output_FD, Binary);
432 Tree_Write_Initialize (Output_FD);
435 -----------------------
436 -- Write_Debug_Info --
437 -----------------------
439 procedure Write_Debug_Info (Info : String) renames Write_Info;
441 ------------------------
442 -- Write_Library_Info --
443 ------------------------
445 procedure Write_Library_Info (Info : String) renames Write_Info;
447 ---------------------
448 -- Write_List_Info --
449 ---------------------
451 procedure Write_List_Info (S : String) is
453 Write_With_Check (S'Address, S'Length);
456 ------------------------
457 -- Write_Repinfo_Line --
458 ------------------------
460 procedure Write_Repinfo_Line (Info : String) renames Write_Info;
463 Adjust_OS_Resource_Limits;
465 Opt.Create_Repinfo_File_Access := Create_Repinfo_File'Access;
466 Opt.Write_Repinfo_Line_Access := Write_Repinfo_Line'Access;
467 Opt.Close_Repinfo_File_Access := Close_Repinfo_File'Access;
469 Opt.Create_List_File_Access := Create_List_File'Access;
470 Opt.Write_List_Info_Access := Write_List_Info'Access;
471 Opt.Close_List_File_Access := Close_List_File'Access;
473 Set_Program (Compiler);