[m-dev.] diff: GCC back-end: misc changes needed for bootstrapping

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 29 17:46:06 AEDT 2001


Estimated hours taken: 20

Various fixes to get the GCC back-end interface to bootstrap.

library/exception.m:
	Define function versions of mercury__exception__builtin_catch_3_p_*.
	This is needed (a) in case we take their address, and (b) for the
	GCC back-end interface, where we can't use C macros, since we're
	compiling to assembler.

browser/dl.m:
browser/util.m:
browser/interactive_query.m:
compiler/stack_layout.m:
	Add #includes for header files needed by these modules.

browser/dl.m:
	Delete an unnecessary nested extern declaration, to avoid
	a warning from `gcc -Wshadow'.

compiler/mlds_to_gcc.m:
	When calling mlds_to_c to process foreign_code, make all
	definitions public, so that the can be used from the assembler
	code that we generate in mlds_to_gcc.

	Don't call mlds_to_c to generate `.c' and `.h' files if the
	module contains only `pragma foreign_decls', not `pragma
	foreign_code', `pragma foreign_proc', or `pragma export'.
	This change is needed to avoid calling mlds_to_c when
	intermodule optimization is enabled and `pragma c_header_code'
	declarations have been read in from the `.opt' file and have
	propagated through to the MLDS.  Calling mlds_to_c when the
	module itself doesn't contain C code breaks things, since
	Mmake won't compile and link in the generated `.c' files, but
	those files contain the definition of the `*__init_type_tables()'
	functions that are referenced by `*_init.c'.

	XXX This is not quite right, since if the module itself contains
	`pragma foreign_decls', the `.h' file might be needed.  
	But the Mercury standard library needs intermodule optimization
	enabled for `make install' to work.
	A better fix would be to ignore foreign_decls that were defined
	in other modules, but to call mlds_to_c for foreign_decls
	that were defined in the module that we're compiling.

compiler/modules.m:
	Change the code which decides when to link in extra object files
	for foreign code to reflect the above change to when mlds_to_gcc.m
	invokes mlds_to_c.m.

compiler/mlds_to_c.m:
	When target=asm, i.e. we're compiling to asm, but mlds_to_c.m
	has been invoked to generate C code for a `foreign_code',
	`foreign_proc', or `pragma export' declaration, don't generate
	#include directives for the imported modules, since we may not
	have generated any header file for them.

	XXX This is a bit of a hack; it might sometimes lead to
	problems, since the header files might sometimes be needed.
	But including them unconditionally is definitely wrong,
	since they may not exist, and so this change is needed to get
	the compiler to bootstrap.

compiler/Mmakefile:
	Add a dependency of mercury_compile on $(GCC_BACK_END_LIBS),
	so that we know to relink it if the GCC back-end has changed.
	(That variable is set to empty if we're not linking in the GCC
	back-end, so it won't cause problems when not using the GCC
	back-end.)

library/Mmakefile:
browser/Mmakefile:
compiler/Mmakefile:
	Add an `ss' target, for use by tools/bootcheck.

tools/bootcheck:
	Add `--target asm' option.  If that is set, pass `--target asm'
	to mmake, and build and compare the stage 3 `.s' files rather
	than the `.c' files.

	Also add `--make-opts' option, for passing options to `make'.
	Put `-k' in `--make-opts', not `--mmake-opts', since `-k' is
	an option to `make', not to `mmake'.  This makes a difference
	since although `make' options can be passed to `mmake', any
	options after the first `make' option are assumed to be
	options to `make', not to `mmake'.

----------

I've enclosed below both a relative diff and a full diff.
The relative diff is relative to the diff that I posted earlier
(without any log message).

----------
RELATIVE DIFF
----------
diff -u compiler/Mmakefile compiler/Mmakefile
--- compiler/Mmakefile
+++ compiler/Mmakefile
@@ -250,9 +250,10 @@
 
 #-----------------------------------------------------------------------------#
 
-.PHONY: os cs
+.PHONY: os cs ss
 os: $(mercury_compile.os) $(os_subdir)mercury_compile_init.$O
 cs: $(mercury_compile.cs) $(cs_subdir)mercury_compile_init.c
+ss: $(mercury_compile.ss)
 
 #-----------------------------------------------------------------------------#
 
diff -u compiler/mlds_to_gcc.m compiler/mlds_to_gcc.m
--- compiler/mlds_to_gcc.m
+++ compiler/mlds_to_gcc.m
@@ -353,6 +353,29 @@
 	{ list__filter(defn_contains_foreign_code(lang_asm), Defns0,
 		ForeignDefns, Defns) },
 	(
+		% Check if there is any code from pragma foreign_code,
+		% pragma export, or pragma foreign_proc declarations.
+		%
+		% We don't call mlds_to_c to generate `.c' and `.h' files
+		% if the module contains only `pragma foreign_decls'.
+		% This is needed to avoid calling mlds_to_c when intermodule
+		% optimization is enabled and `pragma foreign_decls'
+		% declarations have been read in from the `.opt' files
+		% and have propagated through to the MLDS.
+		% Calling mlds_to_c when the module itself doesn't contain
+		% C code breaks things, since Mmake won't compile and link
+		% in the generated `.c' files, but those files contain the
+		% definition of the `*__init_type_tables()' functions that
+		% are referenced by `*_init.c'.
+		%
+		% XXX This is not quite right, since if the module itself
+		% contains `pragma foreign_decls', the `.h' file might
+		% be needed.  But the Mercury standard library needs
+		% intermodule optimization enabled for `make install'
+		% to work.  A better fix would be to ignore foreign_decls
+		% that were defined in other modules, but to call mlds_to_c
+		% for foreign_decls that were defined in the module that
+		% we're compiling.
 		{ ForeignCode = mlds__foreign_code(_Decls, [], []) },
 		{ ForeignDefns = [] }
 	->
diff -u compiler/modules.m compiler/modules.m
--- compiler/modules.m
+++ compiler/modules.m
@@ -3255,9 +3255,12 @@
 item_list_contains_foreign_code([Item|Items]) :-
 	(
 		Item = pragma(Pragma) - _Context,
-		% Note that we do NOT count foreign_decls here.
-		% We should only need to link in a foreign object file
-		% if there is some foriegn_code, not just foreign_decls.
+		% The code here should match the way that mlds_to_gcc.m
+		% decides whether or not to call mlds_to_c.m.
+		% XXX Note that we do NOT count foreign_decls here.
+		% We only link in a foreign object file if mlds_to_gcc
+		% called mlds_to_c.m to generate it, which it will only
+		% do if there is some foreign_code, not just foreign_decls.
 		% Counting foreign_decls here causes problems with
 		% intermodule optimization.
 		(	Pragma = foreign(_Lang, _)
diff -u tools/bootcheck tools/bootcheck
--- tools/bootcheck
+++ tools/bootcheck
@@ -106,7 +106,7 @@
 do_bootcheck=true
 check_namespace=true
 grade=
-target_opt=
+target=c
 test_grade=
 test_params=false
 copy_runtime=false
@@ -169,7 +169,11 @@
 		outfile="` expr $1 : '-o\(.*\)' `"; ;;
 
 	--target)
-		target_opt="--target $2"; shift ;;
+		case "$2" in
+		c|asm)	target="$2"; shift ;;
+		*)	echo "unknown target \`$2'" 1>&2; exit 1 ;;
+		esac
+		;;
 
 	-G|--grade)
 		grade="$2"; shift ;;
@@ -248,8 +252,26 @@
 
 case $use_subdirs in
 	yes)	cs_subdir=Mercury/cs/
+		ss_subdir=Mercury/ss/
 		;;
 	no)	cs_subdir=
+		ss_subdir=
+		;;
+esac
+
+case $target in
+	c)	target_ext=c
+		target_subdir=$cs_subdir
+		target_opt=
+		;;
+	asm)	target_ext=s
+		target_subdir=$ss_subdir
+		target_opt="--target asm"
+		# If the stage 1 directory was built without --target asm, 
+		# but the stage 2 will be built with `--target asm',
+		# then we need to copy the profiler directory.
+		# So to be safe, we just enable this by default.
+		copy_profiler=true
 		;;
 esac
 
@@ -651,7 +673,7 @@
 
 	if 	(cd stage3/library &&
 		$MMAKE $mmake_opts $jfactor all-ints &&
-		$MMAKE $mmake_opts $jfactor cs)
+		$MMAKE $mmake_opts $jfactor ${target_ext}s)
 	then
 		echo "building of stage 3 library successful"
 	else
@@ -660,7 +682,7 @@
 		# try again, in case the failure cause was transient
 		if 	(cd stage3/library &&
 			$MMAKE $mmake_opts $jfactor all-ints &&
-			$MMAKE $mmake_opts $jfactor cs)
+			$MMAKE $mmake_opts $jfactor ${target_ext}s)
 		then
 			echo "building of stage 3 library successful"
 		else
@@ -683,14 +705,14 @@
 		xargs /bin/rm -f
 	fi
 
