[m-dev.] diff: GCC back-end: don't invoke it twice

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Feb 1 05:12:04 AEDT 2001


Estimated hours taken: 1.5

compiler/mlds_to_gcc.m:
	Reset progname after we return from toplev_main(),
	to avoid confusing MC_in_gcc().
	
	When we try to invoke the gcc back-end more than once,
	abort nicely with a "Sorry, not implemented: ..." message,
	rather aborting with an obscure gcc internal compiler error.

Workspace: /home/hg/fjh/gcc-cvs/gcc/mercury
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.28
diff -u -d -r1.28 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	2001/01/31 16:20:26	1.28
+++ compiler/mlds_to_gcc.m	2001/01/31 18:08:55
@@ -269,6 +269,8 @@
 void MC_continue_frontend(void);
 
 #include ""mercury_wrapper.h""		/* for MR_make_argv() */
+#include <stdio.h>			/* for fprintf() */
+#include <stdlib.h>			/* for exit() */
 ").
 
 :- pragma c_code("
@@ -308,14 +310,49 @@
 	char **argv;
 	int argc;
 	const char *error_msg;
+	static int num_calls = 0;
 
+	/*
+	** The gcc back-end cannot be called more than once.
+	** If you try, it uses up all available memory.
+	** So we need to abort nicely in that case.
+	**
+	** That case will happen if (a) there were nested
+	** sub-modules or (b) the user specified more than
+	** one module on the command line.
+	*/
+	num_calls++;
+	if (num_calls > 1) {
+		fprintf(stderr, ""Sorry, not implemented:\\n""
+			""compiling more than one module at a time ""
+			""with `--target asm'.\\n""
+			""Please use separate sub-modules ""
+			""rather than nested sub-modules,\\n""
+			""i.e. put each sub-module in its own file, ""
+			""and don't specify more\\n""
+			""than one module on the command line ""
+			""(use Mmake instead).\\n""
+			""Or alternatively, just use `--target c'.\\n"");
+		exit(EXIT_FAILURE);
+	}
+
 	error_msg = MR_make_argv(all_args, &args, &argv, &argc);
 	if (error_msg) {
-		MR_fatal_error(""error parsing GCC back-end arguments:\n%s\n"",
+		fprintf(stderr,
+			""Error parsing GCC back-end arguments:\n%s\n"",
 			error_msg);
+		exit(EXIT_FAILURE);
 	}
+
 	merc_continue_frontend = &MC_continue_frontend;
 	*result = toplev_main(argc, argv);
+
+	/*
+	** Reset GCC's progname after we return from toplev_main(),
+	** so that MC_in_gcc() knows that we're no longer in GCC. 
+	*/
+	progname = NULL;
+
 	MR_GC_free(args);
 	MR_GC_free(argv);
 }

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list