Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / gcc / ada / gnatxref.adb
blob9e03e6cbd70b43d8d2953c5dd1f80f6aafcf5f07
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T X R E F --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1998-2002 Free Software Foundation, Inc. --
11 -- --
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. --
22 -- --
23 ------------------------------------------------------------------------------
25 with Xr_Tabls; use Xr_Tabls;
26 with Xref_Lib; use Xref_Lib;
27 with Osint; use Osint;
28 with Types; use Types;
30 with Gnatvsn;
31 with Opt;
33 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
34 with Ada.Text_IO; use Ada.Text_IO;
35 with GNAT.Command_Line; use GNAT.Command_Line;
37 procedure Gnatxref is
39 Search_Unused : Boolean := False;
40 Local_Symbols : Boolean := True;
41 Prj_File : File_Name_String;
42 Prj_File_Length : Natural := 0;
43 Usage_Error : exception;
44 Full_Path_Name : Boolean := False;
45 Vi_Mode : Boolean := False;
46 Read_Only : Boolean := False;
47 Have_File : Boolean := False;
48 Der_Info : Boolean := False;
50 procedure Parse_Cmd_Line;
51 -- Parse every switch on the command line
53 procedure Write_Usage;
54 -- Print a small help page for program usage
56 --------------------
57 -- Parse_Cmd_Line --
58 --------------------
60 procedure Parse_Cmd_Line is
61 begin
62 loop
63 case
64 GNAT.Command_Line.Getopt
65 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
67 when ASCII.NUL =>
68 exit;
70 when 'a' =>
71 if GNAT.Command_Line.Full_Switch = "a" then
72 Read_Only := True;
74 elsif GNAT.Command_Line.Full_Switch = "aI" then
75 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
77 else
78 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
79 end if;
81 when 'd' =>
82 Der_Info := True;
84 when 'f' =>
85 Full_Path_Name := True;
87 when 'g' =>
88 Local_Symbols := False;
90 when 'h' =>
91 Write_Usage;
93 when 'I' =>
94 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
95 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
97 when 'n' =>
98 if GNAT.Command_Line.Full_Switch = "nostdinc" then
99 Opt.No_Stdinc := True;
100 elsif GNAT.Command_Line.Full_Switch = "nostlib" then
101 Opt.No_Stdlib := True;
102 end if;
104 when 'p' =>
105 declare
106 S : constant String := GNAT.Command_Line.Parameter;
108 begin
109 Prj_File_Length := S'Length;
110 Prj_File (1 .. Prj_File_Length) := S;
111 end;
113 when 'u' =>
114 Search_Unused := True;
115 Vi_Mode := False;
117 when 'v' =>
118 Vi_Mode := True;
119 Search_Unused := False;
121 -- The only switch starting with -- recognized is --RTS
123 when '-' =>
124 Opt.No_Stdinc := True;
125 Opt.RTS_Switch := True;
127 declare
128 Src_Path_Name : String_Ptr :=
129 Get_RTS_Search_Dir
130 (GNAT.Command_Line.Parameter, Include);
132 Lib_Path_Name : String_Ptr :=
133 Get_RTS_Search_Dir
134 (GNAT.Command_Line.Parameter, Objects);
136 begin
137 if Src_Path_Name /= null and then Lib_Path_Name /= null then
138 Add_Search_Dirs (Src_Path_Name, Include);
139 Add_Search_Dirs (Lib_Path_Name, Objects);
141 elsif Src_Path_Name = null and then Lib_Path_Name = null then
142 Osint.Fail ("RTS path not valid: missing " &
143 "adainclude and adalib directories");
145 elsif Src_Path_Name = null then
146 Osint.Fail ("RTS path not valid: missing " &
147 "adainclude directory");
149 elsif Lib_Path_Name = null then
150 Osint.Fail ("RTS path not valid: missing " &
151 "adalib directory");
152 end if;
153 end;
155 when others =>
156 Write_Usage;
157 end case;
158 end loop;
160 -- Get the other arguments
162 loop
163 declare
164 S : constant String := GNAT.Command_Line.Get_Argument;
166 begin
167 exit when S'Length = 0;
169 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
170 Ada.Text_IO.Put_Line
171 ("Only file names are allowed on the command line");
172 Write_Usage;
173 end if;
175 Add_Xref_File (S);
176 Have_File := True;
177 end;
178 end loop;
180 exception
181 when GNAT.Command_Line.Invalid_Switch =>
182 Ada.Text_IO.Put_Line ("Invalid switch : "
183 & GNAT.Command_Line.Full_Switch);
184 Write_Usage;
186 when GNAT.Command_Line.Invalid_Parameter =>
187 Ada.Text_IO.Put_Line ("Parameter missing for : "
188 & GNAT.Command_Line.Full_Switch);
189 Write_Usage;
190 end Parse_Cmd_Line;
192 -----------------
193 -- Write_Usage --
194 -----------------
196 procedure Write_Usage is
197 use Ada.Text_IO;
199 begin
200 Put_Line ("GNATXREF " & Gnatvsn.Gnat_Version_String
201 & " Copyright 1998-2002, Ada Core Technologies Inc.");
202 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
203 New_Line;
204 Put_Line (" file ... list of source files to xref, " &
205 "including with'ed units");
206 New_Line;
207 Put_Line ("gnatxref switches:");
208 Put_Line (" -a Consider all files, even when the ali file is"
209 & " readonly");
210 Put_Line (" -aIdir Specify source files search path");
211 Put_Line (" -aOdir Specify library/object files search path");
212 Put_Line (" -d Output derived type information");
213 Put_Line (" -f Output full path name");
214 Put_Line (" -g Output information only for global symbols");
215 Put_Line (" -Idir Like -aIdir -aOdir");
216 Put_Line (" -nostdinc Don't look for sources in the system default"
217 & " directory");
218 Put_Line (" -nostdlib Don't look for library files in the system"
219 & " default directory");
220 Put_Line (" --RTS=dir specify the default source and object search"
221 & " path");
222 Put_Line (" -p file Use file as the default project file");
223 Put_Line (" -u List unused entities");
224 Put_Line (" -v Print a 'tags' file for vi");
225 New_Line;
227 raise Usage_Error;
228 end Write_Usage;
230 begin
231 Parse_Cmd_Line;
233 if not Have_File then
234 Write_Usage;
235 end if;
237 Xr_Tabls.Set_Default_Match (True);
239 -- Find the project file
241 if Prj_File_Length = 0 then
242 Xr_Tabls.Create_Project_File
243 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
244 else
245 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
246 end if;
248 -- Fill up the table
250 Search_Xref (Local_Symbols, Read_Only, Der_Info);
252 if Search_Unused then
253 Print_Unused (Full_Path_Name);
254 elsif Vi_Mode then
255 Print_Vi (Full_Path_Name);
256 else
257 Print_Xref (Full_Path_Name);
258 end if;
260 exception
261 when Usage_Error =>
262 null;
263 end Gnatxref;