Commit 1938bea6 by Per Bothner

jvspecs.c: Add (but don't enable) support for combining multiple .class and .java input...

�
	* jvspecs.c:  Add (but don't enable) support for combining multiple
	.class and .java input filenames to a single jc1 invocation.
	Add support for -C flag (copile to .class files).
	Translate -classpath and -CLASSPATH arguments.
	* lang-specs.h:  Don't set %2 spec.

From-SVN: r23238
parent 172b2240
/* Specific flags and argument handling of the front-end of the /* Specific flags and argument handling of the front-end of the
GNU compiler for the Java(TM) language. GNU compiler for the Java(TM) language.
Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
...@@ -46,6 +46,12 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ ...@@ -46,6 +46,12 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* This bit is set if they did `-lpthread' (or added some other thread /* This bit is set if they did `-lpthread' (or added some other thread
library). */ library). */
#define THREADLIB (1<<5) #define THREADLIB (1<<5)
/* True if this arg is a parameter to the previous option-taking arg. */
#define PARAM_ARG (1<<6)
/* True if this arg is a .java input file name. */
#define JAVA_FILE_ARG (1<<7)
/* True if this arg is a .class input file name. */
#define CLASS_FILE_ARG (1<<8)
#ifndef MATH_LIBRARY #ifndef MATH_LIBRARY
#define MATH_LIBRARY "-lm" #define MATH_LIBRARY "-lm"
...@@ -59,6 +65,11 @@ extern size_t input_filename_length; ...@@ -59,6 +65,11 @@ extern size_t input_filename_length;
char *main_class_name = NULL; char *main_class_name = NULL;
int lang_specific_extra_outfiles = 0; int lang_specific_extra_outfiles = 0;
/* Once we have the proper support in jc1 (and gcc.c) working,
set COMBINE_INPUTS to one. This enables combining multiple *.java
and *.class input files to be passed to a single jc1 invocation. */
#define COMBINE_INPUTS 0
char jvgenmain_spec[] = char jvgenmain_spec[] =
"jvgenmain %i %{!pipe:%u.i} |\n\ "jvgenmain %i %{!pipe:%u.i} |\n\
cc1 %{!pipe:%U.i} %1 \ cc1 %{!pipe:%U.i} %1 \
...@@ -86,6 +97,30 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) ...@@ -86,6 +97,30 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
link in libjava. */ link in libjava. */
int library = 1; int library = 1;
#if COMBINE_INPUTS
/* This will be 1 if multiple input files (.class and/or .java)
should be passed to a single jc1 invocation. */
int combine_inputs = 0;
/* Index of last .java or .class argument. */
int last_input_index;
/* A buffer containing the concatenation of the inputs files
(e.g. "foo.java&bar.class&baz.class"). if combine_inputs. */
char* combined_inputs_buffer;
/* Next available location in combined_inputs_buffer. */
int combined_inputs_pos;
/* Number of .java and .class source file arguments seen. */
int java_files_count = 0;
int class_files_count = 0;
/* Cumulative length of the .java and .class source file names. */
int java_files_length = 0;
int class_files_length = 0;
#endif
/* The number of arguments being added to what's in argv, other than /* The number of arguments being added to what's in argv, other than
libraries. We use this to track the number of times we've inserted libraries. We use this to track the number of times we've inserted
-xc++/-xnone. */ -xc++/-xnone. */
...@@ -118,6 +153,10 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) ...@@ -118,6 +153,10 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
/* Saw `-ljava' on command line. */ /* Saw `-ljava' on command line. */
int saw_libjava = 0; int saw_libjava = 0;
/* Saw -C or -o option, respectively. */
int saw_C = 0;
int saw_o = 0;
/* An array used to flag each argument that needs a bit set for /* An array used to flag each argument that needs a bit set for
LANGSPEC, MATHLIB, WITHLIBC, or GCLIB. */ LANGSPEC, MATHLIB, WITHLIBC, or GCLIB. */
int *args; int *args;
...@@ -157,6 +196,7 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) ...@@ -157,6 +196,7 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
if (quote) if (quote)
{ {
quote = NULL; quote = NULL;
args[i] |= PARAM_ARG;
continue; continue;
} }
...@@ -183,7 +223,10 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) ...@@ -183,7 +223,10 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
need_math = 0; need_math = 0;
} }
else if (strncmp (argv[i], "-fmain=", 7) == 0) else if (strncmp (argv[i], "-fmain=", 7) == 0)
main_class_name = argv[i] + 7; {
main_class_name = argv[i] + 7;
added--;
}
else if (strcmp (argv[i], "-ljava") == 0) else if (strcmp (argv[i], "-ljava") == 0)
saw_libjava = 1; saw_libjava = 1;
else if (strcmp (argv[i], "-lc") == 0) else if (strcmp (argv[i], "-lc") == 0)
...@@ -209,10 +252,31 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) ...@@ -209,10 +252,31 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
} }
else if (strncmp (argv[i], "-x", 2) == 0) else if (strncmp (argv[i], "-x", 2) == 0)
saw_speclang = 1; saw_speclang = 1;
else if (strcmp (argv[i], "-C") == 0)
{
saw_C = 1;
#if COMBINE_INPUTS
combine_inputs = 1;
#endif
if (library != 0)
added -= 2;
library = 0;
will_link = 0;
}
else if (((argv[i][2] == '\0' else if (((argv[i][2] == '\0'
&& (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL) && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
|| strcmp (argv[i], "-Tdata") == 0)) || strcmp (argv[i], "-Tdata") == 0))
quote = argv[i]; {
if (strcmp (argv[i], "-o") == 0)
saw_o = 1;
quote = argv[i];
}
else if (strcmp(argv[i], "-classpath") == 0
|| strcmp(argv[i], "-CLASSPATH") == 0)
{
quote = argv[i];
added -= 1;
}
else if (library != 0 else if (library != 0
&& ((argv[i][2] == '\0' && ((argv[i][2] == '\0'
&& (char *) strchr ("cSEM", argv[i][1]) != NULL) && (char *) strchr ("cSEM", argv[i][1]) != NULL)
...@@ -240,41 +304,94 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) ...@@ -240,41 +304,94 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
continue; continue;
} }
/* If the filename ends in .c or .i, put options around it. #if COMBINE_INPUTS
But not if a specified -x option is currently active. */
len = strlen (argv[i]); len = strlen (argv[i]);
if (len > 2 if (len > 5 && strcmp (argv[i] + len - 5, ".java") == 0)
&& (argv[i][len - 1] == 'c' || argv[i][len - 1] == 'i') {
&& argv[i][len - 2] == '.') args[i] |= JAVA_FILE_ARG;
java_files_count++;
java_files_length += len;
last_input_index = i;
}
if (len > 6 && strcmp (argv[i] + len - 6, ".class") == 0)
{ {
args[i] |= LANGSPEC; args[i] |= CLASS_FILE_ARG;
added += 2; class_files_count++;
class_files_length += len;
last_input_index = i;
} }
#endif
} }
} }
if (quote) if (quote)
(*fn) ("argument to `%s' missing\n", quote); (*fn) ("argument to `%s' missing\n", quote);
num_args = argc + added;
if (will_link)
num_args += need_math + need_thread;
if (saw_C)
{
num_args += 3;
#if COMBINE_INPUTS
class_files_length = 0;
num_args -= class_files_count;
num_args += 2; /* For -o NONE. */
#endif
if (saw_o)
(*fn) ("cannot specify both -C and -o");
}
#if COMBINE_INPUTS
if (saw_o && java_files_count + (saw_C ? 0 : class_files_count) > 1)
combine_inputs = 1;
if (combine_inputs)
{
int len = java_files_length + java_files_count - 1;
num_args -= java_files_count;
num_args++; /* Add one for the combined arg. */
if (class_files_length > 0)
{
len += class_files_length + class_files_count - 1;
num_args -= class_files_count;
}
combined_inputs_buffer = (char*) xmalloc (len);
combined_inputs_pos = 0;
}
/* If we know we don't have to do anything, bail now. */ /* If we know we don't have to do anything, bail now. */
if (! added && ! library && main_class_name == NULL) #endif
#if 0
if (! added && ! library && main_class_name == NULL && ! saw_C)
{ {
free (args); free (args);
return; return;
} }
#endif
num_args = argc + added + need_math + need_thread;
if (main_class_name) if (main_class_name)
{ {
lang_specific_extra_outfiles++; lang_specific_extra_outfiles++;
} }
arglist = (char **) xmalloc (num_args * sizeof (char *)); arglist = (char **) xmalloc ((num_args + 1) * sizeof (char *));
/* NOTE: We start at 1 now, not 0. */
for (i = 0, j = 0; i < argc; i++, j++) for (i = 0, j = 0; i < argc; i++, j++)
{ {
arglist[j] = argv[i]; arglist[j] = argv[i];
if ((args[i] & PARAM_ARG) || i == 0)
continue;
if (strcmp (argv[i], "-classpath") == 0
|| strcmp (argv[i], "-CLASSPATH") == 0)
{
char* patharg
= (char*) xmalloc (strlen (argv[i]) + strlen (argv[i+1]) + 3);
sprintf (patharg, "-f%s=%s", argv[i]+1, argv[i+1]);
arglist[j] = patharg;
i++;
continue;
}
if (strncmp (argv[i], "-fmain=", 7) == 0) if (strncmp (argv[i], "-fmain=", 7) == 0)
{ {
if (! will_link) if (! will_link)
...@@ -311,8 +428,37 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) ...@@ -311,8 +428,37 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
--j; --j;
saw_threadlib = argv[i]; saw_threadlib = argv[i];
} }
if ((args[i] & CLASS_FILE_ARG) && saw_C)
{
--j;
continue;
}
#if COMBINE_INPUTS
if (combine_inputs && (args[i] & (CLASS_FILE_ARG|JAVA_FILE_ARG)) != 0)
{
if (combined_inputs_pos > 0)
combined_inputs_buffer[combined_inputs_pos++] = '&';
strcpy (&combined_inputs_buffer[combined_inputs_pos], argv[i]);
combined_inputs_pos += strlen (argv[i]);
--j;
continue;
}
#endif
} }
#if COMBINE_INPUTS
if (combine_inputs)
{
combined_inputs_buffer[combined_inputs_pos] = '\0';
#if 0
if (! saw_C)
#endif
arglist[j++] = combined_inputs_buffer;
}
#endif
/* Add `-ljava' if we haven't already done so. */ /* Add `-ljava' if we haven't already done so. */
if (library && ! saw_libjava) if (library && ! saw_libjava)
{ {
...@@ -348,6 +494,17 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) ...@@ -348,6 +494,17 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
if (saw_libc) if (saw_libc)
arglist[j++] = saw_libc; arglist[j++] = saw_libc;
if (saw_C)
{
arglist[j++] = "-fsyntax-only";
arglist[j++] = "-femit-class-files";
arglist[j++] = "-S";
#if COMBINE_INPUTS
arglist[j++] = "-o";
arglist[j++] = "NONE";
#endif
}
arglist[j] = NULL; arglist[j] = NULL;
*in_argc = j; *in_argc = j;
......
...@@ -27,7 +27,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ ...@@ -27,7 +27,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
{".java", {"@java"} }, {".java", {"@java"} },
{".class", {"@java"} }, {".class", {"@java"} },
{"@java", {"@java",
{"%{!E:jc1 %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\ {"%{!E:jc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a}\
%{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\ %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
%{traditional} %{v:-version} %{pg:-p} %{p}\ %{traditional} %{v:-version} %{pg:-p} %{p}\
%{f*} %{+e*} %{aux-info*}\ %{f*} %{+e*} %{aux-info*}\
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment