This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[PATCH, M2] Compiler driver patches


here are some patches to introduce Modula-2 into the GCC trunk.  They
have been re-written after taking on board the comments found in this
thread:

   https://gcc.gnu.org/ml/gcc-patches/2013-11/msg02620.html

These patches and newfiles introduce the gm2 driver in gcc/m2 with
appropriate Makefile/configure changes.  I've run all language
regression tests on trunk and no extra failures occur.

I'm currently tracking gcc trunk and gcc-9 with gm2 (which works well
with amd64/arm64/i386) - these patches are currently simply for the
driver to minimise the patch size.  There are also > 1800 tests in a
dejagnu testsuite for gm2 which can be included at some future time.

These patches will result in a tree of files found here:

   http://git.savannah.gnu.org/cgit/gm2.git/tree/gcc-versionno/gcc?h=gcc_trunk

and the development gm2 tracking gcc trunk is found in:

   http://git.savannah.gnu.org/cgit/gm2.git/tree/gcc-versionno/gcc?h=master

My proposed plan of work is to push the patches to the mailing list
(and probably some references to large tarballs at some point) which
will effectively migrate source from the gm2 master branch onto the
gcc_trunk (and thus to the gcc svn trunk).  Feel free to suggest a
different plan of work of course.

Here are the proposed patches and ChangeLogs and new files (after the
patches):

./ChangeLog

04-06-2019  Gaius Mulley   <gaius.mulley@southwales.ac.uk>

        * configure.ac (GM2_FOR_BUILD): Added.
          (GM2_FOR_TARGET): Added.
          Request build driver program gm2.
        * Makefile.def (GM2_FOR_TARGET): Added.
          (GM2FLAGS_FOR_TARGET): Added.  Assign GM2,
          GM2_FOR_BUILD, GM2_FOR_TARGET and GM2FLAGS.
          Pass variables to make.

./gcc/ChangeLog

04-06-2019  Gaius Mulley   <gaius.mulley@southwales.ac.uk>

        * gcc.c (allow_linker): Global variable to disable
          linker by the front end.
          (handle_OPT_B): New function to handle the -B option.
          (fe_save_switch): New function to allow front ends to
          add switches.
          (fe_B_prefix): New function to allow front ends to add
          their own -B option.
          (fe_remove_infile): Front ends can mark a source file
          as compiled.
          (maybe_run_linker): Check allow_linker before running
          the linker.
        * gcc.h (fe_B_prefix): Prototype.
          (fe_save_switch): Prototype.
          (allow_linker): Extern.

--- gcc-versionno-orig/configure.ac	2019-05-28 22:11:37.993620055 +0100
+++ gcc-versionno/configure.ac	2019-05-28 22:39:16.345133571 +0100
@@ -1270,6 +1270,7 @@
   GFORTRAN_FOR_BUILD=${GFORTRAN_FOR_BUILD-gfortran}
   GOC_FOR_BUILD=${GOC_FOR_BUILD-gccgo}
   GDC_FOR_BUILD=${GDC_FOR_BUILD-gdc}
+  GM2_FOR_BUILD=${GM2_FOR_BUILD-gm2}
   DLLTOOL_FOR_BUILD=${DLLTOOL_FOR_BUILD-dlltool}
   LD_FOR_BUILD=${LD_FOR_BUILD-ld}
   NM_FOR_BUILD=${NM_FOR_BUILD-nm}
@@ -1284,6 +1285,7 @@
   GFORTRAN_FOR_BUILD="\$(GFORTRAN)"
   GOC_FOR_BUILD="\$(GOC)"
   GDC_FOR_BUILD="\$(GDC)"
+  GM2_FOR_BUILD="\$(GM2)"
   DLLTOOL_FOR_BUILD="\$(DLLTOOL)"
   LD_FOR_BUILD="\$(LD)"
   NM_FOR_BUILD="\$(NM)"
@@ -3272,6 +3274,7 @@
 AC_SUBST(GFORTRAN_FOR_BUILD)
 AC_SUBST(GOC_FOR_BUILD)
 AC_SUBST(GDC_FOR_BUILD)
+AC_SUBST(GM2_FOR_BUILD)
 AC_SUBST(LDFLAGS_FOR_BUILD)
 AC_SUBST(LD_FOR_BUILD)
 AC_SUBST(NM_FOR_BUILD)
