From 1938bea67ecff1bbb892e9f24d2e9cc5c21161db Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Thu, 22 Oct 1998 16:11:53 -0700 Subject: [PATCH] jvspecs.c: Add (but don't enable) support for combining multiple .class and .java input... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit � * 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 --- gcc/java/jvspec.c | 185 ++++++++++++++++++++++++++++++++++++++---- gcc/java/lang-specs.h | 2 +- 2 files changed, 172 insertions(+), 15 deletions(-) diff --git a/gcc/java/jvspec.c b/gcc/java/jvspec.c index 7b86b135664..21277d15cbb 100644 --- a/gcc/java/jvspec.c +++ b/gcc/java/jvspec.c @@ -1,4 +1,4 @@ -/* 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. Copyright (C) 1996, 1997, 1998 Free Software Foundation, 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 library). */ #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 #define MATH_LIBRARY "-lm" @@ -59,6 +65,11 @@ extern size_t input_filename_length; char *main_class_name = NULL; 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[] = "jvgenmain %i %{!pipe:%u.i} |\n\ cc1 %{!pipe:%U.i} %1 \ @@ -86,6 +97,30 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) link in libjava. */ 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 libraries. We use this to track the number of times we've inserted -xc++/-xnone. */ @@ -118,6 +153,10 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) /* Saw `-ljava' on command line. */ 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 LANGSPEC, MATHLIB, WITHLIBC, or GCLIB. */ int *args; @@ -157,6 +196,7 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) if (quote) { quote = NULL; + args[i] |= PARAM_ARG; continue; } @@ -183,7 +223,10 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) need_math = 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) saw_libjava = 1; else if (strcmp (argv[i], "-lc") == 0) @@ -209,10 +252,31 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) } else if (strncmp (argv[i], "-x", 2) == 0) 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' && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL) || 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 && ((argv[i][2] == '\0' && (char *) strchr ("cSEM", argv[i][1]) != NULL) @@ -240,41 +304,94 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) continue; } - /* If the filename ends in .c or .i, put options around it. - But not if a specified -x option is currently active. */ +#if COMBINE_INPUTS len = strlen (argv[i]); - if (len > 2 - && (argv[i][len - 1] == 'c' || argv[i][len - 1] == 'i') - && argv[i][len - 2] == '.') + if (len > 5 && strcmp (argv[i] + len - 5, ".java") == 0) { - args[i] |= LANGSPEC; - added += 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] |= CLASS_FILE_ARG; + class_files_count++; + class_files_length += len; + last_input_index = i; + } +#endif } } if (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 (! added && ! library && main_class_name == NULL) +#endif +#if 0 + if (! added && ! library && main_class_name == NULL && ! saw_C) { free (args); return; } +#endif - num_args = argc + added + need_math + need_thread; if (main_class_name) { 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++) { 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 (! will_link) @@ -311,8 +428,37 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) --j; 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. */ if (library && ! saw_libjava) { @@ -348,6 +494,17 @@ lang_specific_driver (fn, in_argc, in_argv, in_added_libraries) if (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; *in_argc = j; diff --git a/gcc/java/lang-specs.h b/gcc/java/lang-specs.h index 190a44ceedd..726f313e8b4 100644 --- a/gcc/java/lang-specs.h +++ b/gcc/java/lang-specs.h @@ -27,7 +27,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ {".java", {"@java"} }, {".class", {"@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}\ %{traditional} %{v:-version} %{pg:-p} %{p}\ %{f*} %{+e*} %{aux-info*}\