for review: interface tracing, part 1

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu May 14 17:23:58 AEST 1998


Estimated hours taken: 50

This change introduces interface tracing, and makes it possible to successfully
bootstrap the compiler with tracing (either interface or full).

compiler/options.m:
	Change the bool options --generate-trace into a string option --trace
	with three valid values: minimal, interface and full. The last two mean
	what they say; the intention is that eventually minimal will mean
	no tracing in non-tracing grades and interface tracing in tracing
	grades.

compiler/globals.m:
	Add a new global for the trace level.

compiler/handle_options.m:
	Convert the argument of --trace to a trace level.

	Use only consistent 4-space indentation in the deeply nested
	if-then-else.

compiler/trace.m:
	Implement interface tracing.

	Rename trace__generate_depth_reset_code as trace__prepare_for_call,
	since it does more than reset the depth if this module is compiled
	with interface tracing.

	Do not check whether tracing is enabled before calling MR_trace;
	let MR_trace make the check. This trades increased non-tracing
	execution time for a substantial code size reduction (which may
	in turn benefit execution time).

compiler/call_gen.m:
	Call trace__generate_depth_reset_code by its new name.

compiler/code_info.m:
	Fix a bug in the handling of non/semi commits. When entering a commit,
	we used to push a clone of whatever the top failure continuation was.
	However, the resume setup for this continuation could have started
	with a label that assumed that the resume vars were in their original
	locations (which are often registers), whereas the method of
	backtracking to that point only guarantees the survival of stack slots,
	not registers.

	(This bug caused two lines of incorrect code to be generated among
	the approx 30 million lines of code in the stage 2 compiler when
	compiled with tracing.)

	Fix another bug (previously untriggered as far as I know) in the
	handling of multi/det commits. This one was breaking the invariant
	that the resume vars set of each entry on the failure continuation
	stack included the resume vars set of every other entry below it,
	which meant that the values of these resume vars were not guaranteed
	to be preserved.

compiler/stack_layout.m:
	Make layout structures local to their module. They are not (yet)
	referred to by name from other modules, and by declaring them
	to be global we caused their names to be included even in stripped
	executables, adding several megabytes to the size of the binary.
	(The names are not stripped because a dynamically linked library
	may want to refer to them.)

	Change the mercury_data__stack_layout__ prefix on the names of
	generated globals vars to just mercury_data__layout__. It is now
	merely too long instead of far too long.

	Include the label number in the label layout structure and the number
	of typeinfo variables in a var_info structure only with native gc.
	Their only use is in debugging native gc.

	Fix some documentation rot.

compiler/llds.m:
	Add a new field to the pragma_c instruction that says whether the
	compiler-generated C code fragments access any stack variables.

compiler/frameopt.m:
	Use the new field in pragma_c's to avoid a bug. Because frameopt was
	assuming that the pragma_c instruction that filled in the stack slots
	containing the call sequence number and depth did not access the stack,
	it moved the pragma_c before the incr_sp that allocates the frame
	(it was trying to get it out of the loop).

