Patch: gcj -vs- new dependency code

Tom Tromey tromey@cygnus.com
Sat Mar 4 16:52:00 GMT 2000


Zack recently added generic dependency handling code to the gcc
directory.  This patches changes gcj to use that code.

Ok to install?

2000-03-04  Tom Tromey  <tromey@cygnus.com>

	* Make-lang.in (jc1$(exeext)): Depend on mkdeps.o.
	(gcjh$(exeext)): Likewise.
	* Makefile.in (OBJS): Added mkdeps.o.
	(OBJDEPS): Likewise.
	(../gcjh$(exeext)): Added mkdeps.o.
	* jcf-depend.c: Include mkdeps.h.
	(struct entry, dependencies, targets, MAX_OUTPUT_COLUMNS,
	add_entry): Removed.
	(jcf_dependency_reset): Rewrote.
	(dependencies): New global.
	(jcf_dependency_set_target): Rewrote.
	(jcf_dependency_add_target): Likewise.
	(jcf_dependency_add_file): Likewise.
	(munge): Removed.
	(print_ents): Removed.
	(jcf_dependency_write): Rewrote.

Tom

Index: Make-lang.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/Make-lang.in,v
retrieving revision 1.28
diff -u -r1.28 Make-lang.in
--- Make-lang.in	2000/02/16 16:22:47	1.28
+++ Make-lang.in	2000/03/05 00:49:39
@@ -77,7 +77,8 @@
   $(srcdir)/java/check-init.c \
   $(srcdir)/java/jcf-depend.c  $(srcdir)/java/jcf-path.c
 
-jc1$(exeext): $(P) $(JAVA_SRCS) $(LIBDEPS) stamp-objlist ggc-callbacks.o
+jc1$(exeext): $(P) $(JAVA_SRCS) $(LIBDEPS) stamp-objlist \
+		ggc-callbacks.o mkdeps.o
 	cd java; $(MAKE) $(FLAGS_TO_PASS) $(JAVA_FLAGS_TO_PASS) ../jc1$(exeext)
 
 jvspec.o: $(srcdir)/java/jvspec.c system.h $(GCC_H)
@@ -107,7 +108,7 @@
 	$(srcdir)/java/javaop.def $(srcdir)/java/jcf-depend.c \
 	$(srcdir)/java/jcf-path.c
 
-gcjh$(exeext): $(GCJH_SOURCES) $(LIBDEPS) $(TREE_H)
+gcjh$(exeext): $(GCJH_SOURCES) $(LIBDEPS) $(TREE_H) mkdeps.o
 	cd java && $(MAKE) $(FLAGS_TO_PASS) $(JAVA_FLAGS_TO_PASS) ../gcjh$(exeext)
 
 # This must be kept in sync with dependencies in Makefile.in.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/Makefile.in,v
retrieving revision 1.50
diff -u -r1.50 Makefile.in
--- Makefile.in	2000/03/04 22:27:35	1.50
+++ Makefile.in	2000/03/05 00:49:40
@@ -171,8 +171,8 @@
 JAVA_OBJS_LITE = parse-scan.o jv-scan.o
 
 # Language-independent object files.
-OBJS = `cat ../stamp-objlist` ../ggc-callbacks.o
-OBJDEPS = ../stamp-objlist ../ggc-callbacks.o
+OBJS = `cat ../stamp-objlist` ../ggc-callbacks.o ../mkdeps.o
+OBJDEPS = ../stamp-objlist ../ggc-callbacks.o ../mkdeps.o
 
 compiler: ../jc1$(exeext) ../jv-scan$(exeext)
 ../jc1$(exeext): $(P) $(JAVA_OBJS) $(OBJDEPS) $(LIBDEPS)
@@ -192,9 +192,10 @@
 	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ jvgenmain.o mangle.o $(LIBS)
 
 ../gcjh$(exeext): gjavah.o jcf-io.o jcf-depend.o jcf-path.o \
-		zextract.o ../version.o $(LIBDEPS)
+		zextract.o ../version.o ../mkdeps.o $(LIBDEPS)
 	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ gjavah.o jcf-io.o \
-	  jcf-depend.o jcf-path.o zextract.o ../errors.o ../version.o $(LIBS)
+	  jcf-depend.o jcf-path.o zextract.o ../errors.o ../version.o \
+	  ../mkdeps.o $(LIBS)
 
 Makefile: $(srcdir)/Makefile.in $(srcdir)/../configure
 	cd ..; $(SHELL) config.status
Index: jcf-depend.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/jcf-depend.c,v
retrieving revision 1.9
diff -u -r1.9 jcf-depend.c
--- jcf-depend.c	2000/02/20 04:16:42	1.9
+++ jcf-depend.c	2000/03/05 00:49:40
@@ -25,6 +25,7 @@
 
 #include "config.h"
 #include "system.h"
+#include "mkdeps.h"
 
 #include <assert.h>
 
@@ -32,27 +33,8 @@
 
 
 
-/* We keep a linked list of all the files we've already read.  */
-struct entry
-{
-  char *file;
-  struct entry *next;
-};
-
-static void free_entry PARAMS ((struct entry **));
-static void add_entry PARAMS ((struct entry **, const char *));
-static const char *munge PARAMS ((const char *));
-static int print_ents PARAMS ((struct entry *, int));
-
-/* List of files.  */
-static struct entry *dependencies = NULL;
-
-/* Name of targets.  We support multiple targets when writing .class
-   files.  */
-static struct entry *targets = NULL;
-
-/* Number of columns in output.  */
-#define MAX_OUTPUT_COLUMNS 72
+/* The dependency structure used for this invocation.  */
+struct deps *dependencies;
 
 /* The output file, or NULL if we aren't doing dependency tracking.  */
 static FILE *dep_out = NULL;