-	if (cd stage3/browser && $MMAKE $mmake_opts $jfactor cs)
+	if (cd stage3/browser && $MMAKE $mmake_opts $jfactor ${target_ext}s)
 	then
 		echo "building of stage 3 browser successful"
 	else
 		echo "building of stage 3 browser initially not successful"
 		df .
 		# try again, in case the failure cause was transient
-		if (cd stage3/browser && $MMAKE $mmake_opts $jfactor cs)
+		if (cd stage3/browser && $MMAKE $mmake_opts $jfactor ${target_ext}s)
 		then
 			echo "building of stage 3 browser successful"
 		else
@@ -699,14 +721,14 @@
 		fi
 	fi
 
-	if (cd stage3/compiler && $MMAKE $mmake_opts $jfactor cs)
+	if (cd stage3/compiler && $MMAKE $mmake_opts $jfactor ${target_ext}s)
 	then
 		echo "building of stage 3 compiler successful"
 	else
 		echo "building of stage 3 compiler initially not successful"
 		df .
 		# try again, in case the failure cause was transient
-		if (cd stage3/compiler && $MMAKE $mmake_opts $jfactor cs)
+		if (cd stage3/compiler && $MMAKE $mmake_opts $jfactor ${target_ext}s)
 		then
 			echo "building of stage 3 compiler successful"
 		else
@@ -731,7 +753,7 @@
 	fi
 
 	for dir in library browser compiler; do
-		for file in stage2/$dir/${cs_subdir}*.c; do
+		for file in stage2/$dir/${target_subdir}*.${target_ext}; do
 		    diff -u $file stage3/$dir/${cs_subdir}`basename $file` ||
 			diff_status=1
 		done
only in patch2:
--- library/Mmakefile	2001/01/01 04:03:48	1.55
+++ library/Mmakefile	2001/01/28 14:24:38
@@ -194,9 +194,10 @@
 
 #-----------------------------------------------------------------------------#
 
-.PHONY: os cs ils library.dlls dlls
+.PHONY: os cs ss ils library.dlls dlls
 os: $(library.os)
 cs: $(library.cs)
+ss: $(library.ss)
 ils: $(library.ils)
 library.dlls = $(library.mods:%=%.dll)
 dlls: $(library.dlls)
only in patch2:
--- browser/Mmakefile	2000/08/17 05:30:56	1.12
+++ browser/Mmakefile	2001/01/28 14:24:51
@@ -121,9 +121,10 @@
 
 #-----------------------------------------------------------------------------#
 
-.PHONY: os cs
+.PHONY: os cs ss
 os: $(mdb.os)
 cs: $(mdb.cs)
+ss: $(mdb.ss)
 
 #-----------------------------------------------------------------------------#

----------
FULL DIFF
----------