@@ -3383,6 +3386,7 @@
 NCN_STRICT_CHECK_TARGET_TOOLS(GFORTRAN_FOR_TARGET, gfortran)
 NCN_STRICT_CHECK_TARGET_TOOLS(GOC_FOR_TARGET, gccgo)
 NCN_STRICT_CHECK_TARGET_TOOLS(GDC_FOR_TARGET, gdc)
+NCN_STRICT_CHECK_TARGET_TOOLS(GM2_FOR_TARGET, gm2)
 
 ACX_CHECK_INSTALLED_TARGET_TOOL(AR_FOR_TARGET, ar)
 ACX_CHECK_INSTALLED_TARGET_TOOL(AS_FOR_TARGET, as)
@@ -3419,6 +3423,8 @@
 		[gcc/gccgo -B$$r/$(HOST_SUBDIR)/gcc/], go)
 GCC_TARGET_TOOL(gdc, GDC_FOR_TARGET, GDC,
 		[gcc/gdc -B$$r/$(HOST_SUBDIR)/gcc/], d)
+GCC_TARGET_TOOL(gm2, GM2_FOR_TARGET, GM2,
+		[gcc/xgm2 -B$$r/$(HOST_SUBDIR)/gcc/], gm2)
 GCC_TARGET_TOOL(ld, LD_FOR_TARGET, LD, [ld/ld-new])
 GCC_TARGET_TOOL(lipo, LIPO_FOR_TARGET, LIPO)
 GCC_TARGET_TOOL(nm, NM_FOR_TARGET, NM, [binutils/nm-new])
--- gcc-versionno-orig/gcc/gcc.c	2019-05-28 22:15:19.368276992 +0100
+++ gcc-versionno/gcc/gcc.c	2019-06-04 23:58:15.164747925 +0100
@@ -305,6 +305,9 @@
 static const char *cross_compile = "0";
 #endif
 
+/* The lang specs might wish to override the default linker.  */
+int allow_linker = 1;
+
 /* Greatest exit code of sub-processes that has been encountered up to
    now.  */
 static int greatest_status = 1;
@@ -410,6 +413,7 @@
 static const char *debug_level_greater_than_spec_func (int, const char **);
 static const char *find_fortran_preinclude_file (int, const char **);
 static char *convert_white_space (char *);
+static void handle_OPT_B (const char *arg);
 
 /* The Specs Language
 
@@ -3725,6 +3729,70 @@
   setenv ("SOURCE_DATE_EPOCH", source_date_epoch, 0);
 }
 
+/* Save an option OPT with N_ARGS arguments in array ARGS, marking it
+   as validated if VALIDATED.  */
+
+void
+fe_save_switch (const char *opt, size_t n_args, const char *const *args,
+		bool validated, bool known)
+{
+  save_switch (opt, n_args, args, validated, known);
+}
+
+/* fe_B_prefix allow the front end to add its own -B option.  */
+
+void
+fe_B_prefix (const char *arg)
+{
+  handle_OPT_B (arg);
+}
+
+/* Handle the -B option by adding the prefix to exec, startfile and
+   include search paths.  */
+
+static
+void handle_OPT_B (const char *arg)
+{
+  size_t len = strlen (arg);
+
+  /* Catch the case where the user has forgotten to append a
+     directory separator to the path.  Note, they may be using
+     -B to add an executable name prefix, eg "i386-elf-", in
+     order to distinguish between multiple installations of
+     GCC in the same directory.  Hence we must check to see
+     if appending a directory separator actually makes a
+     valid directory name.  */
+  if (!IS_DIR_SEPARATOR (arg[len - 1])
+      && is_directory (arg, false))
+    {
+      char *tmp = XNEWVEC (char, len + 2);
+      strcpy (tmp, arg);
+      tmp[len] = DIR_SEPARATOR;
+      tmp[++len] = 0;
+      arg = tmp;
+    }
+
+  add_prefix (&exec_prefixes, arg, NULL,
+	      PREFIX_PRIORITY_B_OPT, 0, 0);
+  add_prefix (&startfile_prefixes, arg, NULL,
+	      PREFIX_PRIORITY_B_OPT, 0, 0);
+  add_prefix (&include_prefixes, arg, NULL,
+	      PREFIX_PRIORITY_B_OPT, 0, 0);
+}
+
+/* Remove an object file, name.  */
+
+void
+fe_remove_infile (const char *name)
+{
+  int max = n_infiles + lang_specific_extra_outfiles;
+  int i;
+
+  for (i = 0; i < max; i++)
+    if (filename_cmp (name, infiles[i].name) == 0)
+      infiles[i].compiled = true;
+}
+
 /* Handle an option DECODED that is unknown to the option-processing
    machinery.  */
 