compiler/*.m:
	Minor changes to set or ignore the extra field in pragma_c, to refer
	to layout structures via the new prefix, or to handle the --trace
	option.

doc/user_guide.texi:
	Update the documentation for --trace.

runtime/mercury_goto.h:
	Use the shorter layout prefix.

runtime/mercury_stack_layout.h:
	Use the shorter layout prefix, and include the label number only with
	native gc.

runtime/mercury_trace.[ch]:
runtime/mercury_trace_internal.[ch]:
runtime/mercury_trace_external.[ch]:
runtime/mercury_trace_util.[ch]:
	Divide the old mercury_trace.[ch] into several components, with one
	module for the internal debugger, one for the interface to the
	external debugger, one for utilities needed by both. Mercury_trace.c
	now has only the top-level stuff that steers between the two
	debuggers.

runtime/mercury_trace.[ch]:
	Add the new global variable MR_trace_from_full. Before each call,
	the calling procedure assigns TRUE to this variable if the caller
	is fully traced, and FALSE otherwise. Interface traced procedures
	generate trace events only if this variable is TRUE when they are
	called (fully traced callee procedures ignore the initial value of
	the variable).

	Make MR_trace return immediately without doing anything unless
	tracing is enabled and a new extra argument to MR_trace is TRUE.
	This extra argument is always TRUE for trace events in fully traced
	procedures, while for trace events from interface traced procedures,
	its value is set from the value of MR_trace_from_full at the time
	that the procedure was called (i.e. the event is ignored unless the
	interface traced procedure was called from a fully traced procedure).

runtime/mercury_trace.[ch]:
runtime/mercury_trace_internal.[ch]:
	For global variables that are stored in stack slots, make their type
	Word rather than int.

	Use a new function MR_trace_event_report instead of calling
	MR_trace_event with a NULL command structure pointer to indicate
	that the event is to be reported but there is to be no user
	interaction.

	Use %ld formats in printfs and casts to long for better portability.

runtime/mercury_trace_internal.c:
	Save trace-related globals across calls to Mercury library code
	in the debugger, since otherwise any trace events in this code
	could screw up e.g. the event number or the call number sequence.

	Create separate functions for printing port names and determinisms.

runtime/mercury_wrapper.h:
	Disable the tracing of the initialization code written in Mercury.

runtime/Mmakefile:
	Update for the new source and header files.

tests/debugger/{debugger_regs,interpreter,queens}_lib.{m,inp,exp}:
	One new copy of each existing test case. These ones are intended
	to be used when the stage 2 library is compiled with tracing, which
	affects the tests by adding events for the library procedures called
	from the test programs.

	The .m files are the same as before; one of the .inp files is a bit
	different; the .exp files reflect the correct output when the library
	is compiled with full tracing.

tests/debugger/Mmakefile:
	Provide separate targets for the new set of test cases.

	Use --trace full instead of --generate-trace.

tests/debugger/runtests:
	Try both the new set of test cases if the old set fails, and report
	failure only if both sets fail. This is simpler than trying to figure
	out which set should be really tested, and the probability of a false
	positive is negligible.

Zoltan.

This diff will not contain the new files in tests/debugger, since they are
boring and almost exactly like the existing files.

Apart from that, part 1 contains everything but the diffs to
runtime/mercury_trace*.

Index: compiler/basic_block.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/basic_block.m,v
retrieving revision 1.3
diff -u -r1.3 basic_block.m
--- basic_block.m	1998/01/13 10:11:02	1.3
+++ basic_block.m	1998/05/11 03:23:47
@@ -187,7 +187,7 @@
 possible_targets(discard_tickets_to(_), []).
 possible_targets(incr_sp(_, _), []).
 possible_targets(decr_sp(_), []).
-possible_targets(pragma_c(_, _, _, _), []).
+possible_targets(pragma_c(_, _, _, _, _), []).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/call_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/call_gen.m,v
retrieving revision 1.121
diff -u -r1.121 call_gen.m
--- call_gen.m	1998/03/03 17:33:37	1.121
+++ call_gen.m	1998/05/04 04:57:03
@@ -107,7 +107,7 @@
 
 	code_info__get_maybe_trace_info(MaybeTraceInfo),
 	( { MaybeTraceInfo = yes(TraceInfo) } ->
-		{ trace__generate_depth_reset_code(TraceInfo, TraceCode) }
+		{ trace__prepare_for_call(TraceInfo, TraceCode) }
 	;
 		{ TraceCode = empty }
 	),
@@ -230,7 +230,7 @@
 
 	code_info__get_maybe_trace_info(MaybeTraceInfo),
 	( { MaybeTraceInfo = yes(TraceInfo) } ->
-		{ trace__generate_depth_reset_code(TraceInfo, TraceCode) }
+		{ trace__prepare_for_call(TraceInfo, TraceCode) }
 	;
 		{ TraceCode = empty }
 	),
Index: compiler/code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_gen.m,v
retrieving revision 1.49
diff -u -r1.49 code_gen.m
--- code_gen.m	1998/04/08 11:31:15	1.49
+++ code_gen.m	1998/05/12 06:27:35
@@ -210,12 +210,12 @@
 		PredId, ProcId, ProcInfo, InitialInst, FollowVars,
 		ModuleInfo, CellCount0, CodeInfo0),
 		% generate code for the procedure
-	globals__lookup_bool_option(Globals, generate_trace, Trace),
+	globals__get_trace_level(Globals, TraceLevel),
 	code_util__make_proc_label(ModuleInfo, PredId, ProcId, ProcLabel),
 	(
-		Trace = yes
+		( TraceLevel = interface ; TraceLevel = full )
 	->
-		trace__setup(CodeInfo0, CodeInfo1)
+		trace__setup(TraceLevel, CodeInfo0, CodeInfo1)
 	;
 		CodeInfo1 = CodeInfo0
 	),
@@ -548,7 +548,7 @@
 					do_fail)
 					- "Allocate stack frame",
 				pragma_c([], DefineComponents,
-					will_not_call_mercury, no)
+					will_not_call_mercury, no, no)
 					- ""
 			]) },
 			{ NondetPragma = yes }
@@ -632,7 +632,7 @@
 		{ UndefComponents = [pragma_c_raw_code(UndefStr)] },
 		{ UndefCode = node([
 			pragma_c([], UndefComponents,
-				will_not_call_mercury, no)
+				will_not_call_mercury, no, no)
 				- ""
 		]) },
 		{ RestoreDeallocCode = empty },	% always empty for nondet code
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.219
diff -u -r1.219 code_info.m
--- code_info.m	1998/04/08 11:31:18	1.219
+++ code_info.m	1998/05/05 09:47:13
@@ -1902,10 +1902,12 @@
 
 code_info__generate_semi_pre_commit(RedoLabel, Slots, PreCommit) -->
 	code_info__generate_pre_commit_saves(Slots, SaveCode),
+	code_info__get_next_label(ResumeLabel),
 	code_info__top_failure_cont(FailureCont0),
 	{ FailureCont0 = failure_cont(_, FailureMap0) },
-	code_info__clone_resume_maps(FailureMap0, FailureMap),
-	{ FailureCont = failure_cont(nondet(known, no), FailureMap) },
+	{ code_info__pick_stack_resume_point(FailureMap0, StackMap, _) },
+	{ FailureCont = failure_cont(nondet(known, no),
+		stack_only(StackMap, label(ResumeLabel))) },
 	code_info__push_failure_cont(FailureCont),
 	code_info__get_next_label(RedoLabel),
 	{ HijackCode = node([
@@ -1970,9 +1972,11 @@
 	% We therefore push a dummy nondet failure continuation onto the
 	% failure stack. Since the code we are cutting across is multi,
 	% the failure continuation will never actually be used.
-	{ map__init(Empty) },
+	code_info__top_failure_cont(FailureCont0),
+	{ FailureCont0 = failure_cont(_, FailureMap) },
+	{ code_info__pick_stack_resume_point(FailureMap, StackMap, _) },
 	{ FailureCont = failure_cont(nondet(known, no),
-		stack_only(Empty, do_fail)) },
+		stack_only(StackMap, do_fail)) },
 	code_info__push_failure_cont(FailureCont).
 
 code_info__generate_det_commit(Slots, Commit) -->
@@ -2155,38 +2159,6 @@
 		tree(RestoreTrail,
 		tree(RestoreTicketCounter,
 		     MainPopCode)) }.
-
-
-:- pred code_info__clone_resume_maps(resume_maps, resume_maps,
-	code_info, code_info).
-:- mode code_info__clone_resume_maps(in, out, in, out) is det.
-
-code_info__clone_resume_maps(ResumeMaps0, ResumeMaps) -->
-	(
-		{ ResumeMaps0 = orig_only(Map1, _) },
-		code_info__get_next_label(Label1),
-		{ Addr1 = label(Label1) },
-		{ ResumeMaps = orig_only(Map1, Addr1) }
-	;
-		{ ResumeMaps0 = stack_only(Map1, _) },
-		code_info__get_next_label(Label1),
-		{ Addr1 = label(Label1) },
-		{ ResumeMaps = stack_only(Map1, Addr1) }
-	;
-		{ ResumeMaps0 = stack_and_orig(Map1, _, Map2, _) },
-		code_info__get_next_label(Label1),
-		{ Addr1 = label(Label1) },
-		code_info__get_next_label(Label2),
-		{ Addr2 = label(Label2) },
-		{ ResumeMaps = stack_and_orig(Map1, Addr1, Map2, Addr2) }
-	;
-		{ ResumeMaps0 = orig_and_stack(Map1, _, Map2, _) },
-		code_info__get_next_label(Label1),
-		{ Addr1 = label(Label1) },
-		code_info__get_next_label(Label2),
-		{ Addr2 = label(Label2) },
-		{ ResumeMaps = orig_and_stack(Map1, Addr1, Map2, Addr2) }
-	).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
Index: compiler/dupelim.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/dupelim.m,v
retrieving revision 1.31
diff -u -r1.31 dupelim.m
--- dupelim.m	1998/01/16 07:05:38	1.31
+++ dupelim.m	1998/05/11 03:25:36
@@ -114,7 +114,7 @@
 	),
 	AddPragmaReferredLabels = lambda(
 		[Instr::in, FoldFixed0::in, FoldFixed::out] is det, (
-		( Instr = pragma_c(_, _, _, yes(PragmaLabel)) - _ ->
+		( Instr = pragma_c(_, _, _, yes(PragmaLabel), _) - _ ->
 			set__insert(FoldFixed0, PragmaLabel, FoldFixed)
 		;
 			FoldFixed = FoldFixed0
@@ -354,7 +354,7 @@
 		Instr1 = decr_sp(_),
 		Instr = Instr1
 	;
-		Instr1 = pragma_c(_, _, _, _),
+		Instr1 = pragma_c(_, _, _, _, _),
 		Instr = Instr1
 	).
 
@@ -624,7 +624,7 @@
 		Instr2 = Instr1,
 		Instr = Instr1
 	;
-		Instr1 = pragma_c(_, _, _, _),
+		Instr1 = pragma_c(_, _, _, _, _),
 		Instr2 = Instr1,
 		Instr = Instr1
 	).
@@ -823,7 +823,8 @@
 	dupelim__replace_labels_rval(Rval0, ReplMap, Rval).
 dupelim__replace_labels_instr(incr_sp(Size, Msg), _, incr_sp(Size, Msg)).
 dupelim__replace_labels_instr(decr_sp(Size), _, decr_sp(Size)).
-dupelim__replace_labels_instr(pragma_c(A,B,C,D), ReplMap, pragma_c(A,B,C,D)) :-
+dupelim__replace_labels_instr(pragma_c(A,B,C,D,E), ReplMap,
+		pragma_c(A,B,C,D,E)) :-
 	(
 		D = no
 	;
Index: compiler/frameopt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/frameopt.m,v
retrieving revision 1.68
diff -u -r1.68 frameopt.m
--- frameopt.m	1998/01/16 07:05:39	1.68
+++ frameopt.m	1998/05/11 03:26:33
@@ -537,7 +537,13 @@
 			;
 				Uinstr = c_code(_)
 			;
-				Uinstr = pragma_c(_, _, may_call_mercury, _)
+				Uinstr = pragma_c(_, _,
+					MayCallMercury, _, NeedStack),
+				(
+					MayCallMercury = may_call_mercury
+				;
+					NeedStack = yes
+				)
 			)
 		->
 			NeedsFrame = yes
@@ -687,7 +693,7 @@
 possible_targets(discard_tickets_to(_), []).
 possible_targets(incr_sp(_, _), []).
 possible_targets(decr_sp(_), []).
-possible_targets(pragma_c(_, _, _, MaybeLabel), List) :-
+possible_targets(pragma_c(_, _, _, MaybeLabel, _), List) :-
 	(	
 		MaybeLabel = no,
 		List = []
@@ -712,7 +718,7 @@
 			Uinstr = call(_, _, _, _)
 		;
 			% Only may_call_mercury pragma_c's can clobber succip.
-			Uinstr = pragma_c(_, _, may_call_mercury, _)
+			Uinstr = pragma_c(_, _, may_call_mercury, _, _)
 		)
 	->
 		CanClobberSuccip = yes
@@ -1303,8 +1309,7 @@
 substitute_labels_instr(discard_tickets_to(Rval), _, discard_tickets_to(Rval)).
 substitute_labels_instr(incr_sp(Size, Name), _, incr_sp(Size, Name)).
 substitute_labels_instr(decr_sp(Size), _, decr_sp(Size)).
-substitute_labels_instr(pragma_c(Decls, Components, MayCallMercury, MaybeLabel),
-		_, pragma_c(Decls, Components, MayCallMercury, MaybeLabel)).
+substitute_labels_instr(pragma_c(A, B, C, D, E), _, pragma_c(A, B, C, D, E)).
 
 :- pred substitute_labels_list(list(label)::in, assoc_list(label)::in,
 	list(label)::out) is det.
Index: compiler/globals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.26
diff -u -r1.26 globals.m
--- globals.m	1998/01/23 12:11:54	1.26
+++ globals.m	1998/05/12 06:40:34
@@ -46,15 +46,17 @@
 	;	num_data_elems
 	;	size_data_elems.
 
-:- pred convert_gc_method(string::in, gc_method::out) is semidet.
+:- type trace_level
+	--->	minimal
+	;	interface
+	;	full.
 
+:- pred convert_gc_method(string::in, gc_method::out) is semidet.
 :- pred convert_tags_method(string::in, tags_method::out) is semidet.
-
 :- pred convert_args_method(string::in, args_method::out) is semidet.
-
 :- pred convert_prolog_dialect(string::in, prolog_dialect::out) is semidet.
-
 :- pred convert_termination_norm(string::in, termination_norm::out) is semidet.
+:- pred convert_trace_level(string::in, trace_level::out) is semidet.
 
 %-----------------------------------------------------------------------------%
 
@@ -62,7 +64,7 @@
 
 :- pred globals__init(option_table::di, gc_method::di, tags_method::di,
 	args_method::di, prolog_dialect::di, 
-	termination_norm::di, globals::uo) is det.
+	termination_norm::di, trace_level::di, globals::uo) is det.
 
 :- pred globals__get_options(globals::in, option_table::out) is det.
 :- pred globals__get_gc_method(globals::in, gc_method::out) is det.
@@ -71,19 +73,10 @@
 :- pred globals__get_prolog_dialect(globals::in, prolog_dialect::out) is det.
 :- pred globals__get_termination_norm(globals::in, termination_norm::out) 
 	is det.
+:- pred globals__get_trace_level(globals::in, trace_level::out) is det.
 
 :- pred globals__set_options(globals::in, option_table::in, globals::out)
 	is det.
-:- pred globals__set_gc_method(globals::in, gc_method::in, globals::out)
-	is det.
-:- pred globals__set_tags_method(globals::in, tags_method::in, globals::out)
-	is det.
-:- pred globals__set_args_method(globals::in, args_method::in, globals::out)
-	is det.
-:- pred globals__set_prolog_dialect(globals::in, prolog_dialect::in,
-	globals::out) is det.
-:- pred globals__set_termination_norm(globals::in, termination_norm::in,
-	globals::out) is det.
 
 :- pred globals__lookup_option(globals::in, option::in, option_data::out)
 	is det.
@@ -111,9 +104,10 @@
 
 :- pred globals__io_init(option_table::di, gc_method::in, tags_method::in,
 	args_method::in, prolog_dialect::in, termination_norm::in,
-	io__state::di, io__state::uo) is det.
+	trace_level::in, io__state::di, io__state::uo) is det.
 
 :- pred globals__io_get_gc_method(gc_method::out,
 	io__state::di, io__state::uo) is det.
@@ -130,16 +124,19 @@
 :- pred globals__io_get_termination_norm(termination_norm::out,
 	io__state::di, io__state::uo) is det.
 
+:- pred globals__io_get_trace_level(trace_level::out,
+	io__state::di, io__state::uo) is det.
+
 :- pred globals__io_get_globals(globals::out, io__state::di, io__state::uo)
 	is det.
 
 :- pred globals__io_set_globals(globals::di, io__state::di, io__state::uo)
 	is det.
 
-:- pred globals__io_lookup_option(option::in, option_data::out,
+:- pred globals__io_set_option(option::in, option_data::in,
 	io__state::di, io__state::uo) is det.
 
-:- pred globals__io_set_option(option::in, option_data::in,
+:- pred globals__io_lookup_option(option::in, option_data::out,
 	io__state::di, io__state::uo) is det.
 
 :- pred globals__io_lookup_bool_option(option, bool, io__state, io__state).
@@ -195,6 +192,10 @@
 convert_termination_norm("num-data-elems", num_data_elems).
 convert_termination_norm("size-data-elems", size_data_elems).
 
+convert_trace_level("minimal", minimal).
+convert_trace_level("interface", interface).
+convert_trace_level("full", full).
+
 %-----------------------------------------------------------------------------%
 
 :- type globals
@@ -204,35 +205,27 @@
 			tags_method,
 			args_method,
 			prolog_dialect,
-			termination_norm
+			termination_norm,
+			trace_level
 		).
 
 globals__init(Options, GC_Method, TagsMethod, ArgsMethod,
-		PrologDialect, TerminationNorm, 
+		PrologDialect, TerminationNorm, TraceLevel,
 	globals(Options, GC_Method, TagsMethod, ArgsMethod,
-		PrologDialect, TerminationNorm)).
+		PrologDialect, TerminationNorm, TraceLevel)).
 
-globals__get_options(globals(Options, _, _, _, _, _), Options).
-globals__get_gc_method(globals(_, GC_Method, _, _, _, _), GC_Method).
-globals__get_tags_method(globals(_, _, TagsMethod, _, _, _), TagsMethod).
-globals__get_args_method(globals(_, _, _, ArgsMethod, _, _), ArgsMethod).
-globals__get_prolog_dialect(globals(_, _, _, _, PrologDialect, _),
+globals__get_options(globals(Options, _, _, _, _, _, _), Options).
+globals__get_gc_method(globals(_, GC_Method, _, _, _, _, _), GC_Method).
+globals__get_tags_method(globals(_, _, TagsMethod, _, _, _, _), TagsMethod).
+globals__get_args_method(globals(_, _, _, ArgsMethod, _, _, _), ArgsMethod).
+globals__get_prolog_dialect(globals(_, _, _, _, PrologDialect, _, _),
 	PrologDialect).
-globals__get_termination_norm(globals(_, _, _, _, _, TerminationNorm),
+globals__get_termination_norm(globals(_, _, _, _, _, TerminationNorm, _),
 	TerminationNorm).
+globals__get_trace_level(globals(_, _, _, _, _, _, TraceLevel), TraceLevel).
 
-globals__set_options(globals(_, B, C, D, E, F), Options,
-	globals(Options, B, C, D, E, F)).
-globals__set_gc_method(globals(A, _, C, D, E, F), GC_Method,
-	globals(A, GC_Method, C, D, E, F)).
-globals__set_tags_method(globals(A, B, _, D, E, F), TagsMethod,
-	globals(A, B, TagsMethod, D, E, F)).
-globals__set_args_method(globals(A, B, C, _, E, F), ArgsMethod,
-	globals(A, B, C, ArgsMethod, E, F)).
-globals__set_prolog_dialect(globals(A, B, C, D, _, F), PrologDialect,
-	globals(A, B, C, D, PrologDialect, F)).
-globals__set_termination_norm(globals(A, B, C, D, E, _), TerminationNorm,
-	globals(A, B, C, D, E, TerminationNorm)).
+globals__set_options(globals(_, B, C, D, E, F, G), Options,
+	globals(Options, B, C, D, E, F, G)).
 
 globals__lookup_option(Globals, Option, OptionData) :-
 	globals__get_options(Globals, OptionTable),
@@ -291,14 +284,15 @@
 %-----------------------------------------------------------------------------%
 
 globals__io_init(Options, GC_Method, TagsMethod, ArgsMethod,
-		PrologDialect, TerminationNorm) -->
+		PrologDialect, TerminationNorm, TraceLevel) -->
 	{ copy(GC_Method, GC_Method1) },
 	{ copy(TagsMethod, TagsMethod1) },
 	{ copy(ArgsMethod, ArgsMethod1) },
 	{ copy(PrologDialect, PrologDialect1) },
 	{ copy(TerminationNorm, TerminationNorm1) },
+	{ copy(TraceLevel, TraceLevel1) },
 	{ globals__init(Options, GC_Method1, TagsMethod1, ArgsMethod1,
-		PrologDialect1, TerminationNorm1, Globals) },
+		PrologDialect1, TerminationNorm1, TraceLevel1, Globals) },
 	globals__io_set_globals(Globals).
 
 globals__io_get_gc_method(GC_Method) -->
@@ -320,6 +314,10 @@
 globals__io_get_termination_norm(TerminationNorm) -->
 	globals__io_get_globals(Globals),
 	{ globals__get_termination_norm(Globals, TerminationNorm) }.
+
+globals__io_get_trace_level(TraceLevel) -->
+	globals__io_get_globals(Globals),
+	{ globals__get_trace_level(Globals, TraceLevel) }.
 
 globals__io_get_globals(Globals) -->
 	io__get_globals(UnivGlobals),
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.47
diff -u -r1.47 handle_options.m
--- handle_options.m	1998/04/27 04:01:01	1.47
+++ handle_options.m	1998/05/12 07:47:47
@@ -113,73 +113,81 @@
 
 postprocess_options(error(ErrorMessage), yes(ErrorMessage)) --> [].
 postprocess_options(ok(OptionTable), Error) -->
-            { map__lookup(OptionTable, gc, GC_Method0) },
+    { map__lookup(OptionTable, gc, GC_Method0) },
+    (
+        { GC_Method0 = string(GC_MethodStr) },
+        { convert_gc_method(GC_MethodStr, GC_Method) }
+    ->
+        { map__lookup(OptionTable, tags, TagsMethod0) },
+        (
+            { TagsMethod0 = string(TagsMethodStr) },
+            { convert_tags_method(TagsMethodStr, TagsMethod) }
+        ->
+            { map__lookup(OptionTable, args, ArgsMethod0) },
             (
-                { GC_Method0 = string(GC_MethodStr) },
-                { convert_gc_method(GC_MethodStr, GC_Method) }
+                { ArgsMethod0 = string(ArgsMethodStr) },
+                { convert_args_method(ArgsMethodStr, ArgsMethod) }
             ->
-                { map__lookup(OptionTable, tags, TagsMethod0) },
+                { map__lookup(OptionTable, prolog_dialect,
+                    PrologDialect0) },
                 (
-                    { TagsMethod0 = string(TagsMethodStr) },
-                    { convert_tags_method(TagsMethodStr, TagsMethod) }
+                    { PrologDialect0 = string(PrologDialectStr) },
+                    { convert_prolog_dialect(PrologDialectStr,
+                        PrologDialect) }
                 ->
-                    { map__lookup(OptionTable, args, ArgsMethod0) },
-                    (
-                        { ArgsMethod0 = string(ArgsMethodStr) },
-                        { convert_args_method(ArgsMethodStr, ArgsMethod) }
+                    { map__lookup(OptionTable,
+                        fact_table_hash_percent_full, PercentFull) },
+                    ( 
+                        { PercentFull = int(Percent) },
+                        { Percent >= 1 },
+                        { Percent =< 100 }
                     ->
-                            { map__lookup(OptionTable, prolog_dialect,
-                                PrologDialect0) },
+                        { map__lookup(OptionTable, termination_norm,
+                                TermNorm0) },
+                        ( 
+                            { TermNorm0 = string(TermNormStr) },
+                            { convert_termination_norm(TermNormStr,
+                                    TermNorm) }
+                        ->
+                            { map__lookup(OptionTable, trace, Trace) },
                             (
-                                { PrologDialect0 = string(PrologDialectStr) },
-                                { convert_prolog_dialect(PrologDialectStr,
-                                    PrologDialect) }
+                                { Trace = string(TraceStr) },
+                                { convert_trace_level(TraceStr,
+                                    TraceLevel) }
                             ->
-				{ map__lookup(OptionTable,
-					fact_table_hash_percent_full,
-					PercentFull) },
-				( 
-				    { PercentFull = int(Percent) },
-				    { Percent >= 1 },
-				    { Percent =< 100 }
-				->
-				    { map__lookup(OptionTable,
-				    	termination_norm, TermNorm0) },
-				    ( 
-					{ TermNorm0 = string(TermNormStr) },
-					{ convert_termination_norm(
-						TermNormStr, TermNorm) }
-				    ->
-				    	postprocess_options_2(OptionTable,
-				    	    GC_Method, TagsMethod, ArgsMethod,
-				    	    PrologDialect, TermNorm),
-				        { Error = no }
-				    ;
-				    	{ Error = yes("Invalid argument to option `--termination-norm'\n\t(must be `simple', `total' or  `num-data-elems').") }
-				    )
-				;
-				    { Error = yes("Invalid argument to option `--fact-table-hash-percent-full'\n                 (must be an integer between 1 and 100)") }
-				)
+                                postprocess_options_2(OptionTable,
+                                    GC_Method, TagsMethod, ArgsMethod,
+                                    PrologDialect, TermNorm, TraceLevel),
+                                { Error = no }
                             ;
-                                { Error = yes("Invalid prolog-dialect option (must be `sicstus', `nu', or `default')") }
+                                { Error = yes("Invalid argument to option `--trace'\n\t(must be `minimal', `interface' or  `full').") }
                             )
+                        ;
+                            { Error = yes("Invalid argument to option `--termination-norm'\n\t(must be `simple', `total' or  `num-data-elems').") }
+                        )
                     ;
-                        { Error = yes("Invalid args option (must be `simple' or `compact')") }
+                        { Error = yes("Invalid argument to option `--fact-table-hash-percent-full'\n\t(must be an integer between 1 and 100)") }
                     )
                 ;
-                    { Error = yes("Invalid tags option (must be `none', `low' or `high')") }
+                    { Error = yes("Invalid prolog-dialect option (must be `sicstus', `nu', or `default')") }
                 )
             ;
-                { Error = yes("Invalid GC option (must be `none', `conservative' or `accurate')") }
-            ).
+                { Error = yes("Invalid args option (must be `simple' or `compact')") }
+            )
+        ;
+            { Error = yes("Invalid tags option (must be `none', `low' or `high')") }
+        )
+    ;
+        { Error = yes("Invalid GC option (must be `none', `conservative' or `accurate')") }
+    ).
 
 :- pred postprocess_options_2(option_table, gc_method, tags_method, 
-	args_method, prolog_dialect, termination_norm,
+	args_method, prolog_dialect, termination_norm, trace_level,
 	io__state, io__state).
-:- mode postprocess_options_2(in, in, in, in, in, in, di, uo) is det.
+:- mode postprocess_options_2(in, in, in, in, in, in, in, di, uo) is det.
 
 postprocess_options_2(OptionTable, GC_Method, TagsMethod, ArgsMethod,
-		PrologDialect, TermNorm) -->
+		PrologDialect, TermNorm, TraceLevel) -->
 	% work around for NU-Prolog problems
 	( { map__search(OptionTable, heap_space, int(HeapSpace)) }
 	->
@@ -190,7 +198,7 @@
 
 	{ unsafe_promise_unique(OptionTable, OptionTable1) }, % XXX
 	globals__io_init(OptionTable1, GC_Method, TagsMethod, ArgsMethod,
-		PrologDialect, TermNorm),
+		PrologDialect, TermNorm, TraceLevel),
 
 	% --gc conservative implies --no-reclaim-heap-*
 	( { GC_Method = conservative } ->
@@ -259,15 +267,14 @@
 		[]
 	),
 
-	% --generate-trace requires 
+	% Tracing requires 
 	% 	- disabling optimizations that would change 
 	% 	  the trace being generated
 	%	- enabling some low level optimizations to ensure consistent
 	%	  paths across optimization levels
 	% 	- enabling stack layouts
 	% 	- enabling typeinfo liveness
-	globals__io_lookup_bool_option(generate_trace, Trace),
-	( { Trace = yes } ->
+	( { TraceLevel = interface ; TraceLevel = full } ->
 			% The following options modify the structure
 			% of the program, which makes it difficult to
 			% relate the trace to the source code (although
Index: compiler/live_vars.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/live_vars.m,v
retrieving revision 1.73
diff -u -r1.73 live_vars.m
--- live_vars.m	1998/04/08 11:31:53	1.73
+++ live_vars.m	1998/05/12 07:43:28
@@ -49,8 +49,8 @@
 	initial_liveness(ProcInfo0, ModuleInfo, Liveness0),
 	set__init(LiveSets0),
 	module_info_globals(ModuleInfo, Globals),
-	globals__lookup_bool_option(Globals, generate_trace, Trace),
-	( Trace = yes ->
+	globals__get_trace_level(Globals, TraceLevel),
+	( ( TraceLevel = interface ; TraceLevel = full ) ->
 		trace__fail_vars(ModuleInfo, ProcInfo0, ResumeVars0),
 		set__insert(LiveSets0, ResumeVars0, LiveSets1)
 	;
Index: compiler/livemap.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/livemap.m,v
retrieving revision 1.33
diff -u -r1.33 livemap.m
--- livemap.m	1998/03/03 17:34:47	1.33
+++ livemap.m	1998/05/11 03:26:37
@@ -329,7 +329,7 @@
 		Ccode = Ccode0
 	;
 		% XXX we shouldn't just give up here
-		Uinstr0 = pragma_c(_, _, _, _),
+		Uinstr0 = pragma_c(_, _, _, _, _),
 		Livemap = Livemap0,
 		Livevals = Livevals0,
 		Instrs = Instrs0,
Index: compiler/liveness.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/liveness.m,v
retrieving revision 1.92
diff -u -r1.92 liveness.m
--- liveness.m	1998/04/08 11:31:56	1.92
+++ liveness.m	1998/05/12 07:37:08
@@ -165,8 +165,8 @@
 	detect_deadness_in_goal(Goal1, Deadness0, LiveInfo, _, Goal2),
 
 	module_info_globals(ModuleInfo, Globals),
-	globals__lookup_bool_option(Globals, generate_trace, Trace),
-	( Trace = yes ->
+	globals__get_trace_level(Globals, TraceLevel),
+	( ( TraceLevel = interface ; TraceLevel = full ) ->
 		trace__fail_vars(ModuleInfo, ProcInfo0, ResumeVars0)
 	;
 		set__init(ResumeVars0)
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.222
diff -u -r1.222 llds.m
--- llds.m	1998/03/03 17:34:51	1.222
+++ llds.m	1998/05/11 02:52:27
@@ -231,7 +231,7 @@
 			% Decrement the det stack pointer.
 
 	;	pragma_c(list(pragma_c_decl), list(pragma_c_component),
-				may_call_mercury, maybe(label)).
+				may_call_mercury, maybe(label), bool).
 			% The first argument says what local variable
 			% declarations are required for the following
 			% components, which in turn can specify how
@@ -254,6 +254,12 @@
 			% prevent the label from being optimized away.
 			% To make it known to labelopt, we mention it in
 			% the fourth arg.
+			%
+			% The fifth argument says whether the contents
+			% of the pragma C code can refer to stack slots.
+			% User-written shouldn't refer to stack slots,
+			% the question is whether the compiler-generated
+			% C code does.
 
 	% Procedures defined by nondet pragma C codes must have some way of
 	% preserving information after a success, so that when control
Index: compiler/llds_common.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_common.m,v
retrieving revision 1.16
diff -u -r1.16 llds_common.m
--- llds_common.m	1998/03/03 17:34:53	1.16
+++ llds_common.m	1998/05/11 03:26:42
@@ -253,7 +253,7 @@
 		Instr = Instr0,
 		Info = Info0
 	;
-		Instr0 = pragma_c(_, _, _, _),
+		Instr0 = pragma_c(_, _, _, _, _),
 		Instr = Instr0,
 		Info = Info0
 	).
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.79
diff -u -r1.79 llds_out.m
--- llds_out.m	1998/04/15 06:49:27	1.79
+++ llds_out.m	1998/05/11 03:00:52
@@ -880,8 +880,8 @@
 	output_rval_decls(Rval, "", "", 0, _, DeclSet0, DeclSet).
 output_instruction_decls(incr_sp(_, _), DeclSet, DeclSet) --> [].
 output_instruction_decls(decr_sp(_), DeclSet, DeclSet) --> [].
-output_instruction_decls(pragma_c(_, Components, _, _), DeclSet0, DeclSet) -->
-	output_pragma_c_component_list_decls(Components, DeclSet0, DeclSet).
+output_instruction_decls(pragma_c(_, Comps, _, _, _), DeclSet0, DeclSet) -->
+	output_pragma_c_component_list_decls(Comps, DeclSet0, DeclSet).
 
 :- pred output_pragma_c_component_list_decls(list(pragma_c_component),
 	decl_set, decl_set, io__state, io__state).
@@ -1181,7 +1181,7 @@
 	io__write_int(N),
 	io__write_string(");\n").
 
-output_instruction(pragma_c(Decls, Components, _, _), _) -->
+output_instruction(pragma_c(Decls, Components, _, _, _), _) -->
 	io__write_string("\t{\n"),
 	output_pragma_decls(Decls),
 	output_pragma_c_components(Components),
@@ -2309,7 +2309,7 @@
 		io__write_string(Str)
 	;
 		{ VarName = stack_layout(Label) },
-		io__write_string("_stack_layout__"),
+		io__write_string("_layout__"),
 		output_label(Label)
 	).
 
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.85
diff -u -r1.85 mercury_compile.m
--- mercury_compile.m	1998/04/27 04:01:33	1.85
+++ mercury_compile.m	1998/05/12 07:39:12
@@ -988,8 +988,8 @@
 		"% Allocating storage locations for live vars in ",
 				PredId, ProcId, ModuleInfo3),
 	{ store_alloc_in_proc(ProcInfo5, ModuleInfo3, ProcInfo6) },
-	{ globals__lookup_bool_option(Globals, generate_trace, Trace) },
-	( { Trace = yes } ->
+	globals__io_get_trace_level(TraceLevel),
+	( { TraceLevel = interface ; TraceLevel = full } ->
 		write_proc_progress_message(
 			"% Calculating goal paths in ",
 					PredId, ProcId, ModuleInfo3),
@@ -1612,8 +1612,8 @@
 :- mode mercury_compile__maybe_goal_paths(in, in, in, out, di, uo) is det.
 
 mercury_compile__maybe_goal_paths(HLDS0, Verbose, Stats, HLDS) -->
-	globals__io_lookup_bool_option(generate_trace, Trace),
-	( { Trace = yes } ->
+	globals__io_get_trace_level(TraceLevel),
+	( { TraceLevel = interface ; TraceLevel = full } ->
 		maybe_write_string(Verbose, "% Calculating goal paths..."),
 		maybe_flush_output(Verbose),
 		process_all_nonimported_procs(
@@ -1751,8 +1751,8 @@
 	{ export__get_pragma_exported_procs(HLDS, PragmaExports) },
 	maybe_add_header_file_include(PragmaExports, ModuleName, C_HeaderCode0,
 		C_HeaderCode1),
-	globals__io_lookup_bool_option(generate_trace, Trace),
-	( { Trace = yes } ->
+	globals__io_get_trace_level(TraceLevel),
+	( { TraceLevel = interface ; TraceLevel = full } ->
 		{ term__context_init(Context) },
 		{ TraceInclude = "#include ""mercury_trace.h""\n" - Context },
 		{ list__append(C_HeaderCode1, [TraceInclude], C_HeaderCode) }
Index: compiler/middle_rec.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/middle_rec.m,v
retrieving revision 1.70
diff -u -r1.70 middle_rec.m
--- middle_rec.m	1998/03/03 17:35:09	1.70
+++ middle_rec.m	1998/05/11 03:01:00
@@ -417,7 +417,7 @@
 	middle_rec__find_used_registers_rval(Rval, Used0, Used).
 middle_rec__find_used_registers_instr(incr_sp(_, _), Used, Used).
 middle_rec__find_used_registers_instr(decr_sp(_), Used, Used).
-middle_rec__find_used_registers_instr(pragma_c(_, Components, _, _),
+middle_rec__find_used_registers_instr(pragma_c(_, Components, _, _, _),
 		Used0, Used) :-
 	middle_rec__find_used_registers_components(Components, Used0, Used).
 
Index: compiler/opt_debug.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.80
diff -u -r1.80 opt_debug.m
--- opt_debug.m	1998/03/03 17:35:28	1.80
+++ opt_debug.m	1998/05/11 03:26:49
@@ -903,7 +903,7 @@
 	string__int_to_string(Size, S_str),
 	string__append_list(["decr_sp(", S_str, ")"], Str).
 % XXX  should probably give more info than this
-opt_debug__dump_instr(pragma_c(_, Comps, _, _), Str) :-
+opt_debug__dump_instr(pragma_c(_, Comps, _, _, _), Str) :-
 	opt_debug__dump_components(Comps, C_str),
 	string__append_list(["pragma_c(", C_str, ")"], Str).
 
Index: compiler/opt_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/opt_util.m,v
retrieving revision 1.91
diff -u -r1.91 opt_util.m
--- opt_util.m	1998/04/08 11:32:07	1.91
+++ opt_util.m	1998/05/11 03:02:18
@@ -881,7 +881,7 @@
 		Uinstr0 = decr_sp(_),
 		Need = no
 	;
-		Uinstr0 = pragma_c(_, _, _, _),
+		Uinstr0 = pragma_c(_, _, _, _, _),
 		Need = no
 	).
 
@@ -981,8 +981,8 @@
 opt_util__can_instr_branch_away(discard_tickets_to(_), no).
 opt_util__can_instr_branch_away(incr_sp(_, _), no).
 opt_util__can_instr_branch_away(decr_sp(_), no).
-opt_util__can_instr_branch_away(pragma_c(_, Components, _, _), BranchAway) :-
-	opt_util__can_components_branch_away(Components, BranchAway).
+opt_util__can_instr_branch_away(pragma_c(_, Comps, _, _, _), BranchAway) :-
+	opt_util__can_components_branch_away(Comps, BranchAway).
 
 :- pred opt_util__can_components_branch_away(list(pragma_c_component), bool).
 :- mode opt_util__can_components_branch_away(in, out) is det.
@@ -1040,7 +1040,7 @@
 opt_util__can_instr_fall_through(discard_tickets_to(_), yes).
 opt_util__can_instr_fall_through(incr_sp(_, _), yes).
 opt_util__can_instr_fall_through(decr_sp(_), yes).
-opt_util__can_instr_fall_through(pragma_c(_, _, _, _), yes).
+opt_util__can_instr_fall_through(pragma_c(_, _, _, _, _), yes).
 
 	% Check whether an instruction sequence can possibly fall through
 	% to the next instruction without using its label.
@@ -1081,7 +1081,7 @@
 opt_util__can_use_livevals(discard_tickets_to(_), no).
 opt_util__can_use_livevals(incr_sp(_, _), no).
 opt_util__can_use_livevals(decr_sp(_), no).
-opt_util__can_use_livevals(pragma_c(_, _, _, _), no).
+opt_util__can_use_livevals(pragma_c(_, _, _, _, _), no).
 
 % determine all the labels and code_addresses that are referenced by Instr
 
@@ -1139,7 +1139,7 @@
 opt_util__instr_labels_2(discard_tickets_to(_), [], []).
 opt_util__instr_labels_2(incr_sp(_, _), [], []).
 opt_util__instr_labels_2(decr_sp(_), [], []).
-opt_util__instr_labels_2(pragma_c(_, _, _, MaybeLabel), Labels, []) :-
+opt_util__instr_labels_2(pragma_c(_, _, _, MaybeLabel, _), Labels, []) :-
 	( MaybeLabel = yes(Label) ->
 		Labels = [Label]
 	;
@@ -1174,8 +1174,8 @@
 opt_util__instr_rvals_and_lvals(discard_tickets_to(Rval), [Rval], []).
 opt_util__instr_rvals_and_lvals(incr_sp(_, _), [], []).
 opt_util__instr_rvals_and_lvals(decr_sp(_), [], []).
-opt_util__instr_rvals_and_lvals(pragma_c(_, Components, _, _), Rvals, Lvals) :-
-	pragma_c_components_get_rvals_and_lvals(Components, Rvals, Lvals).
+opt_util__instr_rvals_and_lvals(pragma_c(_, Comps, _, _, _), Rvals, Lvals) :-
+	pragma_c_components_get_rvals_and_lvals(Comps, Rvals, Lvals).
 
 	% extract the rvals and lvals from the pragma_c_components
 :- pred pragma_c_components_get_rvals_and_lvals(list(pragma_c_component),
@@ -1303,7 +1303,7 @@
 	opt_util__count_temps_rval(Rval, R0, R, F0, F).
 opt_util__count_temps_instr(incr_sp(_, _), R, R, F, F).
 opt_util__count_temps_instr(decr_sp(_), R, R, F, F).
-opt_util__count_temps_instr(pragma_c(_, _, _, _), R, R, F, F).
+opt_util__count_temps_instr(pragma_c(_, _, _, _, _), R, R, F, F).
 
 :- pred opt_util__count_temps_lval(lval, int, int, int, int).
 :- mode opt_util__count_temps_lval(in, in, out, in, out) is det.
@@ -1410,7 +1410,7 @@
 		opt_util__touches_nondet_ctrl_lval(Lval, Touch)
 	; Uinstr = restore_hp(Rval) ->
 		opt_util__touches_nondet_ctrl_rval(Rval, Touch)
-	; Uinstr = pragma_c(_, Components, _, _) ->
+	; Uinstr = pragma_c(_, Components, _, _, _) ->
 		opt_util__touches_nondet_ctrl_components(Components, Touch)
 	;
 		Touch = yes
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.227
diff -u -r1.227 options.m
--- options.m	1998/04/28 06:12:38	1.227
+++ options.m	1998/05/12 06:15:39
@@ -88,7 +88,7 @@
 		;	compile_only
 	% Auxiliary output options
 		;	assume_gmake
-		;	generate_trace
+		;	trace
 		;	generate_bytecode
 		;	generate_prolog
 		;	prolog_dialect
@@ -359,7 +359,7 @@
 option_defaults_2(aux_output_option, [
 		% Auxiliary Output Options
 	assume_gmake		-	bool(yes),
-	generate_trace		-	bool(no),
+	trace			-	string("minimal"),
 	generate_bytecode	-	bool(no),
 	generate_prolog		-	bool(no),
 	prolog_dialect		-	string("default"),
@@ -674,7 +674,7 @@
 
 % aux output options
 long_option("assume-gmake",		assume_gmake).
-long_option("generate-trace",		generate_trace).
+long_option("trace",			trace).
 long_option("generate-bytecode",	generate_bytecode).
 long_option("generate-prolog",		generate_prolog).
 long_option("generate-Prolog",		generate_prolog).
@@ -1316,8 +1316,9 @@
 	io__write_string("\t\tWhen generating `.dep' files, generate Makefile\n"),
 	io__write_string("\t\tfragments that use only the features of standard make;\n"),
 	io__write_string("\t\tdo not assume the availability of GNU Make extensions.\n"),
-	io__write_string("\t--generate-trace\n"),
-	io__write_string("\t\tInclude code to generate an execution trace in the\n"),
+	io__write_string("\t--trace {minimal, interface, full}\n"),
+	io__write_string("\t\tGenerate code that includes the specified level\n"), 
+	io__write_string("\t\tof execution tracing.\n"),
 	io__write_string("\t\tC code output by the compiler.\n"),
 	io__write_string("\t--generate-bytecode\n"),
 	io__write_string("\t\tOutput a bytecode form of the module for use\n"),
Index: compiler/pragma_c_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/pragma_c_gen.m,v
retrieving revision 1.15
diff -u -r1.15 pragma_c_gen.m
--- pragma_c_gen.m	1998/04/08 11:32:14	1.15
+++ pragma_c_gen.m	1998/05/11 03:28:32
@@ -429,8 +429,8 @@
 	{ Components = [InputComp, SaveRegsComp, C_Code_Comp,
 			CheckR1_Comp, RestoreRegsComp, OutputComp] },
 	{ PragmaCCode = node([
-		pragma_c(Decls, Components, MayCallMercury, MaybeFailLabel) -
-			"Pragma C inclusion"
+		pragma_c(Decls, Components, MayCallMercury, MaybeFailLabel, no)
+			- "Pragma C inclusion"
 	]) },
 
 	%
@@ -625,7 +625,7 @@
 		],
 		CallBlockCode = node([
 			pragma_c(CallDecls, CallComponents,
-				MayCallMercury, no)
+				MayCallMercury, no, yes)
 				- "Call and shared pragma C inclusion"
 		]),
 
@@ -652,7 +652,7 @@
 		],
 		RetryBlockCode = node([
 			pragma_c(RetryDecls, RetryComponents,
-				MayCallMercury, no)
+				MayCallMercury, no, yes)
 				- "Retry and shared pragma C inclusion"
 		]),
 
@@ -707,7 +707,7 @@
 		],
 		CallBlockCode = node([
 			pragma_c(CallDecls, CallComponents,
-				MayCallMercury, yes(SharedLabel))
+				MayCallMercury, yes(SharedLabel), yes)
 				- "Call pragma C inclusion"
 		]),
 
@@ -734,7 +734,7 @@
 		],
 		RetryBlockCode = node([
 			pragma_c(RetryDecls, RetryComponents,
-				MayCallMercury, yes(SharedLabel))
+				MayCallMercury, yes(SharedLabel), yes)
 				- "Retry pragma C inclusion"
 		]),
 
@@ -760,7 +760,7 @@
 		],
 		SharedBlockCode = node([
 			pragma_c(SharedDecls, SharedComponents,
-				MayCallMercury, no)
+				MayCallMercury, no, yes)
 				- "Shared pragma C inclusion"
 		]),
 
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.11
diff -u -r1.11 stack_layout.m
--- stack_layout.m	1998/04/17 06:55:40	1.11
+++ stack_layout.m	1998/05/11 02:05:48
@@ -27,7 +27,7 @@
 % If the option basic_stack_layout is set, we generate a stack layout table
 % for each procedure. This table will be stored in the global variable
 % whose name is
-%	mercury_data__stack_layout__mercury__<proc_label>.
+%	mercury_data__layout__mercury__<proc_label>.
 % This table will always contain the following information:
 %
 %	code address		(Code *) - address of entry
@@ -79,7 +79,7 @@
 % If the option basic_stack_layout is set, we generate stack layout tables
 % for some labels internal to the procedure. This table will be stored in the
 % global variable whose name is
-%	mercury_data__stack_layout__mercury__<proc_label>_i<label_number>.
+%	mercury_data__layout__mercury__<proc_label>_i<label_number>.
 % This table has the following format:
 %
 %	procedure info		(Word *) - pointer to procedure stack layout
@@ -88,11 +88,15 @@
 % 	live data pairs 	(Word *) - pointer to vector of pairs
 %				containing MR_Live_Lval and MR_Live_Type
 % 	live data names	 	(Word *) - pointer to vector of String
+%	# of type parameters	(Integer)
 %	type parameters		(Word *) - pointer to vector of MR_Live_Lval
 %
-% The internal label number field is just for the convenience of those
-% implementors who are debugging stack layout dependent code. It holds
-% either the label number, or -1 indicating the entry label.
+% The internal label number field holds either the real label number
+% (which is always strictly positive), 0 indicating the entry label,
+% or a negative number indicating unknown (the last alternative is possible
+% only in non-compiler-generated structures). The only purpose of this field
+% is to make debugging the native garbage collector easier. Accordingly,
+% it will be present only if the option agc_stack_layout is set.
 %
 % The live data pair vector will have an entry for each live variable.
 % The entry will give the location of the variable and its type. (It also
@@ -299,7 +303,11 @@
 		{ MaybeRvals = MaybeRvals1 }
 	),
 
-	{ CModule = c_data(ModuleName, stack_layout(Label), yes,
+	{ Exported = no },	% With the new profiler, we will need to
+				% set this to `yes' if the profiling option
+				% is given and if the procedure is exported.
+				% XXX
+	{ CModule = c_data(ModuleName, stack_layout(Label), Exported,
 		MaybeRvals, []) },
 	stack_layout__add_cmodule(CModule, Label).
 
@@ -358,15 +366,21 @@
 	stack_layout__get_module_name(ModuleName),
 	{ EntryAddrRval = const(data_addr_const(data_addr(ModuleName,
 		stack_layout(local(ProcLabel))))) },
-	{ Label = local(_, LabelNum0) ->
-		LabelNum = LabelNum0
-	;
-		LabelNum = -1
-	},
-	{ LabelNumRval = const(int_const(LabelNum)) },
 	stack_layout__construct_internal_rvals(Internal, AgcRvals),
-	{ LayoutRvals = [yes(EntryAddrRval), yes(LabelNumRval) | AgcRvals] },
-	{ CModule = c_data(ModuleName, stack_layout(Label), yes,
+	stack_layout__get_agc_stack_layout(AgcLayout),
+	( { AgcLayout = yes } ->
+		{ Label = local(_, LabelNum0) ->
+			LabelNum = LabelNum0
+		;
+			LabelNum = 0
+		},
+		{ LabelNumRval = const(int_const(LabelNum)) },
+		{ LayoutRvals = [yes(EntryAddrRval), yes(LabelNumRval)
+			| AgcRvals] }
+	;
+		{ LayoutRvals = [yes(EntryAddrRval) | AgcRvals] }
+	),
+	{ CModule = c_data(ModuleName, stack_layout(Label), no,
 		LayoutRvals, []) },
 	stack_layout__add_cmodule(CModule, Label).
 
Index: compiler/store_alloc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/store_alloc.m,v
retrieving revision 1.62
diff -u -r1.62 store_alloc.m
--- store_alloc.m	1998/04/08 11:32:21	1.62
+++ store_alloc.m	1998/05/12 07:37:20
@@ -68,8 +68,8 @@
 		proc_info_goal(ProcInfo0, Goal2)
 	),
 	initial_liveness(ProcInfo0, ModuleInfo, Liveness0),
-	globals__lookup_bool_option(Globals, generate_trace, Trace),
-	( Trace = yes ->
+	globals__get_trace_level(Globals, TraceLevel),
+	( ( TraceLevel = interface ; TraceLevel = full ) ->
 		trace__fail_vars(ModuleInfo, ProcInfo0, ResumeVars0)
 	;
 		set__init(ResumeVars0)
Index: compiler/trace.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.8
diff -u -r1.8 trace.m
--- trace.m	1998/04/08 11:32:34	1.8
+++ trace.m	1998/05/12 06:36:21
@@ -46,7 +46,7 @@
 :- interface.
 
 :- import_module hlds_goal, hlds_pred, hlds_module.
-:- import_module prog_data, llds, code_info.
+:- import_module globals, prog_data, llds, code_info.
 :- import_module assoc_list, set, term.
 
 :- type external_trace_port
@@ -68,24 +68,25 @@
 	% layouts).
 :- pred trace__fail_vars(module_info::in, proc_info::in, set(var)::out) is det.
 
-	% Set up the code generator state for tracing, by reserving
-	% slots for the call number and call depth.
-:- pred trace__setup(code_info::in, code_info::out) is det.
+	% Set up the code generator state for tracing, by reserving stack slots
+	% for the call number, call depth and (for interface tracing) for
+	% the flag that says whether this call should be traced.
+:- pred trace__setup(trace_level::in, code_info::in, code_info::out) is det.
 
-	% Generate code to fill in the slots for the call number and depth.
+	% Generate code to fill in the reserevd stack slots.
 :- pred trace__generate_slot_fill_code(trace_info::in, code_tree::out) is det.
 
-	% Generate code to reset the call depth before a call.
-:- pred trace__generate_depth_reset_code(trace_info::in, code_tree::out) is det.
+	% Generate code to prepare for a call.
+:- pred trace__prepare_for_call(trace_info::in, code_tree::out) is det.
 
-	% If generate_trace is set, generate code for an internal trace event.
-	% This predicate must be called just before generating code for the
-	% given goal.
+	% If we are doing execution tracing, generate code for an internal
+	% trace event. This predicate must be called just before generating
+	% code for the given goal.
 :- pred trace__maybe_generate_internal_event_code(hlds_goal::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
-	% If generate_trace is set, generate code for a nondet pragma C code
-	% trace event.
+	% If we are doing execution tracing, generate code for a nondet
+	% pragma C code trace event.
 :- pred trace__maybe_generate_pragma_event_code(nondet_pragma_trace_port::in,
 	code_tree::out, code_info::in, code_info::out) is det.
 
@@ -129,12 +130,19 @@
 		)
 	;	nondet_pragma.
 
+:- type trace_type
+	--->	full_trace
+	;	interface_trace(lval).	% This holds the saved value of a bool
+					% that is true iff we were called from
+					% code with full tracing.
+
 	% Information for tracing that is valid throughout the execution
 	% of a procedure.
 :- type trace_info
 	--->	trace_info(
 			lval,	% stack slot of call sequence number
-			lval	% stack slot of call depth
+			lval,	% stack slot of call depth
+			trace_type
 		).
 
 trace__fail_vars(ModuleInfo, ProcInfo, FailVars) :-
@@ -151,37 +159,70 @@
 		error("length mismatch in trace__fail_vars")
 	).
 
-trace__setup -->
+trace__setup(TraceLevel) -->
 	code_info__get_trace_slot(CallNumSlot),
 	code_info__get_trace_slot(CallDepthSlot),
-	{ TraceInfo = trace_info(CallNumSlot, CallDepthSlot) },
+	( { TraceLevel = full } ->
+		{ TraceType = full_trace }
+	;
+		code_info__get_trace_slot(CallFromFullSlot),
+		{ TraceType = interface_trace(CallFromFullSlot) }
+	),
+	{ TraceInfo = trace_info(CallNumSlot, CallDepthSlot, TraceType) },
 	code_info__set_maybe_trace_info(yes(TraceInfo)).
 
 trace__generate_slot_fill_code(TraceInfo, TraceCode) :-
-	TraceInfo = trace_info(CallNumLval, CallDepthLval),
+	TraceInfo = trace_info(CallNumLval, CallDepthLval, TraceType),
 	trace__stackref_to_string(CallNumLval, CallNumStr),
 	trace__stackref_to_string(CallDepthLval, CallDepthStr),
-	string__append(CallNumStr, " = MR_trace_incr_seq();\n",
-		CallNumStmt),
-	string__append(CallDepthStr, " = MR_trace_incr_depth();\n",
-		CallDepthStmt),
+	(
+		TraceType = interface_trace(CallFromFullSlot),
+		trace__stackref_to_string(CallFromFullSlot,
+			CallFromFullSlotStr),
+		string__append_list([
+			"\t\t", CallFromFullSlotStr, " = MR_trace_from_full;\n",
+			"\t\tif (MR_trace_from_full) {\n",
+			"\t\t\t", CallNumStr, " = MR_trace_incr_seq();\n",
+			"\t\t\t", CallDepthStr, " = MR_trace_incr_depth();\n",
+			"\t\t}"
+		], TraceStmt)
+	;
+		TraceType = full_trace,
+		string__append_list([
+			"\t\t", CallNumStr, " = MR_trace_incr_seq();\n",
+			"\t\t", CallDepthStr, " = MR_trace_incr_depth();"
+		], TraceStmt)
+	),
 	TraceCode = node([
-		c_code(CallNumStmt) - "",
-		c_code(CallDepthStmt) - ""
+		pragma_c([], [pragma_c_raw_code(TraceStmt)],
+			will_not_call_mercury, no, yes) - ""
 	]).
 
-trace__generate_depth_reset_code(TraceInfo, TraceCode) :-
-	TraceInfo = trace_info(_CallNumLval, CallDepthLval),
+trace__prepare_for_call(TraceInfo, TraceCode) :-
+	TraceInfo = trace_info(_CallNumLval, CallDepthLval, TraceType),
 	trace__stackref_to_string(CallDepthLval, CallDepthStr),
 	string__append_list(["MR_trace_reset_depth(", CallDepthStr, ");\n"],
-		Stmt),
-	TraceCode = node([
-		c_code(Stmt) - ""
-	]).
+		ResetDepthStmt),
+	(
+		TraceType = interface_trace(_),
+		TraceCode = node([
+			c_code("MR_trace_from_full = 0;\n") - "",
+			c_code(ResetDepthStmt) - ""
+		])
+	;
+		TraceType = full_trace,
+		TraceCode = node([
+			c_code("MR_trace_from_full = 1;\n") - "",
+			c_code(ResetDepthStmt) - ""
+		])
+	).
 
 trace__maybe_generate_internal_event_code(Goal, Code) -->
 	code_info__get_maybe_trace_info(MaybeTraceInfo),
-	( { MaybeTraceInfo = yes(TraceInfo) } ->
+	(
+		{ MaybeTraceInfo = yes(TraceInfo) },
+		{ TraceInfo = trace_info(_, _, full_trace) }
+	->
 		{ Goal = _ - GoalInfo },
 		{ goal_info_get_goal_path(GoalInfo, Path) },
 		{ goal_info_get_pre_deaths(GoalInfo, PreDeaths) },
@@ -213,7 +254,10 @@
 
 trace__maybe_generate_pragma_event_code(PragmaPort, Code) -->
 	code_info__get_maybe_trace_info(MaybeTraceInfo),
-	( { MaybeTraceInfo = yes(TraceInfo) } ->
+	(
+		{ MaybeTraceInfo = yes(TraceInfo) },
+		{ TraceInfo = trace_info(_, _, full_trace) }
+	->
 		{ trace__convert_nondet_pragma_port_type(PragmaPort, Port) },
 		trace__generate_event_code(Port, nondet_pragma, TraceInfo,
 			_, _, Code)
@@ -266,28 +310,32 @@
 	set__list_to_set(TvarDataList, TvarDataSet),
 	LayoutLabelInfo = layout_label_info(VarInfoSet, TvarDataSet),
 	llds_out__get_label(Label, yes, LabelStr),
-	TraceInfo = trace_info(CallNumLval, CallDepthLval),
+	TraceInfo = trace_info(CallNumLval, CallDepthLval, TraceType),
 	trace__stackref_to_string(CallNumLval, CallNumStr),
 	trace__stackref_to_string(CallDepthLval, CallDepthStr),
 	Quote = """",
 	Comma = ", ",
 	trace__port_to_string(Port, PortStr),
-	IfStmt = "\tif (MR_trace_enabled) {\n",
-	EndStmt = "\t}",
+	(
+		TraceType = full_trace,
+		FlagStr = "1"				% meaning true
+	;
+		TraceType = interface_trace(CallFromFullLval),
+		trace__stackref_to_string(CallFromFullLval, FlagStr)
+	),
 	SaveStmt = "\t\tsave_transient_registers();\n",
-	RestoreStmt = "\t\trestore_transient_registers();\n",
+	RestoreStmt = "\t\trestore_transient_registers();",
 	string__int_to_string(MaxReg, MaxRegStr),
 	string__append_list([
 		"\t\tMR_trace((const MR_Stack_Layout_Label *)\n",
-		"\t\t\t&mercury_data__stack_layout__", LabelStr, Comma, "\n",
+		"\t\t\t&mercury_data__layout__", LabelStr, Comma, "\n",
 		"\t\t\t", PortStr, Comma,
 		CallNumStr, Comma,
 		CallDepthStr, Comma, "\n",
 		"\t\t\t", Quote, PathStr, Quote, Comma,
-		MaxRegStr, ");\n"],
+		MaxRegStr, Comma, FlagStr, ");\n"],
 		CallStmt),
-	string__append_list([IfStmt, SaveStmt, CallStmt, RestoreStmt, EndStmt],
-		TraceStmt),
+	string__append_list([SaveStmt, CallStmt, RestoreStmt], TraceStmt),
 	TraceCode =
 		node([
 			label(Label)
@@ -300,7 +348,7 @@
 				% by another label, and this way we can
 				% eliminate this other label.
 			pragma_c([], [pragma_c_raw_code(TraceStmt)],
-				may_call_mercury, yes(Label))
+				may_call_mercury, yes(Label), yes)
 				- ""
 		]),
 	Code = tree(ProduceCode, TraceCode)
Index: compiler/value_number.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/value_number.m,v
retrieving revision 1.90
diff -u -r1.90 value_number.m
--- value_number.m	1998/01/13 10:14:00	1.90
+++ value_number.m	1998/05/11 03:28:37
@@ -1092,7 +1092,7 @@
 value_number__boundary_instr(discard_tickets_to(_), no).
 value_number__boundary_instr(incr_sp(_, _), yes).
 value_number__boundary_instr(decr_sp(_), yes).
-value_number__boundary_instr(pragma_c(_, _, _, _), yes).
+value_number__boundary_instr(pragma_c(_, _, _, _, _), yes).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/vn_block.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/vn_block.m,v
retrieving revision 1.52
diff -u -r1.52 vn_block.m
--- vn_block.m	1998/01/13 10:14:03	1.52
+++ vn_block.m	1998/05/11 03:06:18
@@ -353,7 +353,7 @@
 	vn_block__new_ctrl_node(vn_decr_sp(N), Livemap,
 		Params, VnTables0, VnTables,
 		Liveset0, Liveset, Tuple0, Tuple).
-vn_block__handle_instr(pragma_c(_, _, _, _),
+vn_block__handle_instr(pragma_c(_, _, _, _, _),
 		_Livemap, _Params, VnTables, VnTables, Liveset, Liveset,
 		SeenIncr, SeenIncr, Tuple, Tuple) :-
 	error("value numbering not supported for pragma_c").
@@ -891,7 +891,7 @@
 vn_block__is_ctrl_instr(discard_tickets_to(_), yes).
 vn_block__is_ctrl_instr(incr_sp(_, _), yes).
 vn_block__is_ctrl_instr(decr_sp(_), yes).
-vn_block__is_ctrl_instr(pragma_c(_, _, _, _), no).
+vn_block__is_ctrl_instr(pragma_c(_, _, _, _, _), no).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/vn_cost.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/vn_cost.m,v
retrieving revision 1.31
diff -u -r1.31 vn_cost.m
--- vn_cost.m	1998/01/13 10:14:06	1.31
+++ vn_cost.m	1998/05/11 03:06:23
@@ -181,7 +181,7 @@
 		Uinstr = decr_sp(_),
 		Cost = 0
 	;
-		Uinstr = pragma_c(_, _, _, _),
+		Uinstr = pragma_c(_, _, _, _, _),
 		error("pragma_c found in vn_block_cost")
 	).
 
Index: compiler/vn_filter.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/vn_filter.m,v
retrieving revision 1.16
diff -u -r1.16 vn_filter.m
--- vn_filter.m	1998/04/08 11:32:39	1.16
+++ vn_filter.m	1998/05/11 03:06:41
@@ -154,7 +154,7 @@
 vn_filter__user_instr(discard_tickets_to(Rval), yes(Rval)).
 vn_filter__user_instr(incr_sp(_, _), no).
 vn_filter__user_instr(decr_sp(_), no).
-vn_filter__user_instr(pragma_c(_, _, _, _), _):-
+vn_filter__user_instr(pragma_c(_, _, _, _, _), _):-
 	error("inappropriate instruction in vn__filter").
 
 	% vn_filter__replace_in_user_instr(Instr0, Old, New, Instr):
@@ -216,7 +216,7 @@
 	error("non-user instruction in vn_filter__replace_in_user_instr").
 vn_filter__replace_in_user_instr(decr_sp(_), _, _, _) :-
 	error("non-user instruction in vn_filter__replace_in_user_instr").
-vn_filter__replace_in_user_instr(pragma_c(_, _, _, _), _, _, _):-
+vn_filter__replace_in_user_instr(pragma_c(_, _, _, _, _), _, _, _):-
 	error("inappropriate instruction in vn__filter").
 
 	% Check whether this instruction defines the value of any lval.
@@ -248,7 +248,7 @@
 vn_filter__defining_instr(discard_tickets_to(_), no).
 vn_filter__defining_instr(incr_sp(_, _), no).
 vn_filter__defining_instr(decr_sp(_), no).
-vn_filter__defining_instr(pragma_c(_, _, _, _), _):-
+vn_filter__defining_instr(pragma_c(_, _, _, _, _), _):-
 	error("inappropriate instruction in vn__filter").
 
 	% vn_filter__replace_in_defining_instr(Instr0, Old, New, Instr):
@@ -308,7 +308,7 @@
 	error("non-def instruction in vn_filter__replace_in_defining_instr").
 vn_filter__replace_in_defining_instr(decr_sp(_), _, _, _) :-
 	error("non-def instruction in vn_filter__replace_in_defining_instr").
-vn_filter__replace_in_defining_instr(pragma_c(_, _, _, _), _, _, _):-
+vn_filter__replace_in_defining_instr(pragma_c(_, _, _, _, _), _, _, _):-
 	error("inappropriate instruction in vn__filter").
 
 	% vn_filter__replace_in_lval(Lval0, Old, New, Lval):
Index: compiler/vn_verify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/vn_verify.m,v
retrieving revision 1.16
diff -u -r1.16 vn_verify.m
--- vn_verify.m	1998/01/13 10:14:23	1.16
+++ vn_verify.m	1998/05/11 03:48:41
@@ -373,7 +373,7 @@
 		NoDeref = NoDeref0,
 		Tested = Tested0
 	;
-		Instr = pragma_c(_, _, _, _),
+		Instr = pragma_c(_, _, _, _, _),
 		error("found c_code in vn_verify__tags_instr")
 	).
 
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.121
diff -u -r1.121 user_guide.texi
--- user_guide.texi	1998/04/27 04:03:21	1.121
+++ user_guide.texi	1998/05/12 06:16:58
@@ -1684,9 +1684,10 @@
 do not assume the availability of GNU Make extensions.
 This makes these files significantly larger.
 
- at item --generate-trace
-Include code to generate an execution trace in the
-C code output by the compiler.
+ at item --trace @var{level}
+Generate code that includes the specified level of execution tracing.
+The @var{level} should be one of
+ at samp{minimal}, @samp{interface} and @samp{full}.
 
 @item --generate-bytecode
 @c Output a bytecode version of the module
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.26
diff -u -r1.26 Mmakefile
--- Mmakefile	1998/05/08 02:53:22	1.26
+++ Mmakefile	1998/05/12 08:04:07
@@ -61,6 +61,9 @@
 			mercury_tags.h		\
 			mercury_timing.h	\
 			mercury_trace.h		\
+			mercury_trace_external.h \
+			mercury_trace_internal.h \
+			mercury_trace_util.h	\
 			mercury_trail.h		\
 			mercury_types.h		\
 			mercury_type_info.h	\
@@ -104,6 +107,9 @@
 			mercury_table.c		\
 			mercury_timing.c	\
 			mercury_trace.c		\
+			mercury_trace_external.c \
+			mercury_trace_internal.c \
+			mercury_trace_util.c	\
 			mercury_trail.c 	\
 			mercury_type_info.c	\
 			mercury_wrapper.c
Index: runtime/mercury_goto.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_goto.h,v
retrieving revision 1.8
diff -u -r1.8 mercury_goto.h
--- mercury_goto.h	1998/04/08 11:33:53	1.8
+++ mercury_goto.h	1998/05/07 02:04:49
@@ -20,7 +20,7 @@
 
 #ifdef MR_USE_STACK_LAYOUTS
   #define MR_STACK_LAYOUT(label)        (Word *) (Word) \
-	&(paste(mercury_data__stack_layout__,label))
+	&(paste(mercury_data__layout__,label))
 #else
   #define MR_STACK_LAYOUT(label) (Word *) NULL
 #endif /* MR_USE_STACK_LAYOUTS */
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.4
diff -u -r1.4 mercury_stack_layout.h
--- mercury_stack_layout.h	1998/04/18 08:06:51	1.4
+++ mercury_stack_layout.h	1998/05/13 04:06:37
@@ -162,12 +162,12 @@
 
 #ifdef MR_USE_STACK_LAYOUTS
  #define MR_MAKE_STACK_LAYOUT_ENTRY(l) 					\
