This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[ecj] Patch: FYI: change gcj to invoke ecj1


I'm checking this in on the gcj-eclipse branch.

This adds support for invoking 'ecj1' when a .java file is seen on
the command line.  It also adds new -fsource and -ftarget options for
the user (and -fsaw-java-file, which is only used internally).

I see I didn't comment how this all works.  Actually, I'm not really
sure where to comment it... maybe lang-specs.h?  Opinions?


Meanwhile I'll describe it here.

This adds -fsource and -ftarget so that the user can pick the source
and target versions, as is done with other java compilers.  This is
particularly useful for choosing 1.4 -vs- 1.5 -- now relevant with
ecj.

The gcj driver now handles all the classpath-related options directly,
and only passes -fbootclasspath down to subprocesses.  This was the
easiest way to avoid duplicating a lot of logic in ecj.

The new specs invoke a special driver for ecj which I am calling ecj1.
(I'll post the patch against ecj soon.)  This driver is only invoked
when gcj sees a .java file on the command line.

ecj1 is just another main() method for the eclipse compiler.  It
mostly exists to bridge the impedance mismatch between gcc-style
options and eclipse-style options.  When ecj1 compiles a .java file
(and when run in the compile-to-native mode -- gcj has a lot of
compilation modes and this patch tries to support them all, hence the
complexity of the specs), it emits two jar files.

One jar file contains the classes which need to be compiled to object
code.  The other jar file contains classes which we compiled from
source but which are only needed for dependencies.  This is used to
support the C++ ABI, which needs to understand the layout of all
classes, not just those being directly compiled.  (In BC compilation
ecj1 won't write to this second jar).

There are still a few bugs here.  I think we leave some files in /tmp
sometimes, I haven't investigate that.  Also I'm not sure every
possible compilation mode works properly, though I've tried most
things.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* lang.opt (-fsaw-java-file, -fsource, -ftarget): New options.
	* jvspec.c (jvgenmain_spec): Remove -fsaw-java-file, -fsource,
	and -ftarget.
	(lang_specific_driver): Removed dead code.  Add -fsaw-java-file
	when needed.  Handle classpath-setting.
	* Make-lang.in ($(GCJ)$(exeext)): Link in jcf-path.o.
	* lang-specs.h: Rewrote.

Index: lang-specs.h
===================================================================
--- lang-specs.h	(revision 114362)
+++ lang-specs.h	(working copy)
@@ -1,5 +1,5 @@
 /* Definitions for specs for the GNU compiler for the Java(TM) language.
-   Copyright (C) 1996, 1998, 1999, 2000, 2001, 2003, 2004
+   Copyright (C) 1996, 1998, 1999, 2000, 2001, 2003, 2004, 2006
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -35,7 +35,29 @@
     %{fjni:%{femit-class-file:%e-fjni and -femit-class-file are incompatible}}\
     %{femit-class-file:%{!fsyntax-only:%e-femit-class-file should used along with -fsyntax-only}}\
     %{femit-class-files:%{!fsyntax-only:%e-femit-class-file should used along with -fsyntax-only}}\
-    %{!E:jc1 %i %(jc1) %(cc1_options) %{+e*} %{I*}\
-             %{MD:-MD_} %{MMD:-MMD_} %{M} %{MM} %{MA} %{MT*} %{MF*}\
-             %{!fsyntax-only:%(invoke_as)}}", 0, 0, 0},
+    %{E:%{e-E is not valid for gcj}}\
+    %{.java|fsaw-java-file:ecj1 %i %{W*} %{w} %{g*}			\
+      %{fbootclasspath*}						\
+      %{fenable-assertions*}						\
+      %{fdisable-assertions*}						\
+      %{fencoding*} %{ffilelist-file}					\
+      %{foutput-class-dir*} %{g*}					\
+      %{fsource*} %{!fsource*:-fsource=1.4}				\
+      %{ftarget*} %{!ftarget*:-ftarget=1.4}				\
+      %{!findirect-dispatch:-fzip-dependency=%U.zip}			\
+      %{!fsyntax-only:-fzip-target=%U.jar}}\n				\
+    %{.class|.zip|.jar|!fsyntax-only:jc1				\
+      %{.java:%U.jar}							\
+      %{.class|.zip|.jar|ffilelist-file|fcompile-resource*:%i}		\
+      %(jc1) %(cc1_options) %{I*} %{!findirect-dispatch:-I%U.zip}	\
+      %(invoke_as)}",
+      0, 0, 0},
 
+  /*
+    FIXME: we don't use %|, even though we could, because we need the
+    dependency zip to be ready early enough.  We could work around
+    this by not having a dependency zip and instead teaching jc1 to
+    read a special manifest file included in the sole zip, this
+    manifest would say which files are to be compiled and which are
+    not.
+   */
Index: Make-lang.in
===================================================================
--- Make-lang.in	(revision 114362)
+++ Make-lang.in	(working copy)
@@ -1,6 +1,6 @@
 # Top level -*- makefile -*- fragment for the GNU compiler for the Java(TM)
 # language.
-#   Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+#   Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 #This file is part of GCC.
 
@@ -67,10 +67,11 @@
 		$(INCLUDES) $(srcdir)/java/jvspec.c $(OUTPUT_OPTION))
 
 # Create the compiler driver for $(GCJ).
-$(GCJ)$(exeext): $(GCC_OBJS) jvspec.o version.o \
+$(GCJ)$(exeext): $(GCC_OBJS) jvspec.o java/jcf-path.o version.o \
 	   prefix.o intl.o $(LIBDEPS) $(EXTRA_GCC_OBJS)
 	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GCC_OBJS) jvspec.o \
-	  prefix.o intl.o version.o $(EXTRA_GCC_OBJS) $(LIBS)
+	  java/jcf-path.o prefix.o intl.o \
+	  version.o $(EXTRA_GCC_OBJS) $(LIBS)
 
 # Create a version of the $(GCJ) driver which calls the cross-compiler.
 $(GCJ)-cross$(exeext): $(GCJ)$(exeext)
Index: jvspec.c
===================================================================
--- jvspec.c	(revision 114362)
+++ jvspec.c	(working copy)
@@ -1,6 +1,6 @@
 /* Specific flags and argument handling of the front-end of the 
    GNU compiler for the Java(TM) language.
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -29,6 +29,7 @@
 #include "coretypes.h"
 #include "tm.h"
 #include "gcc.h"
+#include "jcf.h"
 
 /* Name of spec file.  */
 #define SPEC_FILE "libgcj.spec"
@@ -74,7 +75,7 @@
 		   %<fextdirs*\
 		   %<fuse-divide-subroutine %<fno-use-divide-subroutine\
 		   %<fcheck-references %<fno-check-references\
-		   %<ffilelist-file\
+		   %<ffilelist-file %<fsaw-java-file %<fsource* %<ftarget*\
 		   %{f*} -fdollars-in-identifiers\
 		   %{aux-info*}\
 		   %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
@@ -189,23 +190,6 @@
      already gave a language for the file.  */
   int saw_speclang = 0;
 
-#if 0
-  /* "-lm" or "-lmath" if it appears on the command line.  */
-  const char *saw_math ATTRIBUTE_UNUSED = 0;
-
-  /* "-lc" if it appears on the command line.  */
-  const char *saw_libc ATTRIBUTE_UNUSED = 0;
-
-  /* "-lgcjgc" if it appears on the command line.  */
-  const char *saw_gc ATTRIBUTE_UNUSED = 0;
-
-  /* Saw `-l' option for the thread library.  */
-  const char *saw_threadlib ATTRIBUTE_UNUSED = 0;
-
-  /* Saw `-lgcj' on command line.  */
-  int saw_libgcj ATTRIBUTE_UNUSED = 0;
-#endif
-
   /* Saw --resource, -C or -o options, respectively. */
   int saw_resource = 0;
   int saw_C = 0;
@@ -231,6 +215,10 @@
   /* The number of libraries added in.  */
   int added_libraries;
 
+  /* The total number of arguments having to do with classpath
+     setting.  */
+  int classpath_args = 0;
+
   /* The total number of arguments with the new stuff.  */
   int num_args = 1;
 
@@ -460,14 +448,6 @@
       num_args -= java_files_count + class_files_count + zip_files_count;
       num_args += 3;  /* for the combined arg "-xjava", and "-xnone" */
     }