@@ -4204,33 +4272,7 @@
       break;
 
     case OPT_B:
-      {
-	size_t len = strlen (arg);
-
-	/* Catch the case where the user has forgotten to append a
-	   directory separator to the path.  Note, they may be using
-	   -B to add an executable name prefix, eg "i386-elf-", in
-	   order to distinguish between multiple installations of
-	   GCC in the same directory.  Hence we must check to see
-	   if appending a directory separator actually makes a
-	   valid directory name.  */
-	if (!IS_DIR_SEPARATOR (arg[len - 1])
-	    && is_directory (arg, false))
-	  {
-	    char *tmp = XNEWVEC (char, len + 2);
-	    strcpy (tmp, arg);
-	    tmp[len] = DIR_SEPARATOR;
-	    tmp[++len] = 0;
-	    arg = tmp;
-	  }
-
-	add_prefix (&exec_prefixes, arg, NULL,
-		    PREFIX_PRIORITY_B_OPT, 0, 0);
-	add_prefix (&startfile_prefixes, arg, NULL,
-		    PREFIX_PRIORITY_B_OPT, 0, 0);
-	add_prefix (&include_prefixes, arg, NULL,
-		    PREFIX_PRIORITY_B_OPT, 0, 0);
-      }
+      handle_OPT_B (arg);
       validated = true;
       break;
 
@@ -8259,7 +8301,8 @@
 
   /* Run ld to link all the compiler output files.  */
 
-  if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2)
+  if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2
+      && allow_linker)
     {
       int tmp = execution_count;
 
@@ -8326,7 +8369,7 @@
   /* If options said don't run linker,
      complain about input files to be given to the linker.  */
 
-  if (! linker_was_run && !seen_error ())
+  if (! linker_was_run && !seen_error () && allow_linker)
     for (i = 0; (int) i < n_infiles; i++)
       if (explicit_link_files[i]
 	  && !(infiles[i].language && infiles[i].language[0] == '*'))
--- gcc-versionno-orig/gcc/gcc.h	2019-05-28 22:15:19.368276992 +0100
+++ gcc-versionno/gcc/gcc.h	2019-06-04 21:17:43.950739675 +0100
@@ -72,6 +72,9 @@
 extern int do_spec (const char *);
 extern void record_temp_file (const char *, int, int);
 extern void set_input (const char *);
+extern void fe_save_switch (const char *opt, size_t n_args,
+			    const char *const *args, bool validated);
+extern void fe_B_prefix (const char *arg);
 
 /* Spec files linked with gcc.c must provide definitions for these.  */
 
@@ -96,4 +99,8 @@
 					      void *user_data),
 				   void *user_data);
 
+/* Default setting is true, but can be overridden by the language
+   front end to prohibit the linker from being invoked.  */
+extern int allow_linker;
+
 #endif /* ! GCC_GCC_H */
--- gcc-versionno-orig/Makefile.def	2019-05-28 22:33:03.786431313 +0100
+++ gcc-versionno/Makefile.def	2019-05-28 22:39:16.353133392 +0100
@@ -284,6 +284,8 @@
 flags_to_pass = { flag= GOCFLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= GDC_FOR_TARGET ; };
 flags_to_pass = { flag= GDCFLAGS_FOR_TARGET ; };
+flags_to_pass = { flag= GM2_FOR_TARGET ; };
+flags_to_pass = { flag= GM2FLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= LD_FOR_TARGET ; };
 flags_to_pass = { flag= LIPO_FOR_TARGET ; };
 flags_to_pass = { flag= LDFLAGS_FOR_TARGET ; };
--- gcc-versionno-orig/Makefile.tpl	2019-05-28 22:33:04.658406768 +0100
+++ gcc-versionno/Makefile.tpl	2019-05-28 22:39:16.357133302 +0100
@@ -161,6 +161,7 @@
 	GOCFLAGS="$(GOCFLAGS_FOR_BUILD)"; export GOCFLAGS; \
 	GDC="$(GDC_FOR_BUILD)"; export GDC; \
 	GDCFLAGS="$(GDCFLAGS_FOR_BUILD)"; export GDCFLAGS; \