- const struct mercury_data__stack_layout__##l##_struct {		\
+ const struct mercury_data__layout__##l##_struct {			\
 	Code * f1;							\
 	Integer f2;							\
 	Integer f3;							\
 	Integer f4;							\
- } mercury_data__stack_layout__##l = {					\
+ } mercury_data__layout__##l = {					\
 	STATIC(l),							\
 	(Integer) -1, 	/* Unknown determinism */			\
 	(Integer) -1,	/* Unknown number of stack slots */		\
@@ -178,6 +178,20 @@
 #endif	/* MR_USE_STACK_LAYOUTS */
 
 /*
+** The layout structure for an internal label will have a field containing
+** the label number of that label (or -1, if the internal label has no
+** label number, being the entry label) only if we are using native gc.
+*/
+
+#ifdef	NATIVE_GC
+#define	UNKNOWN_INTERNAL_LABEL_FIELD	Integer f2;
+#define	UNKNOWN_INTERNAL_LABEL_NUMBER	(Integer) -1,
+#else
+#define	UNKNOWN_INTERNAL_LABEL_FIELD
+#define	UNKNOWN_INTERNAL_LABEL_NUMBER
+#endif
+
+/*
 ** Define a stack layout for an internal label. Need to supply the
 ** label name (l) and the entry label name (e).
 **
@@ -187,13 +201,13 @@
 
 #ifdef MR_USE_STACK_LAYOUTS
  #define MR_MAKE_STACK_LAYOUT_INTERNAL_WITH_ENTRY(l, e)			\
- const struct mercury_data__stack_layout__##l##_struct {		\
+ const struct mercury_data__layout__##l##_struct {			\
 	const Word * f1;						\
-	Integer f2;							\
+	UNKNOWN_INTERNAL_LABEL_FIELD					\
 	Integer f3;							\
- } mercury_data__stack_layout__##l = {					\
-	(const Word *) &mercury_data__stack_layout__##e,		\
-	(Integer) -1,		/* Unknown label number */		\
+ } mercury_data__layout__##l = {					\
+	(const Word *) &mercury_data__layout__##e,			\
+	UNKNOWN_INTERNAL_LABEL_NUMBER					\
 	(Integer) 0		/* No live values */			\
  };
 #else
