Handle DFmode and DImode constant addresses.
[official-gcc.git] / gcc / java / jcf-depend.c
blob87b474caed2e260c66792f1a7971dff07c5c3596
1 /* Functions for handling dependency tracking when reading .class files.
3 Copyright (C) 1998 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU CC; see the file COPYING. If not, write to
17 the Free Software Foundation, 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
20 Java and all Java-based marks are trademarks or registered trademarks
21 of Sun Microsystems, Inc. in the United States and other countries.
22 The Free Software Foundation is independent of Sun Microsystems, Inc. */
24 /* Written by Tom Tromey <tromey@cygnus.com>, October 1998. */
26 #include "config.h"
27 #include "system.h"
29 #include <assert.h>
31 #include "jcf.h"
35 /* We keep a linked list of all the files we've already read. */
36 struct entry
38 char *file;
39 struct entry *next;
42 static void free_entry PROTO ((struct entry **));
43 static void add_entry PROTO ((struct entry **, const char *));
44 static const char *munge PROTO ((const char *));
45 static int print_ents PROTO ((struct entry *, int));
47 /* List of files. */
48 static struct entry *dependencies = NULL;
50 /* Name of targets. We support multiple targets when writing .class
51 files. */
52 static struct entry *targets = NULL;
54 /* Number of columns in output. */
55 #define MAX_OUTPUT_COLUMNS 72
57 /* The output file, or NULL if we aren't doing dependency tracking. */
58 static FILE *dep_out = NULL;
60 /* Nonzero if system files should be added. */
61 static int system_files;
65 /* Helper to free an entry list. */
66 static void
67 free_entry (entp)
68 struct entry **entp;
70 struct entry *ent, *next;
72 for (ent = *entp; ent != NULL; ent = next)
74 next = ent->next;
75 free (ent->file);
76 free (ent);
78 *entp = NULL;
81 /* Helper to add to entry list. */
82 static void
83 add_entry (entp, name)
84 struct entry **entp;
85 const char *name;
87 struct entry *ent;
89 for (ent = *entp; ent != NULL; ent = ent->next)
90 if (! strcmp (ent->file, name))
91 return;
93 ent = (struct entry *) malloc (sizeof (struct entry));
94 ent->file = strdup (name);
95 ent->next = *entp;
96 *entp = ent;
99 /* Call this to reset the dependency module. This is required if
100 multiple dependency files are being generated from a single tool
101 invocation. */
102 void
103 jcf_dependency_reset ()
105 free_entry (&dependencies);
106 free_entry (&targets);
108 if (dep_out != NULL)
110 if (dep_out != stdout)
111 fclose (dep_out);
112 dep_out = NULL;
116 void
117 jcf_dependency_set_target (name)
118 const char *name;
120 free_entry (&targets);
121 if (name != NULL)
122 add_entry (&targets, name);
125 void
126 jcf_dependency_add_target (name)
127 const char *name;
129 add_entry (&targets, name);
132 void
133 jcf_dependency_set_dep_file (name)
134 const char *name;
136 assert (dep_out != stdout);
137 if (dep_out)
138 fclose (dep_out);
139 if (! strcmp (name, "-"))
140 dep_out = stdout;
141 else
142 dep_out = fopen (name, "w");
145 void
146 jcf_dependency_add_file (filename, system_p)
147 const char *filename;
148 int system_p;
150 /* Just omit system files. */
151 if (system_p && ! system_files)
152 return;
154 add_entry (&dependencies, filename);
157 void
158 jcf_dependency_init (system_p)
159 int system_p;
161 system_files = system_p;
164 /* FIXME: this is taken almost directly from cccp.c. Such duplication
165 is bad. */
166 static const char *
167 munge (filename)
168 const char *filename;
170 static char *buffer = NULL;
171 static int buflen = 0;
173 int len = 2 * strlen (filename) + 1;
174 const char *p;
175 char *dst;
177 if (buflen < len)
179 buflen = len;
180 if (buffer == NULL)
181 buffer = malloc (buflen);
182 else
183 buffer = realloc (buffer, buflen);
186 dst = buffer;
187 for (p = filename; *p; ++p)
189 switch (*p)
191 case ' ':
192 case '\t':
194 /* GNU make uses a weird quoting scheme for white space.
195 A space or tab preceded by 2N+1 backslashes represents
196 N backslashes followed by space; a space or tab
197 preceded by 2N backslashes represents N backslashes at
198 the end of a file name; and backslashes in other
199 contexts should not be doubled. */
200 const char *q;
201 for (q = p - 1; filename < q && q[-1] == '\\'; q--)
202 *dst++ = '\\';
204 *dst++ = '\\';
205 goto ordinary_char;
207 case '$':
208 *dst++ = '$';
209 /* Fall through. This can mishandle things like "$(" but
210 there's no easy fix. */
211 default:
212 ordinary_char:
213 /* This can mishandle characters in the string "\0\n%*?[\\~";
214 exactly which chars are mishandled depends on the `make' version.
215 We know of no portable solution for this;
216 even GNU make 3.76.1 doesn't solve the problem entirely.
217 (Also, '\0' is mishandled due to our calling conventions.) */
218 *dst++ = *p;
219 break;
223 *dst++ = '\0';
224 return buffer;
227 /* Helper to print list of files. */
228 static int
229 print_ents (ent, column)
230 struct entry *ent;
231 int column;
233 int first = 1;
235 for (; ent != NULL; ent = ent->next)
237 const char *depname = munge (ent->file);
238 int len = strlen (depname);
240 if (column + len + 2 > MAX_OUTPUT_COLUMNS)
242 fprintf (dep_out, " \\\n ");
243 column = 1;
246 if (! first)
247 fputs (" ", dep_out);
248 fputs (depname, dep_out);
249 first = 0;
250 column += len + 1;
253 return column;
256 void
257 jcf_dependency_write ()
259 int column = 0;
261 if (! dep_out)
262 return;
264 assert (targets);
265 column = print_ents (targets, 0);
266 fputs (" : ", dep_out);
268 print_ents (dependencies, column);
269 fputs ("\n", dep_out);
270 fflush (dep_out);