Workspace: /home/hg/fjh/gcc-cvs/gcc/mercury
Index: browser/dl.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/dl.m,v
retrieving revision 1.7
diff -u -d -r1.7 dl.m
--- browser/dl.m	2001/01/18 01:18:25	1.7
+++ browser/dl.m	2001/01/25 16:07:48
@@ -63,6 +63,7 @@
 :- pragma c_header_code("
 	#include <stdio.h>
 	#include ""mercury_conf.h""
+	#include ""mercury_string.h""	/* for MR_make_aligned_string_copy() */
 #ifdef HAVE_DLFCN_H
 	#include <dlfcn.h>
 #endif
@@ -180,7 +181,6 @@
 :- pragma foreign_code("C", make_closure_layout = (ClosureLayout::out),
 	[will_not_call_mercury, thread_safe],
 "{
-	extern	int			ML_DL_closure_counter;
 	MR_Closure_Id			*closure_id;
 	MR_Closure_Dyn_Link_Layout	*closure_layout;
 	char				buf[80];
Index: browser/interactive_query.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/interactive_query.m,v
retrieving revision 1.8
diff -u -d -r1.8 interactive_query.m
--- browser/interactive_query.m	2000/10/16 01:33:23	1.8
+++ browser/interactive_query.m	2001/01/25 16:03:55
@@ -443,7 +443,10 @@
 % executable was compiled in, in a form suitable for
 % passing as a `--grade' option to mmc or ml.
 %
-:- pragma c_header_code("#include ""mercury_grade.h""").
+:- pragma c_header_code("
+	#include ""mercury_grade.h""
+	#include ""mercury_string.h""
+").
 :- pragma c_code(grade_option = (GradeOpt::out),
 	[thread_safe, will_not_call_mercury],
 	"MR_make_aligned_string(GradeOpt, (MR_String) MR_GRADE_OPT);").
Index: browser/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/Mmakefile,v
retrieving revision 1.12
diff -u -d -r1.12 Mmakefile
--- browser/Mmakefile	2000/08/17 05:30:56	1.12
+++ browser/Mmakefile	2001/01/28 14:24:51
@@ -121,9 +121,10 @@
 
 #-----------------------------------------------------------------------------#
 
-.PHONY: os cs
+.PHONY: os cs ss
 os: $(mdb.os)
 cs: $(mdb.cs)
+ss: $(mdb.ss)
 
 #-----------------------------------------------------------------------------#
 
Index: browser/util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/util.m,v
retrieving revision 1.11
diff -u -d -r1.11 util.m
--- browser/util.m	2000/10/01 03:13:40	1.11
+++ browser/util.m	2001/01/25 16:01:41
@@ -101,6 +101,7 @@
 	#include ""mercury_string.h""
 	#include ""mercury_trace_base.h""
 	#include ""mercury_trace_internal.h""
+	#include ""mercury_library_types.h""
 ").
 
 :- pragma c_code(call_trace_getline(MdbIn::in, MdbOut::in, Prompt::in,
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.77
diff -u -d -r1.77 mlds_to_c.m
--- compiler/mlds_to_c.m	2001/01/17 17:37:17	1.77
+++ compiler/mlds_to_c.m	2001/01/25 15:52:42
@@ -162,7 +162,19 @@
 :- mode mlds_output_src_imports(in, in, di, uo) is det.
 
 mlds_output_src_imports(Indent, Imports) -->
-	list__foldl(mlds_output_src_import(Indent), Imports).
+	globals__io_get_target(Target),
+	( { Target = asm } ->
+		% For --target asm, we don't create the header files
+		% for modules that don't contain C code, so we'd better
+		% not include them, since they might not exist.
+		% XXX This is a hack; it may lead to warnings or errors
+		% when compiling the generated code, since the functions
+		% that we call (e.g. for `pragma export') may not have
+		% been declared.
+		[]
+	;
+		list__foldl(mlds_output_src_import(Indent), Imports)
+	).
 
 :- pred mlds_output_src_import(indent, mlds__import, io__state, io__state).
 :- mode mlds_output_src_import(in, in, di, uo) is det.
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.26
diff -u -d -r1.26 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	2001/01/24 06:27:52	1.26
+++ compiler/mlds_to_gcc.m	2001/01/29 06:39:54
@@ -353,7 +353,30 @@
 	{ list__filter(defn_contains_foreign_code(lang_asm), Defns0,
 		ForeignDefns, Defns) },
 	(
-		{ ForeignCode = mlds__foreign_code([], [], []) },
+		% Check if there is any code from pragma foreign_code,
+		% pragma export, or pragma foreign_proc declarations.
+		%
+		% We don't call mlds_to_c to generate `.c' and `.h' files
+		% if the module contains only `pragma foreign_decls'.
+		% This is needed to avoid calling mlds_to_c when intermodule
+		% optimization is enabled and `pragma foreign_decls'
+		% declarations have been read in from the `.opt' files
+		% and have propagated through to the MLDS.
+		% Calling mlds_to_c when the module itself doesn't contain
+		% C code breaks things, since Mmake won't compile and link
+		% in the generated `.c' files, but those files contain the
+		% definition of the `*__init_type_tables()' functions that
+		% are referenced by `*_init.c'.
+		%
+		% XXX This is not quite right, since if the module itself
+		% contains `pragma foreign_decls', the `.h' file might
+		% be needed.  But the Mercury standard library needs
+		% intermodule optimization enabled for `make install'
+		% to work.  A better fix would be to ignore foreign_decls
+		% that were defined in other modules, but to call mlds_to_c
+		% for foreign_decls that were defined in the module that
+		% we're compiling.
+		{ ForeignCode = mlds__foreign_code(_Decls, [], []) },
 		{ ForeignDefns = [] }
 	->
 		{ ContainsCCode = no },
@@ -362,9 +385,10 @@
 		{ NeedInitFn = yes }
 	;
 		% create a new MLDS containing just the foreign code
-		% and pass that to mlds_to_c.m
+		% (with all definitions made public, so we can use
+		% them from the asm file!) and pass that to mlds_to_c.m
 		{ ForeignMLDS = mlds(ModuleName, ForeignCode, Imports,
-			ForeignDefns) },
+			list__map(make_public, ForeignDefns)) },
 		mlds_to_c__output_mlds(ForeignMLDS),
 		% XXX currently the only foreign code we handle is C;
 		%     see comments above (at the declaration for
@@ -436,6 +460,11 @@
 	io__write_string(
 		"static const void *const MR_grade = &MR_GRADE_VAR;\n").
 ******/
+
+:- func make_public(mlds__defn) = mlds__defn.
+make_public(mlds__defn(Name, Context, Flags0, Defn)) =
+	    mlds__defn(Name, Context, Flags, Defn) :-
+	Flags = mlds__set_access(Flags0, public).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Mmakefile,v
retrieving revision 1.40
diff -u -d -r1.40 Mmakefile
--- compiler/Mmakefile	2001/01/18 12:07:57	1.40
+++ compiler/Mmakefile	2001/01/28 14:25:46
@@ -26,6 +26,7 @@
 GCC_MAIN_LIBS = $(patsubst %,$(GCC_SRC_DIR)/gcc/%,$(filter-out -l%,$(GCC_LIBS)))
 GCC_BACKEND_LIBS = $(GCC_MAIN_LIBS) $(GCC_EXTRA_LIBS)
 else
+GCC_MAIN_LIBS =
 GCC_BACKEND_LIBS =
 endif
 
@@ -220,6 +221,7 @@
 # Should also depend on $(BOEHM_GC_DIR)/libgc(_prof).$A, but only
 # if in .gc(.prof) grade; GNU make does not support dynamic dependencies,
 # so just leave it out.
+mercury_compile: $(GCC_MAIN_LIBS)
 
 mercury_compile_init.c: $(UTIL_DIR)/mkinit
 
@@ -248,9 +250,10 @@
 
 #-----------------------------------------------------------------------------#
 
-.PHONY: os cs
+.PHONY: os cs ss
 os: $(mercury_compile.os) $(os_subdir)mercury_compile_init.$O
 cs: $(mercury_compile.cs) $(cs_subdir)mercury_compile_init.c
+ss: $(mercury_compile.ss)
 
 #-----------------------------------------------------------------------------#
 
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.146
diff -u -d -r1.146 modules.m
--- compiler/modules.m	2001/01/24 13:18:15	1.146
+++ compiler/modules.m	2001/01/29 06:37:59
@@ -3255,8 +3255,15 @@
 item_list_contains_foreign_code([Item|Items]) :-
 	(
 		Item = pragma(Pragma) - _Context,
-		(	Pragma = foreign_decl(_Lang, _)
-		;	Pragma = foreign(_Lang, _)
+		% The code here should match the way that mlds_to_gcc.m
+		% decides whether or not to call mlds_to_c.m.
+		% XXX Note that we do NOT count foreign_decls here.
+		% We only link in a foreign object file if mlds_to_gcc
+		% called mlds_to_c.m to generate it, which it will only
+		% do if there is some foreign_code, not just foreign_decls.
+		% Counting foreign_decls here causes problems with
+		% intermodule optimization.
+		(	Pragma = foreign(_Lang, _)
 		;	Pragma = foreign(_, _, _, _, _, _)
 		;	% XXX `pragma export' should not be treated as
 			% foreign, but currently mlds_to_gcc.m doesn't
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.59
diff -u -d -r1.59 stack_layout.m
--- compiler/stack_layout.m	2001/01/18 01:18:54	1.59
+++ compiler/stack_layout.m	2001/01/25 16:43:27
@@ -143,6 +143,12 @@
 :- pred stack_layout__concat_string_list(list(string)::in, int::in,
 	string::out) is det.
 
+:- pragma c_header_code("
+	#include ""mercury_tags.h""	/* for MR_list_*() */
+	#include ""mercury_heap.h""	/* for MR_incr_hp_atomic*() */
+	#include ""mercury_misc.h""	/* for MR_fatal_error() */
+").
+
 :- pragma c_code(stack_layout__concat_string_list(StringList::in,
 		ArenaSize::in, Arena::out),
 		[will_not_call_mercury, thread_safe], "{
Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.41
diff -u -d -r1.41 exception.m
--- library/exception.m	2001/01/18 01:19:03	1.41
+++ library/exception.m	2001/01/25 18:19:27
@@ -557,8 +557,56 @@
 %
 
 :- pragma c_header_code("
+/* protect against multiple inclusion */
+#ifndef MR_HLC_EXCEPTION_GUARD
+#define MR_HLC_EXCEPTION_GUARD
+
 #ifdef MR_HIGHLEVEL_CODE
 
+  #ifdef MR_USE_GCC_NESTED_FUNCTIONS
+  	#define MR_CONT_PARAMS		MR_NestedCont cont
+  	#define MR_CONT_PARAM_TYPES	MR_NestedCont
+  	#define MR_CONT_ARGS		cont
+  #else
+  	#define MR_CONT_PARAMS		MR_Cont cont, void *cont_env
+  	#define MR_CONT_PARAM_TYPES	MR_Cont, void *
+  	#define MR_CONT_ARGS		cont, cont_env
+  #endif
+
+	/* det */
+	void MR_CALL
+	mercury__exception__builtin_catch_3_p_0(MR_Mercury_Type_Info type_info,
+		MR_Pred pred, MR_Pred handler_pred, MR_Box *output);
+
+	/* semidet */
+	bool MR_CALL
+	mercury__exception__builtin_catch_3_p_1(MR_Mercury_Type_Info type_info,
+		MR_Pred pred, MR_Pred handler_pred, MR_Box *output);
+
+	/* cc_multi */
+	void MR_CALL
+	mercury__exception__builtin_catch_3_p_2(MR_Mercury_Type_Info type_info,
+		MR_Pred pred, MR_Pred handler_pred, MR_Box *output);
+
+	/* cc_nondet */
+	bool MR_CALL
+	mercury__exception__builtin_catch_3_p_3(MR_Mercury_Type_Info type_info,
+		MR_Pred pred, MR_Pred handler_pred, MR_Box *output);
+
+	/* multi */
+	void MR_CALL
+	mercury__exception__builtin_catch_3_p_4(MR_Mercury_Type_Info type_info,
+		MR_Pred pred, MR_Pred handler_pred, MR_Box *output,
+		MR_CONT_PARAMS);
+
+	/* nondet */
+	void MR_CALL
+	mercury__exception__builtin_catch_3_p_5(MR_Mercury_Type_Info type_info,
+		MR_Pred pred, MR_Pred handler_pred, MR_Box *output,
+		MR_CONT_PARAMS);
+
+  #ifndef MR_AVOID_MACROS
+
 	/* det ==> model_det */
 	#define mercury__exception__builtin_catch_3_p_0 \
 		mercury__exception__builtin_catch_model_det
@@ -583,9 +631,10 @@
 	#define mercury__exception__builtin_catch_3_p_5 \
 		mercury__exception__builtin_catch_model_non
 
-	void MR_CALL mercury__exception__builtin_throw_1_p_0(MR_Univ);
+  #endif /* !MR_AVOID_MACROS */
 
 	void MR_CALL mercury__exception__builtin_throw_1_p_0(MR_Univ exception);
+
 	void MR_CALL mercury__exception__builtin_catch_model_det(
 		MR_Mercury_Type_Info type_info, MR_Pred pred,
 		MR_Pred handler_pred, MR_Box *output);
@@ -595,18 +644,86 @@
 	void MR_CALL mercury__exception__builtin_catch_model_non(
 		MR_Mercury_Type_Info type_info, MR_Pred pred,
 		MR_Pred handler_pred, MR_Box *output,
-#ifdef MR_USE_GCC_NESTED_FUNCTIONS
-		MR_NestedCont cont
-#else
-		MR_Cont cont, void *cont_env
-#endif
-	);
+		MR_CONT_PARAMS);
+
 #endif /* MR_HIGHLEVEL_CODE */
+
+#endif /* MR_HLC_EXCEPTION_GUARD */
 ").
 
 :- pragma c_code("
 #ifdef MR_HIGHLEVEL_CODE
 
+/*
+** We also need to provide definitions of these builtins
+** as functions rather than as macros.  This is needed
+** (a) in case we take their address, and (b) for the
+** GCC back-end interface.
+*/
+
+#undef mercury__exception__builtin_catch_3_p_0
+#undef mercury__exception__builtin_catch_3_p_1
+#undef mercury__exception__builtin_catch_3_p_2
+#undef mercury__exception__builtin_catch_3_p_3
+#undef mercury__exception__builtin_catch_3_p_4
+#undef mercury__exception__builtin_catch_3_p_5
+
+/* det ==> model_det */
+void MR_CALL
+mercury__exception__builtin_catch_3_p_0(MR_Mercury_Type_Info type_info,
+	MR_Pred pred, MR_Pred handler_pred, MR_Box *output)
+{
+	mercury__exception__builtin_catch_model_det(type_info,
+		pred, handler_pred, output);
+}
+
+/* semidet ==> model_semi */
+bool MR_CALL
+mercury__exception__builtin_catch_3_p_1(MR_Mercury_Type_Info type_info,
+	MR_Pred pred, MR_Pred handler_pred, MR_Box *output)
+{
+	return mercury__exception__builtin_catch_model_semi(type_info,
+		pred, handler_pred, output);
+}
+
+/* cc_multi ==> model_det */
+void MR_CALL
+mercury__exception__builtin_catch_3_p_2(MR_Mercury_Type_Info type_info,
+	MR_Pred pred, MR_Pred handler_pred, MR_Box *output)
+{
+	mercury__exception__builtin_catch_model_det(type_info,
+		pred, handler_pred, output);
+}
+
+/* cc_nondet ==> model_semi */
+bool MR_CALL
+mercury__exception__builtin_catch_3_p_3(MR_Mercury_Type_Info type_info,
+	MR_Pred pred, MR_Pred handler_pred, MR_Box *output)
+{
+	return mercury__exception__builtin_catch_model_semi(type_info,
+		pred, handler_pred, output);
+}
+
+/* multi ==> model_non */
+void MR_CALL
+mercury__exception__builtin_catch_3_p_4(MR_Mercury_Type_Info type_info,
+	MR_Pred pred, MR_Pred handler_pred, MR_Box *output,
+	MR_CONT_PARAMS)
+{
+	mercury__exception__builtin_catch_model_non(type_info,
+		pred, handler_pred, output, MR_CONT_ARGS);
+}
+
+/* multi ==> model_non */
+void MR_CALL
+mercury__exception__builtin_catch_3_p_5(MR_Mercury_Type_Info type_info,
+	MR_Pred pred, MR_Pred handler_pred, MR_Box *output,
+	MR_CONT_PARAMS)
+{
+	mercury__exception__builtin_catch_model_non(type_info,
+		pred, handler_pred, output, MR_CONT_ARGS);
+}
+
 /*---------------------------------------------------------------------------*/
 
 static void
@@ -629,31 +746,16 @@
 	return (*code)((void *) closure, result);
 }
 
-#ifdef MR_USE_GCC_NESTED_FUNCTIONS
-
-static void
-ML_call_goal_non(MR_Mercury_Type_Info type_info,
-	MR_Pred closure, MR_Box *result, MR_NestedCont cont)
-{
-	typedef void MR_CALL NondetFuncType(void *, MR_Box *, MR_NestedCont);
-	NondetFuncType *code = (NondetFuncType *)
-		MR_field(MR_mktag(0), closure, (MR_Integer) 1);
-	(*code)((void *) closure, result, cont);
-}
-
-#else
-
 static void
 ML_call_goal_non(MR_Mercury_Type_Info type_info,
-	MR_Pred closure, MR_Box *result, MR_Cont cont, void *cont_env)
+	MR_Pred closure, MR_Box *result, MR_CONT_PARAMS)
 {
-	typedef void MR_CALL NondetFuncType(void *, MR_Box *, MR_Cont, void *);
+	typedef void MR_CALL NondetFuncType(void *, MR_Box *,
+		MR_CONT_PARAM_TYPES);
 	NondetFuncType *code = (NondetFuncType *)
 		MR_field(MR_mktag(0), closure, (MR_Integer) 1);
-	(*code)((void *) closure, result, cont, cont_env);
+	(*code)((void *) closure, result, MR_CONT_ARGS);
 }
-
-#endif
 
 /*---------------------------------------------------------------------------*/
 
Index: library/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/library/Mmakefile,v
retrieving revision 1.55
diff -u -d -r1.55 Mmakefile
--- library/Mmakefile	2001/01/01 04:03:48	1.55
+++ library/Mmakefile	2001/01/28 14:24:38
@@ -194,9 +194,10 @@
 
 #-----------------------------------------------------------------------------#
 
-.PHONY: os cs ils library.dlls dlls
+.PHONY: os cs ss ils library.dlls dlls
 os: $(library.os)
 cs: $(library.cs)
+ss: $(library.ss)
 ils: $(library.ils)
 library.dlls = $(library.mods:%=%.dll)
 dlls: $(library.dlls)
Index: tools/bootcheck
===================================================================
RCS file: /home/mercury1/repository/mercury/tools/bootcheck,v
retrieving revision 1.111
diff -u -d -r1.111 bootcheck
--- tools/bootcheck	2001/01/18 12:52:10	1.111
+++ tools/bootcheck	2001/01/29 03:35:28
@@ -24,8 +24,12 @@
 		Keep the stage 2 object files even if stage 2 is successful.
 	-m <mmake-args>, --mmake-opts <mmake-args>
 		Pass <mmake-args> as options to \`mmake'.
+	-M <make-args>, --make-opts <make-args>
+		Pass <make-args> as options to \`make'.
 	-o <filename>, --output-file <filename>
 		Output results to <filename>.
+	--target <target>
+		Specify the target to use in creating stages 2 and 3.
 	-G <grade>, --grade <grade>
 		Specify the grade to use in creating stages 2 and 3.
 		The tests will also be executed in this grade, unless
@@ -95,12 +99,14 @@
 extras=false
 jfactor=""
 keep_objs=false
-mmake_opts="-k"
+mmake_opts=""
+make_opts="-k"
 outfile=""
 runtests=true
 do_bootcheck=true
 check_namespace=true
 grade=
+target=c
 test_grade=
 test_params=false
 copy_runtime=false
@@ -152,14 +158,23 @@
 	-k|--keep-objs)
 		keep_objs=true ;;
 
-	-m|--mmake)
+	-m|--mmake|--mmake-opts)
 		mmake_opts="$mmake_opts $2"; shift ;;
+	-M|--make-opts)
+		make_opts="$make_opts $2"; shift ;;
 
 	-o|--output-file)
 		outfile="$2"; shift ;;
 	-o*)
 		outfile="` expr $1 : '-o\(.*\)' `"; ;;
 
+	--target)
+		case "$2" in
+		c|asm)	target="$2"; shift ;;
+		*)	echo "unknown target \`$2'" 1>&2; exit 1 ;;
+		esac
+		;;
+
 	-G|--grade)
 		grade="$2"; shift ;;
 	-G*)
@@ -237,9 +252,27 @@
 
 case $use_subdirs in
 	yes)	cs_subdir=Mercury/cs/
+		ss_subdir=Mercury/ss/
 		;;
 	no)	cs_subdir=
+		ss_subdir=
+		;;
+esac
+
+case $target in
+	c)	target_ext=c
+		target_subdir=$cs_subdir
+		target_opt=
 		;;
+	asm)	target_ext=s
+		target_subdir=$ss_subdir
+		target_opt="--target asm"
+		# If the stage 1 directory was built without --target asm, 
+		# but the stage 2 will be built with `--target asm',
+		# then we need to copy the profiler directory.
+		# So to be safe, we just enable this by default.
+		copy_profiler=true
+		;;
 esac
 
 if test "$grade" != "" -o "$test_grade" != ""
@@ -465,6 +498,7 @@
 
 	# Use the new mmake to build stage 2
 	MMAKE=$MMAKE_DIR/mmake
+	mmake_opts="$mmake_opts $target_opt"
 
 	if (cd stage2 && $MMAKE $mmake_opts $jfactor runtime)
 	then
@@ -639,7 +673,7 @@
 
 	if 	(cd stage3/library &&
 		$MMAKE $mmake_opts $jfactor all-ints &&
-		$MMAKE $mmake_opts $jfactor cs)
+		$MMAKE $mmake_opts $jfactor ${target_ext}s)
 	then
 		echo "building of stage 3 library successful"
 	else
@@ -648,7 +682,7 @@
 		# try again, in case the failure cause was transient
 		if 	(cd stage3/library &&
 			$MMAKE $mmake_opts $jfactor all-ints &&
-			$MMAKE $mmake_opts $jfactor cs)
+			$MMAKE $mmake_opts $jfactor ${target_ext}s)
 		then
 			echo "building of stage 3 library successful"
 		else
@@ -671,14 +705,14 @@
 		xargs /bin/rm -f
 	fi
 
-	if (cd stage3/browser && $MMAKE $mmake_opts $jfactor cs)
+	if (cd stage3/browser && $MMAKE $mmake_opts $jfactor ${target_ext}s)
 	then
 		echo "building of stage 3 browser successful"
 	else
 		echo "building of stage 3 browser initially not successful"
 		df .
 		# try again, in case the failure cause was transient
-		if (cd stage3/browser && $MMAKE $mmake_opts $jfactor cs)
+		if (cd stage3/browser && $MMAKE $mmake_opts $jfactor ${target_ext}s)
 		then
 			echo "building of stage 3 browser successful"
 		else
@@ -687,14 +721,14 @@
 		fi
 	fi
 
-	if (cd stage3/compiler && $MMAKE $mmake_opts $jfactor cs)
+	if (cd stage3/compiler && $MMAKE $mmake_opts $jfactor ${target_ext}s)
 	then
 		echo "building of stage 3 compiler successful"
 	else
 		echo "building of stage 3 compiler initially not successful"
 		df .
 		# try again, in case the failure cause was transient
-		if (cd stage3/compiler && $MMAKE $mmake_opts $jfactor cs)
+		if (cd stage3/compiler && $MMAKE $mmake_opts $jfactor ${target_ext}s)
 		then
 			echo "building of stage 3 compiler successful"
 		else
@@ -719,7 +753,7 @@
 	fi
 
 	for dir in library browser compiler; do
-		for file in stage2/$dir/${cs_subdir}*.c; do
+		for file in stage2/$dir/${target_subdir}*.${target_ext}; do
 		    diff -u $file stage3/$dir/${cs_subdir}`basename $file` ||
 			diff_status=1
 		done

 

-- 
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