@@ -218,13 +232,13 @@
 
 #ifdef MR_USE_STACK_LAYOUTS
  #define MR_MAKE_STACK_LAYOUT_INTERNAL(e, x)				\
- const struct mercury_data__stack_layout__##e##_i##x##_struct {		\
+ const struct mercury_data__layout__##e##_i##x##_struct {		\
 	const Word * f1;						\
-	Integer f2;							\
+	UNKNOWN_INTERNAL_LABEL_FIELD					\
 	Integer f3;							\
- } mercury_data__stack_layout__##e##_i##x = {				\
-	(const Word *) &mercury_data__stack_layout__##e,		\
-	(Integer) -1,		/* Unknown label number */		\
+ } mercury_data__layout__##e##_i##x = {					\
+	(const Word *) &mercury_data__layout__##e,			\
+	UNKNOWN_INTERNAL_LABEL_NUMBER					\
 	(Integer) 0		/* No live values */			\
  };
 #else
@@ -272,7 +286,9 @@
 
 typedef	struct MR_Stack_Layout_Label_Struct {
 	MR_Stack_Layout_Entry	*MR_sll_entry;
+#ifdef	NATIVE_GC
 	Integer			MR_sll_label_num;
+#endif
 	Integer			MR_sll_var_count;
 	/* the last field is present only if MR_sll_var_count > 0 */
 	MR_Stack_Layout_Vars	MR_sll_var_info;
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.10
diff -u -r1.10 mercury_wrapper.c
--- mercury_wrapper.c	1998/04/18 08:06:49	1.10
+++ mercury_wrapper.c	1998/05/06 01:59:47
@@ -158,6 +158,8 @@
 void
 mercury_runtime_init(int argc, char **argv)
 {
+	int	saved_trace_enabled;
+
 #if NUM_REAL_REGS > 0
 	Word c_regs[NUM_REAL_REGS];
 #endif
@@ -213,11 +215,25 @@
 	}
 #endif
 
-	/* process the command line and the options in the environment
-	   variable MERCURY_OPTIONS, and save results in global vars */
+	/*
+	** Process the command line and the options in the environment
+	** variable MERCURY_OPTIONS, and save results in global variables.
+	*/
+
 	process_args(argc, argv);
 	process_environment_options();
 
+	/*
+	** Some of the rest of this function may call Mercury code
+	** that may have been compiled with tracing (e.g. the initialization
+	** routines in the library called via MR_library_initializer).
+	** Since this initialization code shouldn't be traced, we disable
+	** tracing until the end of this function.
+	*/
+
+	saved_trace_enabled = MR_trace_enabled;
+	MR_trace_enabled = FALSE;
+
 #if (defined(USE_GCC_NONLOCAL_GOTOS) && !defined(USE_ASM_LABELS)) || \
 		defined(PROFILE_CALLS) || defined(PROFILE_TIME)
 	do_init_modules();
@@ -245,6 +261,13 @@
 
 	/* initialize the Mercury library */
 	(*MR_library_initializer)();
+
+	/* now the real tracing starts */
+	MR_trace_event_number = 0;
+	MR_trace_call_seqno = 0;
+	MR_trace_call_depth = 0;
+	MR_trace_from_full = 1;
+	MR_trace_enabled = saved_trace_enabled;
 
 	/*
 	** Restore the callee-save registers before returning,
Index: tests/debugger/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/Mmakefile,v
retrieving revision 1.3
diff -u -r1.3 Mmakefile
--- Mmakefile	1998/05/13 04:05:46	1.3
+++ Mmakefile	1998/05/14 05:10:52
@@ -13,7 +13,7 @@
 	interpreter	\
 	queens
 
-MCFLAGS = --generate-trace $(EXTRA_MCFLAGS)
+MCFLAGS = --trace full $(EXTRA_MCFLAGS)
 
 # Not all grades can be used with stack layouts
 #
@@ -27,6 +27,9 @@
 	endif
 endif
 
+LIBPROGS=	$(PROGS:%=%_lib)
+ALLPROGS=	$(PROGS) $(LIBPROGS)
+
 #-----------------------------------------------------------------------------#
 
 debugger_regs.out: debugger_regs debugger_regs.inp
@@ -38,24 +41,34 @@
 queens.out: queens queens.inp
 	mdb ./queens < queens.inp > queens.out
 
+debugger_regs_lib.out: debugger_regs_lib debugger_regs_lib.inp
+	mdb ./debugger_regs_lib < debugger_regs_lib.inp > debugger_regs_lib.out
+
+interpreter_lib.out: interpreter_lib interpreter_lib.inp
+	mdb ./interpreter_lib interpreter_lib.m < interpreter_lib.inp > interpreter_lib.out
+
+queens_lib.out: queens_lib queens_lib.inp
+	mdb ./queens_lib < queens_lib.inp > queens_lib.out
+
 #-----------------------------------------------------------------------------#
 
-DEPS=	$(PROGS:%=%.dep)
-DEPENDS=$(PROGS:%=%.depend)
-OUTS=	$(PROGS:%=%.out)
-RESS=	$(PROGS:%=%.res)
-MODS=	$(PROGS:%=%.mod)
+DEPS=		$(ALLPROGS:%=%.dep)
+DEPENDS=	$(ALLPROGS:%=%.depend)
+OUTS=		$(PROGS:%=%.out)
+LIBOUTS=	$(LIBPROGS:%=%.out)
+RESS=		$(PROGS:%=%.res)
+LIBRESS=	$(LIBPROGS:%=%.res)
 
 #-----------------------------------------------------------------------------#
 
-dep:	$(DEPS)
+dep:		$(DEPS)
 
-depend:	$(DEPENDS)
+depend:		$(DEPENDS)
 
-check:	$(OUTS) $(RESS)
+check:		$(OUTS) $(RESS)
 
-mods:	$(MODS)
+check_lib:	$(LIBOUTS) $(LIBRESS)
 
-all:	$(PROGS)
+all:		$(ALLPROGS)
 
 #-----------------------------------------------------------------------------#
Index: tests/debugger/runtests
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/runtests,v
retrieving revision 1.3
diff -u -r1.3 runtests
--- runtests	1998/05/13 04:05:48	1.3
+++ runtests	1998/05/14 05:05:07
@@ -19,9 +19,23 @@
 	. ../shutdown
 	exit 0
 else
-	echo "the tests in the debugger directory failed"
-	echo "gradeopt=$gradeopt, flagsopt=$flagsopt, cflagsopt=$cflagsopt"
-	echo "the differences are:"
-	cat .allres
-	exit 1
+	/bin/rm *.res
+	eval mmake -k $jfactor $gradeopt $flagsopt $cflagsopt check_lib
+	checkstatus=$?
+
+	cat *.res > .allres
+	if test ! -s .allres -a "$checkstatus" = 0
+	then
+		echo "the tests in the debugger directory succeeded"
+		echo "gradeopt=$gradeopt, flagsopt=$flagsopt, cflagsopt=$cflagsopt"
+		rm -f .allres
+		. ../shutdown
+		exit 0
+	else
+		echo "the tests in the debugger directory failed"
+		echo "gradeopt=$gradeopt, flagsopt=$flagsopt, cflagsopt=$cflagsopt"
+		echo "the differences are:"
+		cat .allres
+		exit 1
+	fi
 fi



More information about the developers mailing list