@@ -62,56 +44,17 @@
 
 
 
-/* Helper to free an entry list.  */
-static void
-free_entry (entp)
-     struct entry **entp;
-{
-  struct entry *ent, *next;
-
-  for (ent = *entp; ent != NULL; ent = next)
-    {
-      next = ent->next;
-      free (ent->file);
-      free (ent);
-    }
-  *entp = NULL;
-}
-
-/* Helper to add to the end of the entry list.  */
-static void
-add_entry (entp, name)
-     struct entry **entp;
-     const char *name;
-{
-  struct entry *ent, *last;
-
-  for (last = ent = *entp; ent != NULL; last = ent, ent = ent->next)
-    if (! strcmp (ent->file, name))
-      return;
-
-  ent = (struct entry *) xmalloc (sizeof (struct entry));
-  ent->file = xstrdup (name);
-  ent->next = NULL;
-
-  if (last == *entp)
-    {
-      // This is only true the first time through, when the entry list
-      // is empty.
-      *entp = ent;
-    }     
-  else
-    last->next = ent;
-}
-
 /* Call this to reset the dependency module.  This is required if
    multiple dependency files are being generated from a single tool
-   invocation.  */
+   invocation.  FIXME: we should change our API or just completely use
+   the one in mkdeps.h.  */
 void
 jcf_dependency_reset ()
 {
-  free_entry (&dependencies);
-  free_entry (&targets);
+  if (dependencies != NULL)
+    deps_free (dependencies);
+
+  dependencies = deps_init ();
 
   if (dep_out != NULL)
     {
@@ -125,16 +68,17 @@
 jcf_dependency_set_target (name)
      const char *name;
 {
-  free_entry (&targets);
-  if (name != NULL)
-    add_entry (&targets, name);
+  /* We just handle this the same as an `add_target'.  */
+  assert (dependencies != NULL);
+  deps_add_target (dependencies, name);
 }
 
 void
 jcf_dependency_add_target (name)
      const char *name;
 {
-  add_entry (&targets, name);
+  assert (dependencies != NULL);
+  deps_add_target (dependencies, name);
 }
 
 void
@@ -155,11 +99,13 @@
      const char *filename;
      int system_p;
 {
+  assert (dependencies);
+
   /* Just omit system files.  */
   if (system_p && ! system_files)
     return;
 
-  add_entry (&dependencies, filename);
+  deps_add_dep (dependencies, filename);
 }
 
 void
@@ -169,108 +115,14 @@
   system_files = system_p;
 }
 
-/* FIXME: this is taken almost directly from cccp.c.  Such duplication
-   is bad.  */
-static const char *
-munge (filename)
-     const char *filename;
-{
-  static char *buffer = NULL;
-  static int buflen = 0;
-
-  int len = 2 * strlen (filename) + 1;
-  const char *p;
-  char *dst;
-
-  if (buflen < len)
-    {
-      buflen = len;
-      buffer = xrealloc (buffer, buflen);
-    }
-
-  dst = buffer;
-  for (p = filename; *p; ++p)
-    {
-      switch (*p)
-	{
-	case ' ':
-	case '\t':
-	  {
-	    /* GNU make uses a weird quoting scheme for white space.
-	       A space or tab preceded by 2N+1 backslashes represents
-	       N backslashes followed by space; a space or tab
-	       preceded by 2N backslashes represents N backslashes at
-	       the end of a file name; and backslashes in other
-	       contexts should not be doubled.  */
-	    const char *q;
-	    for (q = p - 1; filename < q && q[-1] == '\\';  q--)
-	      *dst++ = '\\';
-	  }
-	  *dst++ = '\\';
-	  goto ordinary_char;
-
-	case '$':
-	  *dst++ = '$';
-	  /* Fall through.  This can mishandle things like "$(" but
-	     there's no easy fix.  */
-	default:
-	ordinary_char:
-	  /* This can mishandle characters in the string "\0\n%*?[\\~";
-	     exactly which chars are mishandled depends on the `make' version.
-	     We know of no portable solution for this;
-	     even GNU make 3.76.1 doesn't solve the problem entirely.
-	     (Also, '\0' is mishandled due to our calling conventions.)  */
-	  *dst++ = *p;
-	  break;
-	}
-    }
-
-  *dst++ = '\0';
-  return buffer;
-}
-
-/* Helper to print list of files.  */
-static int
-print_ents (ent, column)
-     struct entry *ent;
-     int column;
-{
-  int first = 1;
-
-  for (; ent != NULL; ent = ent->next)
-    {
-      const char *depname = munge (ent->file);
-      int len = strlen (depname);
-
-      if (column + len + 2 > MAX_OUTPUT_COLUMNS)
-	{
-	  fprintf (dep_out, " \\\n ");
-	  column = 1;
-	}
-
-      if (! first)
-	fputs (" ", dep_out);
-      fputs (depname, dep_out);
-      first = 0;
-      column += len + 1;
-    }
-
-  return column;
-}
-
 void
 jcf_dependency_write ()
 {
-  int column = 0;
-
   if (! dep_out)
     return;
 
-  assert (targets);
-  column = print_ents (targets, 0);
-  fputs (" : ", dep_out);
+  assert (dependencies);
 
-  print_ents (dependencies, column);
-  fputs ("\n", dep_out);
+  deps_write (dependencies, dep_out, 72);
   fflush (dep_out);
 }


More information about the Gcc-patches mailing list