-  /* If we know we don't have to do anything, bail now.  */
-#if 0
-  if (! added && ! library && main_class_name == NULL && ! saw_C)
-    {
-      free (args);
-      return;
-    }
-#endif
 
   if (main_class_name)
     {
@@ -476,6 +456,8 @@
   if (saw_g + saw_O == 0)
     num_args++;
   num_args++;
+  /* An additional entry for the classpath.  */
+  num_args++;
 
   if (combine_inputs || indirect_files_count > 0)
     num_args += 1; /* for "-ffilelist-file" */
@@ -488,6 +470,9 @@
   shared_libgcc = 0;
 #endif  
   
+  if (java_files_count > 0)
+    ++num_args;
+
   num_args += shared_libgcc;
 
   arglist = XNEWVEC (const char *, num_args + 1);
@@ -505,6 +490,10 @@
       arglist[j++] = "-xnone";
     }
 
+  if (java_files_count > 0)
+    arglist[j++] = "-fsaw-java-file";
+
+  jcf_path_init ();
   for (i = 1; i < argc; i++, j++)
     {
       arglist[j] = argv[i];
@@ -519,12 +508,52 @@
 	  arglist[j] = "-xnone";
 	}
 
-      if (strcmp (argv[i], "-classpath") == 0
-	  || strcmp (argv[i], "-bootclasspath") == 0
-	  || strcmp (argv[i], "-CLASSPATH") == 0
-	  || strcmp (argv[i], "-encoding") == 0
-	  || strcmp (argv[i], "-extdirs") == 0)
+      if (argv[i][1] == 'I')
 	{
+	  jcf_path_include_arg (&argv[i][2]);
+	  --j;
+	  continue;
+	}
+      if (! strcmp (argv[i], "-classpath")
+	  || ! strcmp (argv[i], "-CLASSPATH"))
+	{
+	  jcf_path_classpath_arg (argv[i + 1]);
+	  ++i;
+	  --j;
+	  continue;
+	}
+      if (! strcmp (argv[i], "-bootclasspath"))
+	{
+	  jcf_path_bootclasspath_arg (argv[i + 1]);
+	  ++i;
+	  --j;
+	  continue;
+	}
+      if (! strncmp (argv[i], "-fCLASSPATH=", 12)
+	  || ! strncmp (argv[i], "-fclasspath=", 12))
+	{
+	  char *p = strchr (argv[i], '=');
+	  jcf_path_classpath_arg (p + 1);
+	  --j;
+	  continue;
+	}
+      if (! strncmp (argv[i], "-fbootclasspath=", 16))
+	{
+	  char *p = strchr (argv[i], '=');
+	  jcf_path_bootclasspath_arg (p + 1);
+	  --j;
+	  continue;
+	}
+      if (! strcmp (argv[i], "-extdirs"))
+	{
+	  jcf_path_extdirs_arg (argv[i + 1]);
+	  ++i;
+	  --j;
+	  continue;
+	}
+
+      if (strcmp (argv[i], "-encoding") == 0)
+	{
 	  arglist[j] = concat ("-f", argv[i]+1, "=", argv[i+1], NULL);
 	  i++;
 	  continue;
@@ -571,6 +600,11 @@
 	}
   }
 
+  /* Handle classpath setting.  We specify the bootclasspath since
+     that requires the fewest changes to our existing code...  */
+  jcf_path_seal (0);
+  arglist[j++] = jcf_path_compute ("-fbootclasspath=");
+
   if (combine_inputs)
     {
       if (fclose (filelist_file))
Index: lang.opt
===================================================================
--- lang.opt	(revision 114362)
+++ lang.opt	(working copy)
@@ -138,6 +138,9 @@
 Java Var(flag_filelist_file)
 Input file is a file with a list of filenames to compile
 
+fsaw-java-file
+Java Undocumented RejectNegative
+
 fforce-classes-archive-check
 Java Var(flag_force_classes_archive_check)
 Always check for non gcj generated classes archives
@@ -188,5 +191,13 @@
 Java Var(flag_bootstrap_classes)
 Generated should be loaded by bootstrap loader
 
+fsource=
+Java Joined
+Set the source language version
+
+ftarget=
+Java Joined
+Set the target VM version
+
 version
 Java


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]