+	GM2="$(GM2_FOR_BUILD)"; export GM2; \
 	DLLTOOL="$(DLLTOOL_FOR_BUILD)"; export DLLTOOL; \
 	LD="$(LD_FOR_BUILD)"; export LD; \
 	LDFLAGS="$(LDFLAGS_FOR_BUILD)"; export LDFLAGS; \
@@ -198,6 +199,7 @@
 	GFORTRAN="$(GFORTRAN)"; export GFORTRAN; \
 	GOC="$(GOC)"; export GOC; \
 	GDC="$(GDC)"; export GDC; \
+	GM2="$(GM2)"; export GM2; \
 	AR="$(AR)"; export AR; \
 	AS="$(AS)"; export AS; \
 	CC_FOR_BUILD="$(CC_FOR_BUILD)"; export CC_FOR_BUILD; \
@@ -295,6 +297,7 @@
 	GFORTRAN="$(GFORTRAN_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export GFORTRAN; \
 	GOC="$(GOC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export GOC; \
 	GDC="$(GDC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export GDC; \
+	GM2="$(GM2_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export GM2; \
 	DLLTOOL="$(DLLTOOL_FOR_TARGET)"; export DLLTOOL; \
 	LD="$(COMPILER_LD_FOR_TARGET)"; export LD; \
 	LDFLAGS="$(LDFLAGS_FOR_TARGET)"; export LDFLAGS; \
@@ -361,6 +364,7 @@
 GFORTRAN_FOR_BUILD = @GFORTRAN_FOR_BUILD@
 GOC_FOR_BUILD = @GOC_FOR_BUILD@
 GDC_FOR_BUILD = @GDC_FOR_BUILD@
+GM2_FOR_BUILD = @GM2_FOR_BUILD@
 LDFLAGS_FOR_BUILD = @LDFLAGS_FOR_BUILD@
 LD_FOR_BUILD = @LD_FOR_BUILD@
 NM_FOR_BUILD = @NM_FOR_BUILD@
@@ -430,6 +434,7 @@
 LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates
 GOCFLAGS = $(CFLAGS)
 GDCFLAGS = $(CFLAGS)
+GM2FLAGS = $(CFLAGS)
 
 CREATE_GCOV = create_gcov
 
@@ -517,6 +522,7 @@
 GFORTRAN_FOR_TARGET=$(STAGE_CC_WRAPPER) @GFORTRAN_FOR_TARGET@
 GOC_FOR_TARGET=$(STAGE_CC_WRAPPER) @GOC_FOR_TARGET@
 GDC_FOR_TARGET=$(STAGE_CC_WRAPPER) @GDC_FOR_TARGET@
+GM2_FOR_TARGET=$(STAGE_CC_WRAPPER) @GM2_FOR_TARGET@
 DLLTOOL_FOR_TARGET=@DLLTOOL_FOR_TARGET@
 LD_FOR_TARGET=@LD_FOR_TARGET@
 
@@ -646,6 +652,7 @@
 	'GFORTRAN=$(GFORTRAN)' \
 	'GOC=$(GOC)' \
 	'GDC=$(GDC)' \
+	'GM2=$(GM2)' \
 	'LD=$(LD)' \
 	'LIPO=$(LIPO)' \
 	'NM=$(NM)' \
@@ -706,6 +713,8 @@
 	'GOCFLAGS=$$(GOCFLAGS_FOR_TARGET)' \
 	'GDC=$$(GDC_FOR_TARGET) $$(XGCC_FLAGS_FOR_TARGET) $$(TFLAGS)' \
 	'GDCFLAGS=$$(GDCFLAGS_FOR_TARGET)' \
+	'GM2=$$(GM2_FOR_TARGET) $$(XGCC_FLAGS_FOR_TARGET) $$(TFLAGS)' \
+	'GM2FLAGS=$$(GM2FLAGS_FOR_TARGET)' \
 	'LD=$(COMPILER_LD_FOR_TARGET)' \
 	'LDFLAGS=$$(LDFLAGS_FOR_TARGET)' \
 	'LIBCFLAGS=$$(LIBCFLAGS_FOR_TARGET)' \


here are the proposed new files which should be untarred will create a
new directory, gcc-version/gcc/m2
(cd gcc-version/gcc ; tar zxf m2.tar.gz).

Attachment: m2.tar.gz
Description: m2 directory files

regards,
Gaius

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