for review: cleanup of c_modules

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Nov 17 20:00:41 AEDT 1998


This is for Peter Ross to review, and for commit after the release.

Estimated hours taken: 6

Change the LLDS representation of a module from containing a list of c_modules
to containing four lists, of (a) compiler generated C code, (b) compiler
generated data, (c) user-written C code and (d) exported C functions.
This simplifies the several passes (e.g. transform_llds, llds_common)
that only care about one kind of "c_module".

compiler/llds.m:
	Change the definition of c_file along the lines above.

compiler/llds_out.m:
	Write out the new data structure.

	Change some predicate names to make it clear what predicates
	handle the splitting of C files.

	Remove the obsolete #define of MR_USE_REDOFR

compiler/base_type_info.m:
compiler/base_type_layout.m:
compiler/base_typeclass_info.m:
	Adapt to the new data structure.

compiler/llds_common.m:
	Use the new data structure to simplify the code.
	Change the order of some arguments to conform to our usual
	conventions.

compiler/transform_llds.m:
	Use the new data structure to simplify the code.

compiler/mercury_compile.m:
	Adapt the gathering of the c_file components to the new data structure.
	Fix a predicate name.

	Fix a bug: stack layouts were always treated as static data, although
	proc layouts are only static if we have static code addresses.

compiler/stackl_layout.m:
	Return the proc layouts and the label layouts in separate lists,
	since only label layouts are always static data.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
Index: compiler/base_type_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/base_type_info.m,v
retrieving revision 1.20
diff -u -u -r1.20 base_type_info.m
--- base_type_info.m	1998/11/02 09:48:56	1.20
+++ base_type_info.m	1998/11/13 11:19:58
@@ -31,7 +31,7 @@
 :- pred base_type_info__generate_hlds(module_info, module_info).
 :- mode base_type_info__generate_hlds(in, out) is det.
 
-:- pred base_type_info__generate_llds(module_info, list(c_module)).
+:- pred base_type_info__generate_llds(module_info, list(comp_gen_c_data)).
 :- mode base_type_info__generate_llds(in, out) is det.
 
 :- implementation.
@@ -131,7 +131,7 @@
 	list__append(CModules1, CModules2, CModules).
 
 :- pred base_type_info__construct_base_type_infos(list(base_gen_info),
-	module_info, list(c_module)).
+	module_info, list(comp_gen_c_data)).
 :- mode base_type_info__construct_base_type_infos(in, in, out) is det.
 
 base_type_info__construct_base_type_infos([], _, []).
@@ -169,8 +169,9 @@
 	;
 		FinalArgs = PredAddrArgs
 	),
-	CModule = c_data(ModuleName, base_type(info, TypeName, TypeArity),
-			Exported, [ArityArg | FinalArgs], Procs),
+	DataName = base_type(info, TypeName, TypeArity),
+	CModule = comp_gen_c_data(ModuleName, DataName, Exported,
+		[ArityArg | FinalArgs], Procs),
 	base_type_info__construct_base_type_infos(BaseGenInfos, ModuleInfo,
 		CModules).
 
Index: compiler/base_type_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/base_type_layout.m,v
retrieving revision 1.35
diff -u -u -r1.35 base_type_layout.m
--- base_type_layout.m	1998/11/02 02:38:08	1.35
+++ base_type_layout.m	1998/11/13 11:23:06
@@ -225,7 +225,7 @@
 :- mode base_type_layout__generate_hlds(in, out) is det.
 
 :- pred base_type_layout__generate_llds(module_info, module_info,
-		list(c_module)).
+		list(comp_gen_c_data)).
 :- mode base_type_layout__generate_llds(in, out, out) is det.
 
 	% stack_layout.m uses this.
@@ -248,7 +248,7 @@
 		int,		% number of tags available
 		int,		% next available label 
 		type_id,	% type_id of type being currently examined
-		list(c_module)	% generated data
+		list(comp_gen_c_data)	% generated data
 	).
 
 :- type tag_category	--->	simple 		% tagged pointer
@@ -419,13 +419,15 @@
 	->
 		LayoutInfo5 = LayoutInfo3
 	;
-		CModule = c_data(ModuleName, base_type(layout, TypeName, 
-			TypeArity), Exported, LayoutTypeData, []),
-		CModule2 = c_data(ModuleName, base_type(functors, TypeName, 
-			TypeArity), Exported, FunctorsTypeData, []),
-		base_type_layout__add_cmodule(LayoutInfo3, CModule, 
+		LayoutDataName = base_type(layout, TypeName, TypeArity),
+		LayoutCData = comp_gen_c_data(ModuleName, LayoutDataName,
+			Exported, LayoutTypeData, []),
+		FunctorsDataName = base_type(functors, TypeName, TypeArity),
+		FunctorsCData = comp_gen_c_data(ModuleName, FunctorsDataName,
+			Exported, FunctorsTypeData, []),
+		base_type_layout__add_c_data(LayoutInfo3, LayoutCData, 
 			LayoutInfo4),
-		base_type_layout__add_cmodule(LayoutInfo4, CModule2, 
+		base_type_layout__add_c_data(LayoutInfo4, FunctorsCData, 
 			LayoutInfo5)
 	),
 	base_type_layout__construct_base_type_data(BaseGenInfos, LayoutInfo5,
@@ -1277,14 +1279,15 @@
 base_type_layout__get_type_id(LayoutInfo, TypeId) :-
 	LayoutInfo = layout_info(_, _, _, _, TypeId, _).
 
-:- pred base_type_layout__get_cmodules(layout_info, list(c_module)).
-:- mode base_type_layout__get_cmodules(in, out) is det.
-base_type_layout__get_cmodules(LayoutInfo, CModules) :-
+:- pred base_type_layout__get_c_data(layout_info, list(comp_gen_c_data)).
+:- mode base_type_layout__get_c_data(in, out) is det.
+base_type_layout__get_c_data(LayoutInfo, CModules) :-
 	LayoutInfo = layout_info(_, _, _, _, _, CModules).
 
-:- pred base_type_layout__add_cmodule(layout_info, c_module, layout_info).
-:- mode base_type_layout__add_cmodule(in, in, out) is det.
-base_type_layout__add_cmodule(LayoutInfo0, CModule, LayoutInfo) :-
+:- pred base_type_layout__add_c_data(layout_info, comp_gen_c_data,
+	layout_info).
+:- mode base_type_layout__add_c_data(in, in, out) is det.
+base_type_layout__add_c_data(LayoutInfo0, CModule, LayoutInfo) :-
 	LayoutInfo0 = layout_info(A, B, C, D, E, CModules0),
 	CModules = [CModule | CModules0],
 	LayoutInfo = layout_info(A, B, C, D, E, CModules).
Index: compiler/base_typeclass_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/base_typeclass_info.m,v
retrieving revision 1.7
diff -u -u -r1.7 base_typeclass_info.m
--- base_typeclass_info.m	1998/11/02 09:48:57	1.7
+++ base_typeclass_info.m	1998/11/13 11:18:35
@@ -22,7 +22,7 @@
 
 :- import_module hlds_module, list, llds, prog_data.
 
-:- pred base_typeclass_info__generate_llds(module_info, list(c_module)).
+:- pred base_typeclass_info__generate_llds(module_info, list(comp_gen_c_data)).
 :- mode base_typeclass_info__generate_llds(in, out) is det.
 
 	% Given a list of types, mangle the names so into a string which
@@ -47,7 +47,8 @@
 		ModuleInfo, CModules).
 
 :- pred base_typeclass_info__gen_infos_for_classes(assoc_list(class_id,
-	list(hlds_instance_defn)), module_name, module_info, list(c_module)).
+	list(hlds_instance_defn)), module_name, module_info,
+	list(comp_gen_c_data)).
 :- mode base_typeclass_info__gen_infos_for_classes(in, in, in, out) is det.
 
 base_typeclass_info__gen_infos_for_classes([], _ModuleName, _ModuleInfo, []).
@@ -63,7 +64,7 @@
 	% XXX make it use an accumulator
 :- pred base_typeclass_info__gen_infos_for_instance_list(
 	pair(class_id, list(hlds_instance_defn)), module_name, module_info,
-	list(c_module)).
+	list(comp_gen_c_data)).
 :- mode base_typeclass_info__gen_infos_for_instance_list(in, in, in, out) 
 	is det.
 
@@ -102,7 +103,8 @@
 			% that we do.)
 		Status = yes,
 
-		CModule = c_data(ModuleName, DataName, Status, Rvals, Procs),
+		CModule = comp_gen_c_data(ModuleName, DataName,
+			Status, Rvals, Procs),
 		CModules = [CModule | CModules1]
 	;
 			% The instance decl is from another module, so
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.231
diff -u -u -r1.231 llds.m
--- llds.m	1998/11/12 03:15:39	1.231
+++ llds.m	1998/11/13 11:14:06
@@ -66,18 +66,25 @@
 	--->	c_file(
 			module_name,
 			c_header_info,
-			list(c_module)
+			list(user_c_code),
+			list(c_export),
+			list(comp_gen_c_data),
+			list(comp_gen_c_module)
 		).
 
-:- type c_module
-		% a bunch of low-level C code
-	--->	c_module(
-			string,			% the name of this C module
-			list(c_procedure) 	% code
-		)
+	% Some C code from a `pragma c_code' declaration that is not
+	% associated with a given procedure.
+:- type user_c_code
+	--->	user_c_code(
+			string,			% C code
+			term__context		% source code location
+		).
 
-		% readonly data, usually containing a typeinfo structure
-	;	c_data(
+	% Global data generated by the compiler. Usually readonly,
+	% with one exception: data containing code addresses must
+	% be initialized.
+:- type comp_gen_c_data
+	--->	comp_gen_c_data(
 			module_name,		% The basename of this C file.
 			data_name,		% A representation of the name
 						% of the variable; it will be
@@ -90,17 +97,12 @@
 			list(maybe(rval)),	% The arguments of the create.
 			list(pred_proc_id)	% The procedures referenced.
 						% Used by dead_proc_elim.
-		)
-
-		% some C code from a `pragma c_code' declaration
-	;	c_code(
-			string,			% C code
-			term__context		% source code location
-		)
+		).
 
-		% Code from `pragma export' decls.
-	;	c_export(
-			list(c_export)
+:- type comp_gen_c_module
+	--->	comp_gen_c_module(
+			string,			% the name of this C module
+			list(c_procedure) 	% code
 		).
 
 :- type c_procedure
Index: compiler/llds_common.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_common.m,v
retrieving revision 1.20
diff -u -u -r1.20 llds_common.m
--- llds_common.m	1998/07/29 08:53:17	1.20
+++ llds_common.m	1998/11/15 07:00:03
@@ -24,9 +24,9 @@
 :- import_module prog_data. % for module_name
 :- import_module list.
 
-:- pred llds_common(list(c_procedure), list(c_module), module_name, 
-	list(c_procedure), list(c_module), list(c_module)).
-:- mode llds_common(in, in, in, out, out, out) is det.
+:- pred llds_common(list(c_procedure)::in, list(comp_gen_c_data)::in,
+	module_name::in, list(c_procedure)::out, list(comp_gen_c_data)::out)
+	is det.
 
 :- implementation.
 
@@ -48,11 +48,11 @@
 					% information
 		).
 
-llds_common(Procedures0, Data0, BaseName, Procedures, Data, DataModules) :-
+llds_common(Procedures0, Data0, BaseName, Procedures, Data) :-
 	map__init(CellMap0),
 	Info0 = common_info(BaseName, 0, CellMap0),
-	llds_common__process_procs(Procedures0, Info0, Info1, Procedures),
-	llds_common__process_modules(Data0, Info1, Info, Data),
+	llds_common__process_procs(Procedures0, Procedures, Info0, Info1),
+	llds_common__process_datas(Data0, Data1, Info1, Info),
 	Info = common_info(_, _, CellMap),
 	map__to_assoc_list(CellMap, CellPairs0),
 	list__sort(lambda([CellPairA::in, CellPairB::in, Compare::out] is det, 
@@ -61,25 +61,25 @@
 			CellPairB = _ - cell_info(BNum),
 			compare(Compare, ANum, BNum)
 		)), CellPairs0, CellPairs),
-	llds_common__cell_pairs_to_modules(CellPairs, BaseName, DataModules).
+	llds_common__cell_pairs_to_modules(CellPairs, BaseName, CommonData),
+	list__append(CommonData, Data1, Data).
 
 :- pred llds_common__cell_pairs_to_modules(
-	assoc_list(list(maybe(rval)), cell_info), module_name, list(c_module)).
-:- mode llds_common__cell_pairs_to_modules(in, in, out) is det.
+	assoc_list(list(maybe(rval)), cell_info)::in, module_name::in,
+	list(comp_gen_c_data)::out) is det.
 
 llds_common__cell_pairs_to_modules([], _, []).
 llds_common__cell_pairs_to_modules([Args - CellInfo | CellPairs], BaseName,
-		[Module | Modules]) :-
+		[Common | Commons]) :-
 	CellInfo = cell_info(VarNum),
-	Module = c_data(BaseName, common(VarNum), no, Args, []),
-	llds_common__cell_pairs_to_modules(CellPairs, BaseName, Modules).
+	Common = comp_gen_c_data(BaseName, common(VarNum), no, Args, []),
+	llds_common__cell_pairs_to_modules(CellPairs, BaseName, Commons).
 
-:- pred llds_common__process_create(tag, list(maybe(rval)),
-	common_info, common_info, rval).
-:- mode llds_common__process_create(in, in, in, out, out) is det.
+:- pred llds_common__process_create(tag::in, list(maybe(rval))::in,
+	rval::out, common_info::in, common_info::out) is det.
 
-llds_common__process_create(Tag, Args0, Info0, Info, Rval) :-
-	llds_common__process_maybe_rvals(Args0, Info0, Info1, Args),
+llds_common__process_create(Tag, Args0, Rval, Info0, Info) :-
+	llds_common__process_maybe_rvals(Args0, Args, Info0, Info1),
 	Info1 = common_info(BaseName, NextCell0, CellMap0),
 	( map__search(CellMap0, Args, CellInfo0) ->
 		CellInfo0 = cell_info(VarNum),
@@ -102,63 +102,52 @@
 	% The rest of the file is quite boring. Its only job is to traverse
 	% the various components of c_modules to arrive at the creates.
 
+:- pred llds_common__process_datas(list(comp_gen_c_data)::in,
+	list(comp_gen_c_data)::out, common_info::in, common_info::out) is det.
 
-	% Only c_data elements are processed, all other elements are ignored.
-	
-:- pred llds_common__process_modules(list(c_module), common_info, common_info,
-	list(c_module)).
-:- mode llds_common__process_modules(in, in, out, out) is det.
-
-llds_common__process_modules([], Info, Info, []).
-llds_common__process_modules([Module0 | Modules0], Info0, Info, 
-		[Module | Modules]) :-
-	llds_common__process_module(Module0, Info0, Info1, Module),
-	llds_common__process_modules(Modules0, Info1, Info, Modules).
-
-:- pred llds_common__process_module(c_module, common_info, common_info,
-	c_module).
-:- mode llds_common__process_module(in, in, out, out) is det.
-
-llds_common__process_module(c_module(Name, Ps), Info, Info, c_module(Name, Ps)).
-llds_common__process_module(c_code(Cde, Ctxt), Info, Info, c_code(Cde, Ctxt)).
-llds_common__process_module(c_export(Exports), Info, Info, c_export(Exports)).
-llds_common__process_module(
-		c_data(Name, DataName, Export, Args0, Refs), Info0, 
-		Info, c_data(Name, DataName, Export, Args, Refs)) :-
-	llds_common__process_maybe_rvals(Args0, Info0, Info, Args).
-
-:- pred llds_common__process_procs(list(c_procedure), common_info, common_info,
-	list(c_procedure)).
-:- mode llds_common__process_procs(in, in, out, out) is det.
-
-llds_common__process_procs([], Info, Info, []).
-llds_common__process_procs([Proc0 | Procs0], Info0, Info, [Proc | Procs]) :-
-	llds_common__process_proc(Proc0, Info0, Info1, Proc),
-	llds_common__process_procs(Procs0, Info1, Info, Procs).
-
-:- pred llds_common__process_proc(c_procedure, common_info, common_info,
-	c_procedure).
-:- mode llds_common__process_proc(in, in, out, out) is det.
+llds_common__process_datas([], [], Info, Info).
+llds_common__process_datas([Data0 | Datas0], [Data | Datas], Info0, Info) :-
+	llds_common__process_data(Data0, Data, Info0, Info1),
+	llds_common__process_datas(Datas0, Datas, Info1, Info).
+
+:- pred llds_common__process_data(comp_gen_c_data::in, comp_gen_c_data::out,
+	common_info::in, common_info::out) is det.
+
+llds_common__process_data(
+		comp_gen_c_data(Name, DataName, Export, Args0, Refs),
+		comp_gen_c_data(Name, DataName, Export, Args, Refs),
+		Info0, Info) :-
+	llds_common__process_maybe_rvals(Args0, Args, Info0, Info).
+
+:- pred llds_common__process_procs(list(c_procedure)::in,
+	list(c_procedure)::out, common_info::in, common_info::out) is det.
+
+llds_common__process_procs([], [], Info, Info).
+llds_common__process_procs([Proc0 | Procs0], [Proc | Procs], Info0, Info) :-
+	llds_common__process_proc(Proc0, Proc, Info0, Info1),
+	llds_common__process_procs(Procs0, Procs, Info1, Info).
 
-llds_common__process_proc(Proc0, Info0, Info, Proc) :-
+:- pred llds_common__process_proc(c_procedure::in, c_procedure::out,
+	common_info::in, common_info::out) is det.
+
+llds_common__process_proc(Proc0, Proc, Info0, Info) :-
 	Proc0 = c_procedure(Name, Arity, PredProcId, Instrs0),
-	llds_common__process_instrs(Instrs0, Info0, Info, Instrs),
+	llds_common__process_instrs(Instrs0, Instrs, Info0, Info),
 	Proc = c_procedure(Name, Arity, PredProcId, Instrs).
 
-:- pred llds_common__process_instrs(list(instruction),
-	common_info, common_info, list(instruction)).
-:- mode llds_common__process_instrs(in, in, out, out) is det.
-
-llds_common__process_instrs([], Info, Info, []).
-llds_common__process_instrs([Uinstr0 - Comment | Instrs0], Info0, Info,
-		[Uinstr - Comment | Instrs]) :-
-	llds_common__process_instr(Uinstr0, Info0, Info1, Uinstr),
-	llds_common__process_instrs(Instrs0, Info1, Info, Instrs).
+:- pred llds_common__process_instrs(list(instruction)::in,
+	list(instruction)::out, common_info::in, common_info::out) is det.
+
+llds_common__process_instrs([], [], Info, Info).
+llds_common__process_instrs([Uinstr0 - Comment | Instrs0],
+		[Uinstr - Comment | Instrs], Info0, Info) :-
+	llds_common__process_instr(Uinstr0, Uinstr, Info0, Info1),
+	llds_common__process_instrs(Instrs0, Instrs, Info1, Info).
 
-:- pred llds_common__process_instr(instr, common_info, common_info, instr).
-:- mode llds_common__process_instr(in, in, out, out) is det.
+:- pred llds_common__process_instr(instr::in, instr::out,
+	common_info::in, common_info::out) is det.
 
-llds_common__process_instr(Instr0, Info0, Info, Instr) :-
+llds_common__process_instr(Instr0, Instr, Info0, Info) :-
 	(
 		Instr0 = comment(_),
 		Instr = Instr0,
@@ -169,11 +158,11 @@
 		Info = Info0
 	;
 		Instr0 = block(NR, NF, Instrs0),
-		llds_common__process_instrs(Instrs0, Info0, Info, Instrs),
+		llds_common__process_instrs(Instrs0, Instrs, Info0, Info),
 		Instr = block(NR, NF, Instrs)
 	;
 		Instr0 = assign(Lval, Rval0),
-		llds_common__process_rval(Rval0, Info0, Info, Rval),
+		llds_common__process_rval(Rval0, Rval, Info0, Info),
 		Instr = assign(Lval, Rval)
 	;
 		Instr0 = call(_, _, _, _),
@@ -194,7 +183,7 @@
 	;
 		% unlikely to find anything to share, but why not try?
 		Instr0 = computed_goto(Rval0, Labels),
-		llds_common__process_rval(Rval0, Info0, Info, Rval),
+		llds_common__process_rval(Rval0, Rval, Info0, Info),
 		Instr = computed_goto(Rval, Labels)
 	;
 		Instr0 = c_code(_),
@@ -203,12 +192,12 @@
 	;
 		% unlikely to find anything to share, but why not try?
 		Instr0 = if_val(Rval0, Target),
-		llds_common__process_rval(Rval0, Info0, Info, Rval),
+		llds_common__process_rval(Rval0, Rval, Info0, Info),
 		Instr = if_val(Rval, Target)
 	;
 		% unlikely to find anything to share, but why not try?
 		Instr0 = incr_hp(Lval, MaybeTag, Rval0, Msg),
-		llds_common__process_rval(Rval0, Info0, Info, Rval),
+		llds_common__process_rval(Rval0, Rval, Info0, Info),
 		Instr = incr_hp(Lval, MaybeTag, Rval, Msg)
 	;
 		Instr0 = mark_hp(_),
@@ -217,7 +206,7 @@
 	;
 		% unlikely to find anything to share, but why not try?
 		Instr0 = restore_hp(Rval0),
-		llds_common__process_rval(Rval0, Info0, Info, Rval),
+		llds_common__process_rval(Rval0, Rval, Info0, Info),
 		Instr = restore_hp(Rval)
 	;
 		Instr0 = store_ticket(_),
@@ -226,7 +215,7 @@
 	;
 		% unlikely to find anything to share, but why not try?
 		Instr0 = reset_ticket(Rval0, Reason),
-		llds_common__process_rval(Rval0, Info0, Info, Rval),
+		llds_common__process_rval(Rval0, Rval, Info0, Info),
 		Instr = reset_ticket(Rval, Reason)
 	;
 		Instr0 = discard_ticket,
@@ -270,10 +259,10 @@
 		Info = Info0
 	).
 
-:- pred llds_common__process_rval(rval, common_info, common_info, rval).
-:- mode llds_common__process_rval(in, in, out, out) is det.
+:- pred llds_common__process_rval(rval::in, rval::out,
+	common_info::in, common_info::out) is det.
 
-llds_common__process_rval(Rval0, Info0, Info, Rval) :-
+llds_common__process_rval(Rval0, Rval, Info0, Info) :-
 	(
 		Rval0 = lval(_),
 		Rval = Rval0,
@@ -284,15 +273,15 @@
 	;
 		Rval0 = create(Tag, Args, Unique, _LabelNo, _Msg),
 		( Unique = no ->
-			llds_common__process_create(Tag, Args, Info0,
-				Info, Rval)
+			llds_common__process_create(Tag, Args, Rval,
+				Info0, Info)
 		;
 			Rval = Rval0,
 			Info = Info0
 		)
 	;
 		Rval0 = mkword(Tag, SubRval0),
-		llds_common__process_rval(SubRval0, Info0, Info, SubRval),
+		llds_common__process_rval(SubRval0, SubRval, Info0, Info),
 		Rval = mkword(Tag, SubRval)
 	;
 		Rval0 = const(_),
@@ -300,53 +289,49 @@
 		Info = Info0
 	;
 		Rval0 = unop(Unop, SubRval0),
-		llds_common__process_rval(SubRval0, Info0, Info, SubRval),
+		llds_common__process_rval(SubRval0, SubRval, Info0, Info),
 		Rval = unop(Unop, SubRval)
 	;
 		Rval0 = binop(Binop, Left0, Right0),
-		llds_common__process_rval(Left0, Info0, Info1, Left),
-		llds_common__process_rval(Right0, Info1, Info, Right),
+		llds_common__process_rval(Left0, Left, Info0, Info1),
+		llds_common__process_rval(Right0, Right, Info1, Info),
 		Rval = binop(Binop, Left, Right)
 	;
 		Rval0 = mem_addr(MemRef0),
-		llds_common__process_mem_ref(MemRef0, Info0, Info, MemRef),
+		llds_common__process_mem_ref(MemRef0, MemRef, Info0, Info),
 		Rval = mem_addr(MemRef)
 	).
 
-:- pred llds_common__process_mem_ref(mem_ref, common_info, common_info,
-	mem_ref).
-:- mode llds_common__process_mem_ref(in, in, out, out) is det.
-
-llds_common__process_mem_ref(stackvar_ref(N), Info, Info, stackvar_ref(N)).
-llds_common__process_mem_ref(framevar_ref(N), Info, Info, framevar_ref(N)).
-llds_common__process_mem_ref(heap_ref(Rval0, Tag, N), Info0, Info,
-		heap_ref(Rval, Tag, N)) :-
-	llds_common__process_rval(Rval0, Info0, Info, Rval).
-
-:- pred llds_common__process_rvals(list(rval), common_info, common_info,
-	list(rval)).
-:- mode llds_common__process_rvals(in, in, out, out) is det.
-
-llds_common__process_rvals([], Info, Info, []).
-llds_common__process_rvals([Rval0 | Rvals0], Info0, Info,
-		[Rval | Rvals]) :-
-	llds_common__process_rval(Rval0, Info0, Info1, Rval),
-	llds_common__process_rvals(Rvals0, Info1, Info, Rvals).
-
-:- pred llds_common__process_maybe_rvals(list(maybe(rval)),
-	common_info, common_info, list(maybe(rval))).
-:- mode llds_common__process_maybe_rvals(in, in, out, out) is det.
-
-llds_common__process_maybe_rvals([], Info, Info, []).
-llds_common__process_maybe_rvals([MaybeRval0 | MaybeRvals0], Info0, Info,
-		[MaybeRval | MaybeRvals]) :-
+:- pred llds_common__process_mem_ref(mem_ref::in, mem_ref::out,
+	common_info::in, common_info::out) is det.
+
+llds_common__process_mem_ref(stackvar_ref(N), stackvar_ref(N), Info, Info).
+llds_common__process_mem_ref(framevar_ref(N), framevar_ref(N), Info, Info).
+llds_common__process_mem_ref(heap_ref(Rval0, Tag, N), heap_ref(Rval, Tag, N),
+		Info0, Info) :-
+	llds_common__process_rval(Rval0, Rval, Info0, Info).
+
+:- pred llds_common__process_rvals(list(rval)::in, list(rval)::out,
+	common_info::in, common_info::out) is det.
+
+llds_common__process_rvals([], [], Info, Info).
+llds_common__process_rvals([Rval0 | Rvals0], [Rval | Rvals], Info0, Info) :-
+	llds_common__process_rval(Rval0, Rval, Info0, Info1),
+	llds_common__process_rvals(Rvals0, Rvals, Info1, Info).
+
+:- pred llds_common__process_maybe_rvals(list(maybe(rval))::in,
+	list(maybe(rval))::out,	common_info::in, common_info::out) is det.
+
+llds_common__process_maybe_rvals([], [], Info, Info).
+llds_common__process_maybe_rvals([MaybeRval0 | MaybeRvals0],
+		[MaybeRval | MaybeRvals], Info0, Info) :-
 	(
 		MaybeRval0 = yes(Rval0),
-		llds_common__process_rval(Rval0, Info0, Info1, Rval),
+		llds_common__process_rval(Rval0, Rval, Info0, Info1),
 		MaybeRval = yes(Rval)
 	;
 		MaybeRval0 = no,
 		MaybeRval = no,
 		Info1 = Info0
 	),
-	llds_common__process_maybe_rvals(MaybeRvals0, Info1, Info, MaybeRvals).
+	llds_common__process_maybe_rvals(MaybeRvals0, MaybeRvals, Info1, Info).
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.96
diff -u -u -r1.96 llds_out.m
--- llds_out.m	1998/11/12 03:15:41	1.96
+++ llds_out.m	1998/11/13 11:14:32
@@ -167,43 +167,81 @@
 output_llds(C_File, StackLayoutLabels) -->
 	globals__io_lookup_bool_option(split_c_files, SplitFiles),
 	( { SplitFiles = yes } ->
-		{ C_File = c_file(ModuleName, C_HeaderInfo, C_Modules) },
+		{ C_File = c_file(ModuleName, C_HeaderInfo,
+			UserCCodes, Exports, Datas, Modules) },
 		module_name_to_file_name(ModuleName, ".dir", yes, ObjDirName),
 		make_directory(ObjDirName),
-		output_split_c_file_init(ModuleName, C_Modules,
+		output_split_c_file_init(ModuleName, Modules, Datas,
 			StackLayoutLabels),
-		output_split_c_file_list(C_Modules, 1, ModuleName,
-			C_HeaderInfo, StackLayoutLabels)
+		output_split_user_c_codes(UserCCodes, ModuleName,
+			C_HeaderInfo, StackLayoutLabels, 1, Num1),
+		output_split_c_exports(Exports, ModuleName,
+			C_HeaderInfo, StackLayoutLabels, Num1, Num2),
+		output_split_comp_gen_c_datas(Datas, ModuleName,
+			C_HeaderInfo, StackLayoutLabels, Num2, Num3),
+		output_split_comp_gen_c_modules(Modules, ModuleName,
+			C_HeaderInfo, StackLayoutLabels, Num3, _Num)
 	;
 		output_single_c_file(C_File, no, StackLayoutLabels)
 	).
 
-:- pred make_directory(string, io__state, io__state).
-:- mode make_directory(in, di, uo) is det.
+:- pred output_split_user_c_codes(list(user_c_code)::in,
+	module_name::in, list(c_header_code)::in, set_bbbtree(label)::in,
+	int::in, int::out, io__state::di, io__state::uo) is det.
+
+output_split_user_c_codes([], _, _, _, Num, Num) --> [].
+output_split_user_c_codes([UserCCode | UserCCodes], ModuleName, C_HeaderLines,
+		StackLayoutLabels, Num0, Num) -->
+	{ CFile = c_file(ModuleName, C_HeaderLines, [UserCCode], [], [], []) },
+	output_single_c_file(CFile, yes(Num0), StackLayoutLabels),
+	{ Num1 is Num0 + 1 },
+	output_split_user_c_codes(UserCCodes, ModuleName, C_HeaderLines,
+		StackLayoutLabels, Num1, Num).
+
+:- pred output_split_c_exports(list(c_export)::in,
+	module_name::in, list(c_header_code)::in, set_bbbtree(label)::in,
+	int::in, int::out, io__state::di, io__state::uo) is det.
+
+output_split_c_exports([], _, _, _, Num, Num) --> [].
+output_split_c_exports([Export | Exports], ModuleName, C_HeaderLines,
+		StackLayoutLabels, Num0, Num) -->
+	{ CFile = c_file(ModuleName, C_HeaderLines, [], [Export], [], []) },
+	output_single_c_file(CFile, yes(Num0), StackLayoutLabels),
+	{ Num1 is Num0 + 1 },
+	output_split_c_exports(Exports, ModuleName, C_HeaderLines,
+		StackLayoutLabels, Num1, Num).
+
+:- pred output_split_comp_gen_c_datas(list(comp_gen_c_data)::in,
+	module_name::in, list(c_header_code)::in, set_bbbtree(label)::in,
+	int::in, int::out, io__state::di, io__state::uo) is det.
+
+output_split_comp_gen_c_datas([], _, _, _, Num, Num) --> [].
+output_split_comp_gen_c_datas([Data | Datas], ModuleName, C_HeaderLines,
+		StackLayoutLabels, Num0, Num) -->
+	{ CFile = c_file(ModuleName, C_HeaderLines, [], [], [Data], []) },
+	output_single_c_file(CFile, yes(Num0), StackLayoutLabels),
+	{ Num1 is Num0 + 1 },
+	output_split_comp_gen_c_datas(Datas, ModuleName, C_HeaderLines,
+		StackLayoutLabels, Num1, Num).
+
+:- pred output_split_comp_gen_c_modules(list(comp_gen_c_module)::in,
+	module_name::in, list(c_header_code)::in, set_bbbtree(label)::in,
+	int::in, int::out, io__state::di, io__state::uo) is det.
+
+output_split_comp_gen_c_modules([], _, _, _, Num, Num) --> [].
+output_split_comp_gen_c_modules([Module | Modules], ModuleName, C_HeaderLines,
+		StackLayoutLabels, Num0, Num) -->
+	{ CFile = c_file(ModuleName, C_HeaderLines, [], [], [], [Module]) },
+	output_single_c_file(CFile, yes(Num0), StackLayoutLabels),
+	{ Num1 is Num0 + 1 },
+	output_split_comp_gen_c_modules(Modules, ModuleName, C_HeaderLines,
+		StackLayoutLabels, Num1, Num).
+
+:- pred output_split_c_file_init(module_name, list(comp_gen_c_module),
+	list(comp_gen_c_data), set_bbbtree(label), io__state, io__state).
+:- mode output_split_c_file_init(in, in, in, in, di, uo) is det.
 
-make_directory(DirName) -->
-	{ string__format("[ -d %s ] || mkdir -p %s", [s(DirName), s(DirName)],
-		Command) },
-	io__call_system(Command, _Result).
-
-:- pred output_split_c_file_list(list(c_module), int, module_name,
-	list(c_header_code), set_bbbtree(label), io__state, io__state).
-:- mode output_split_c_file_list(in, in, in, in, in, di, uo) is det.
-
-output_split_c_file_list([], _, _, _, _) --> [].
-output_split_c_file_list([Module|Modules], Num, ModuleName, C_HeaderLines,
-		StackLayoutLabels) -->
-	output_single_c_file(c_file(ModuleName, C_HeaderLines, [Module]),
-		yes(Num), StackLayoutLabels),
-	{ Num1 is Num + 1 },
-	output_split_c_file_list(Modules, Num1, ModuleName, C_HeaderLines,
-		StackLayoutLabels).
-
-:- pred output_split_c_file_init(module_name, list(c_module),
-	set_bbbtree(label), io__state, io__state).
-:- mode output_split_c_file_init(in, in, in, di, uo) is det.
-
-output_split_c_file_init(ModuleName, C_Modules, StackLayoutLabels) -->
+output_split_c_file_init(ModuleName, Modules, Datas, StackLayoutLabels) -->
 	module_name_to_file_name(ModuleName, ".m", no, SourceFileName),
 	module_name_to_split_c_file_name(ModuleName, 0, ".c", FileName),
 
@@ -227,7 +265,7 @@
 		io__write_string("*/\n\n"),
 		output_c_file_mercury_headers,
 		io__write_string("\n"),
-		output_c_module_init_list(ModuleName, C_Modules,
+		output_c_module_init_list(ModuleName, Modules, Datas,
 			StackLayoutLabels),
 		io__told
 	;
@@ -244,11 +282,6 @@
 :- mode output_c_file_mercury_headers(di, uo) is det.
 
 output_c_file_mercury_headers -->
-		% The next two lines are only until MR_USE_REDOFR is default.
-		% The #undef avoids a warning if the invocation of mgnuc
-		% also supplies a definition on the command line.
-	io__write_string("#undef MR_USE_REDOFR\n"),
-	io__write_string("#define MR_USE_REDOFR\n"),
 	globals__io_get_trace_level(TraceLevel),
 	( { TraceLevel \= none } ->
 		io__write_string("#include ""mercury_imp.h""\n"),
@@ -261,8 +294,9 @@
 	io__state, io__state).
 :- mode output_single_c_file(in, in, in, di, uo) is det.
 
-output_single_c_file(c_file(ModuleName, C_HeaderLines, Modules), SplitFiles,
-		StackLayoutLabels) -->
+output_single_c_file(CFile, SplitFiles, StackLayoutLabels) -->
+	{ CFile = c_file(ModuleName, C_HeaderLines,
+		UserCCode, Exports, Datas, Modules) },
 	( { SplitFiles = yes(Num) } ->
 		module_name_to_split_c_file_name(ModuleName, Num, ".c",
 			FileName)
@@ -293,18 +327,26 @@
 			io__write_string("*/\n\n")
 		),
 		output_c_file_mercury_headers,
+
 		output_c_header_include_lines(C_HeaderLines),
 		io__write_string("\n"),
+
 		{ gather_c_file_labels(Modules, Labels) },
 		{ decl_set_init(DeclSet0) },
 		output_c_label_decl_list(Labels, DeclSet0, DeclSet1),
-		output_c_data_def_list(Modules, DeclSet1, DeclSet),
-		output_c_module_list(Modules, StackLayoutLabels, DeclSet),
+		output_c_data_def_list(Datas, DeclSet1, DeclSet2),
+
+		output_comp_gen_c_data_list(Datas, DeclSet2, DeclSet3),
+		output_comp_gen_c_module_list(Modules, StackLayoutLabels,
+			DeclSet3, _DeclSet),
+		output_user_c_code_list(UserCCode),
+		output_exported_c_functions(Exports),
+
 		( { SplitFiles = yes(_) } ->
 			[]
 		;
 			io__write_string("\n"),
-			output_c_module_init_list(ModuleName, Modules,
+			output_c_module_init_list(ModuleName, Modules, Datas,
 				StackLayoutLabels)
 		),
 		io__told
@@ -318,12 +360,15 @@
 		io__set_exit_status(1)
 	).
 
-:- pred output_c_module_init_list(module_name, list(c_module),
-	set_bbbtree(label), io__state, io__state).
-:- mode output_c_module_init_list(in, in, in, di, uo) is det.
-
-output_c_module_init_list(ModuleName, Modules, StackLayoutLabels) -->
-	{ divide_modules_on_init_status(Modules, StackLayoutLabels,
+:- pred output_c_module_init_list(module_name::in, list(comp_gen_c_module)::in,
+	list(comp_gen_c_data)::in, set_bbbtree(label)::in,
+	io__state::di, io__state::uo) is det.
+
+output_c_module_init_list(ModuleName, Modules, Datas, StackLayoutLabels) -->
+	{ MustInit = lambda([Module::in] is semidet, (
+		module_defines_label_with_layout(Module, StackLayoutLabels)
+	)) },
+	{ list__filter(MustInit, Modules,
 		AlwaysInitModules, MaybeInitModules) },
 	{ list__chunk(AlwaysInitModules, 40, AlwaysInitModuleBunches) },
 	{ list__chunk(MaybeInitModules, 40, MaybeInitModuleBunches) },
@@ -365,7 +410,7 @@
 		io__write_string("#endif\n\n")
 	),
 
-	output_c_data_init_list(Modules),
+	output_c_data_init_list(Datas),
 	io__write_string("\t}\n"),
 	io__write_string("}\n\n"),
 	io__write_string(
@@ -373,59 +418,21 @@
 	io__write_string(
 		"static const void *const MR_grade = &MR_GRADE_VAR;\n").
 
-	% Divide_modules_on_init_status checks every module in its input list.
-	% If the module does not have compiler-generated code in it, it
-	% ignores the module. If it does, it will include the module in
-	% one of its output lists. If the module defines a label that has
-	% a stack layout structure, it will go into the always-init list,
-	% otherwise it will go into the maybe-init list.
-
-:- pred divide_modules_on_init_status(list(c_module), set_bbbtree(label),
-	list(c_module), list(c_module)).
-:- mode divide_modules_on_init_status(in, in, out, out) is det.
-
-divide_modules_on_init_status([], _, [], []).
-divide_modules_on_init_status([Module | Modules], StackLayoutLabels,
-		AlwaysInit, MaybeInit) :-
-	(
-		Module = c_data(_, _, _, _, _),
-		divide_modules_on_init_status(Modules, StackLayoutLabels,
-			AlwaysInit, MaybeInit)
-	;
-		Module = c_export(_),
-		divide_modules_on_init_status(Modules, StackLayoutLabels,
-			AlwaysInit, MaybeInit)
-	;
-		Module = c_code(_, _),
-		divide_modules_on_init_status(Modules, StackLayoutLabels,
-			AlwaysInit, MaybeInit)
-	;
-		Module = c_module(_, Procedures),
-		divide_modules_on_init_status(Modules, StackLayoutLabels,
-			AlwaysInit1, MaybeInit1),
-		( set_bbbtree__empty(StackLayoutLabels) ->
-			% Checking whether the set is empty or not
-			% allows us to avoid calling gather_c_module_labels.
-			AlwaysInit = AlwaysInit1,
-			MaybeInit = [Module | MaybeInit1]
-		;
-			gather_c_module_labels(Procedures, Labels),
-			(
-				list__member(Label, Labels),
-				set_bbbtree__member(Label, StackLayoutLabels)
-			->
-				AlwaysInit = [Module | AlwaysInit1],
-				MaybeInit = MaybeInit1
-			;
-				AlwaysInit = AlwaysInit1,
-				MaybeInit = [Module | MaybeInit1]
-			)
-		)
-	).
+:- pred module_defines_label_with_layout(comp_gen_c_module::in,
+	set_bbbtree(label)::in) is semidet.
 
-:- pred output_init_bunch_defs(list(list(c_module)), module_name, string, int,
-	bool, io__state, io__state).
-:- mode output_init_bunch_defs(in, in, in, in, in, di, uo) is det.
+module_defines_label_with_layout(Module, StackLayoutLabels) :-
+		% Checking whether the set is empty or not
+		% allows us to avoid calling gather_c_module_labels.
+	\+ set_bbbtree__empty(StackLayoutLabels),
+	Module = comp_gen_c_module(_, Procedures),
+	gather_c_module_labels(Procedures, Labels),
+	list__member(Label, Labels),
+	set_bbbtree__member(Label, StackLayoutLabels).
+
+:- pred output_init_bunch_defs(list(list(comp_gen_c_module))::in,
+	module_name::in, string::in, int::in, bool::in,
+	io__state::di, io__state::uo) is det.
 
 output_init_bunch_defs([], _, _, _, _) --> [].
 output_init_bunch_defs([Bunch | Bunches], ModuleName, InitStatus, Seq,
@@ -440,35 +447,29 @@
 	output_init_bunch_defs(Bunches, ModuleName, InitStatus, NextSeq,
 		SplitFiles).
 
-:- pred output_init_bunch_def(list(c_module), module_name, bool,
-	io__state, io__state).
-:- mode output_init_bunch_def(in, in, in, di, uo) is det.
+:- pred output_init_bunch_def(list(comp_gen_c_module)::in, module_name::in,
+	bool::in, io__state::di, io__state::uo) is det.
 
 output_init_bunch_def([], _, _) --> [].
 output_init_bunch_def([Module | Modules], ModuleName, SplitFiles) -->
-	( { Module = c_module(C_ModuleName, _) } ->
-		( { SplitFiles = yes } ->
-			io__write_string("\t{ extern ModuleFunc "),
-			io__write_string(C_ModuleName),
-			io__write_string(";\n"),
-			io__write_string("\t  "),
-			io__write_string(C_ModuleName),
-			io__write_string("(); }\n")
-		;
-			io__write_string("\t"),
-			io__write_string(C_ModuleName),
-			io__write_string("();\n")
-		),
-		output_init_bunch_def(Modules, ModuleName, SplitFiles)
+	{ Module = comp_gen_c_module(C_ModuleName, _) },
+	( { SplitFiles = yes } ->
+		io__write_string("\t{ extern ModuleFunc "),
+		io__write_string(C_ModuleName),
+		io__write_string(";\n"),
+		io__write_string("\t  "),
+		io__write_string(C_ModuleName),
+		io__write_string("(); }\n")
 	;
-		% divide_modules_on_init_status should have filtered out
-		% whatever kind of module we just got.
-		{ error("unexpected type of c_module in output_init_bunch") }
-	).
+		io__write_string("\t"),
+		io__write_string(C_ModuleName),
+		io__write_string("();\n")
+	),
+	output_init_bunch_def(Modules, ModuleName, SplitFiles).
 
-:- pred output_init_bunch_calls(list(list(c_module)), module_name, string, int,
-	io__state, io__state).
-:- mode output_init_bunch_calls(in, in, in, in, di, uo) is det.
+:- pred output_init_bunch_calls(list(list(comp_gen_c_module))::in,
+	module_name::in, string::in, int::in, io__state::di, io__state::uo)
+	is det.
 
 output_init_bunch_calls([], _, _, _) --> [].
 output_init_bunch_calls([_ | Bunches], ModuleName, InitStatus, Seq) -->
@@ -481,18 +482,13 @@
 	% Output MR_INIT_BASE_TYPE_INFO(BaseTypeInfo, TypeId);
 	% for each base_type_info defined in this module.
 
-:- pred output_c_data_init_list(list(c_module), io__state, io__state).
-:- mode output_c_data_init_list(in, di, uo) is det.
+:- pred output_c_data_init_list(list(comp_gen_c_data)::in,
+	io__state::di, io__state::uo) is det.
 
 output_c_data_init_list([]) --> [].
-output_c_data_init_list([c_export(_) | Ms]) -->
-	output_c_data_init_list(Ms).
-output_c_data_init_list([c_code(_, _) | Ms]) -->
-	output_c_data_init_list(Ms).
-output_c_data_init_list([c_module(_, _) | Ms]) -->
-	output_c_data_init_list(Ms).
-output_c_data_init_list([c_data(ModuleName, DataName, _, _, _) | Ms])  -->
+output_c_data_init_list([Data | Datas]) -->
 	(
+		{ Data = comp_gen_c_data(ModuleName, DataName, _, _, _) },
 		{ DataName = base_type(info, TypeName, Arity) }
 	->
 		io__write_string("\t\tMR_INIT_BASE_TYPE_INFO(\n\t\t"),
@@ -515,7 +511,7 @@
 	;
 		[]
 	),
-	output_c_data_init_list(Ms).
+	output_c_data_init_list(Datas).
 
 :- pred output_init_name(module_name, io__state, io__state).
 :- mode output_init_name(in, di, uo) is det.
@@ -547,8 +543,8 @@
 	% data definition to appear before any use of the type in
 	% forward declarations of static constants.
 	%
-:- pred output_c_data_def_list(list(c_module), decl_set, decl_set, 
-		io__state, io__state).
+:- pred output_c_data_def_list(list(comp_gen_c_data), decl_set, decl_set, 
+	io__state, io__state).
 :- mode output_c_data_def_list(in, in, out, di, uo) is det.
 
 output_c_data_def_list([], DeclSet, DeclSet) --> [].
@@ -556,14 +552,12 @@
 	output_c_data_def(M, DeclSet0, DeclSet1),
 	output_c_data_def_list(Ms, DeclSet1, DeclSet).
 
-:- pred output_c_data_def(c_module, decl_set, decl_set, io__state, io__state).
+:- pred output_c_data_def(comp_gen_c_data, decl_set, decl_set,
+	io__state, io__state).
 :- mode output_c_data_def(in, in, out, di, uo) is det.
 
-output_c_data_def(c_module(_, _), DeclSet, DeclSet) --> [].
-output_c_data_def(c_code(_, _), DeclSet, DeclSet) --> [].
-output_c_data_def(c_export(_), DeclSet, DeclSet) --> [].
-output_c_data_def(c_data(ModuleName, VarName, ExportedFromModule, ArgVals,
-		_Refs), DeclSet0, DeclSet) -->
+output_c_data_def(comp_gen_c_data(ModuleName, VarName, ExportedFromModule,
+		ArgVals, _Refs), DeclSet0, DeclSet) -->
 	io__write_string("\n"),
 	{ DataAddr = data_addr(data_addr(ModuleName, VarName)) },
 
@@ -594,21 +588,23 @@
 			yes, yes, no, "", "", 0, _),
 	{ decl_set_insert(DeclSet0, DataAddr, DeclSet) }.
 
-:- pred output_c_module_list(list(c_module), set_bbbtree(label), decl_set,
-	io__state, io__state).
-:- mode output_c_module_list(in, in, in, di, uo) is det.
+:- pred output_comp_gen_c_module_list(list(comp_gen_c_module)::in,
+	set_bbbtree(label)::in, decl_set::in, decl_set::out,
+	io__state::di, io__state::uo) is det.
 
-output_c_module_list([], _, _) --> [].
-output_c_module_list([M | Ms], StackLayoutLabels, DeclSet0) -->
-	output_c_module(M, StackLayoutLabels, DeclSet0, DeclSet),
-	output_c_module_list(Ms, StackLayoutLabels, DeclSet).
+output_comp_gen_c_module_list([], _, DeclSet, DeclSet) --> [].
+output_comp_gen_c_module_list([Module | Modules], StackLayoutLabels,
+		DeclSet0, DeclSet) -->
+	output_comp_gen_c_module(Module, StackLayoutLabels,
+		DeclSet0, DeclSet1),
+	output_comp_gen_c_module_list(Modules, StackLayoutLabels,
+		DeclSet1, DeclSet).
 
-:- pred output_c_module(c_module, set_bbbtree(label), decl_set, decl_set,
-	io__state, io__state).
-:- mode output_c_module(in, in, in, out, di, uo) is det.
+:- pred output_comp_gen_c_module(comp_gen_c_module::in, set_bbbtree(label)::in,
+	decl_set::in, decl_set::out, io__state::di, io__state::uo) is det.
 
-output_c_module(c_module(ModuleName, Procedures), StackLayoutLabels,
-		DeclSet0, DeclSet) -->
+output_comp_gen_c_module(comp_gen_c_module(ModuleName, Procedures),
+		StackLayoutLabels, DeclSet0, DeclSet) -->
 	io__write_string("\n"),
 	output_c_procedure_list_decls(Procedures, DeclSet0, DeclSet),
 	io__write_string("\n"),
@@ -624,8 +620,19 @@
 	output_c_procedure_list(Procedures, PrintComments, EmitCLoops),
 	io__write_string("END_MODULE\n").
 
-output_c_module(c_data(ModuleName, VarName, ExportedFromModule, ArgVals,
-		_Refs), _, DeclSet0, DeclSet) -->
+:- pred output_comp_gen_c_data_list(list(comp_gen_c_data)::in,
+	decl_set::in, decl_set::out, io__state::di, io__state::uo) is det.
+
+output_comp_gen_c_data_list([], DeclSet, DeclSet) --> [].
+output_comp_gen_c_data_list([Data | Datas], DeclSet0, DeclSet) -->
+	output_comp_gen_c_data(Data, DeclSet0, DeclSet1),
+	output_comp_gen_c_data_list(Datas, DeclSet1, DeclSet).
+
+:- pred output_comp_gen_c_data(comp_gen_c_data::in,
+	decl_set::in, decl_set::out, io__state::di, io__state::uo) is det.
+
+output_comp_gen_c_data(comp_gen_c_data(ModuleName, VarName,
+		ExportedFromModule, ArgVals, _Refs), DeclSet0, DeclSet) -->
 	io__write_string("\n"),
 	{ DataAddr = data_addr(data_addr(ModuleName, VarName)) },
 	output_cons_arg_decls(ArgVals, "", "", 0, _, DeclSet0, DeclSet1),
@@ -662,7 +669,18 @@
 		yes, "", "", 0, _),
 	{ decl_set_insert(DeclSet1, DataAddr, DeclSet) }.
 
-output_c_module(c_code(C_Code, Context), _, DeclSet, DeclSet) -->
+:- pred output_user_c_code_list(list(user_c_code)::in,
+	io__state::di, io__state::uo) is det.
+
+output_user_c_code_list([]) --> [].
+output_user_c_code_list([UserCCode | UserCCodes]) -->
+	output_user_c_code(UserCCode),
+	output_user_c_code_list(UserCCodes).
+
+:- pred output_user_c_code(user_c_code::in, io__state::di, io__state::uo)
+	is det.
+
+output_user_c_code(user_c_code(C_Code, Context)) -->
 	globals__io_lookup_bool_option(auto_comments, PrintComments),
 	( { PrintComments = yes } ->
 		io__write_string("/* "),
@@ -676,27 +694,21 @@
 	io__write_string("\n"),
 	output_reset_line_num.
 
-output_c_module(c_export(PragmaExports), _, DeclSet, DeclSet) -->
-	output_exported_c_functions(PragmaExports).
-
 	% output_c_header_include_lines reverses the list of c header lines
 	% and passes them to output_c_header_include_lines_2 which outputs them.
-	% The list must be reversed since they are inserted in reverse order
-:- pred output_c_header_include_lines(list(c_header_code),
-					io__state, io__state).
-:- mode output_c_header_include_lines(in, di, uo) is det.
+	% The list must be reversed since they are inserted in reverse order.
+:- pred output_c_header_include_lines(list(c_header_code)::in,
+	io__state::di, io__state::uo) is det.
 
 output_c_header_include_lines(Headers) -->
 	{ list__reverse(Headers, RevHeaders) },
 	output_c_header_include_lines_2(RevHeaders).
 
-:- pred output_c_header_include_lines_2(list(c_header_code),
-					io__state, io__state).
-:- mode output_c_header_include_lines_2(in, di, uo) is det.
+:- pred output_c_header_include_lines_2(list(c_header_code)::in,
+	io__state::di, io__state::uo) is det.
 
-output_c_header_include_lines_2([]) --> 
-	[].
-output_c_header_include_lines_2([Code - Context|Hs]) -->
+output_c_header_include_lines_2([]) --> [].
+output_c_header_include_lines_2([Code - Context | Hs]) -->
 	globals__io_lookup_bool_option(auto_comments, PrintComments),
 	( { PrintComments = yes } ->
 		io__write_string("/* "),
@@ -3684,39 +3696,37 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred gather_c_file_labels(list(c_module), list(label)).
-:- mode gather_c_file_labels(in, out) is det.
+:- pred gather_c_file_labels(list(comp_gen_c_module)::in, list(label)::out)
+	is det.
 
 gather_c_file_labels(Modules, Labels) :-
 	gather_labels_from_c_modules(Modules, [], Labels1),
 	list__reverse(Labels1, Labels).
 
-:- pred gather_c_module_labels(list(c_procedure), list(label)).
-:- mode gather_c_module_labels(in, out) is det.
+:- pred gather_c_module_labels(list(c_procedure)::in, list(label)::out) is det.
 
 gather_c_module_labels(Procs, Labels) :-
 	gather_labels_from_c_procs(Procs, [], Labels1),
 	list__reverse(Labels1, Labels).
 
-:- pred gather_labels_from_c_modules(list(c_module), list(label), list(label)).
-:- mode gather_labels_from_c_modules(in, in, out) is det.
+%-----------------------------------------------------------------------------%
+
+:- pred gather_labels_from_c_modules(list(comp_gen_c_module)::in,
+	list(label)::in, list(label)::out) is det.
 
 gather_labels_from_c_modules([], Labels, Labels).
 gather_labels_from_c_modules([Module | Modules], Labels0, Labels) :-
 	gather_labels_from_c_module(Module, Labels0, Labels1),
 	gather_labels_from_c_modules(Modules, Labels1, Labels).
 
-:- pred gather_labels_from_c_module(c_module, list(label), list(label)).
-:- mode gather_labels_from_c_module(in, in, out) is det.
+:- pred gather_labels_from_c_module(comp_gen_c_module::in,
+	list(label)::in, list(label)::out) is det.
 
-gather_labels_from_c_module(c_module(_, Procs), Labels0, Labels) :-
+gather_labels_from_c_module(comp_gen_c_module(_, Procs), Labels0, Labels) :-
 	gather_labels_from_c_procs(Procs, Labels0, Labels).
-gather_labels_from_c_module(c_data(_, _, _, _, _), Labels, Labels).
-gather_labels_from_c_module(c_code(_, _), Labels, Labels).
-gather_labels_from_c_module(c_export(_), Labels, Labels).
 
-:- pred gather_labels_from_c_procs(list(c_procedure), list(label), list(label)).
-:- mode gather_labels_from_c_procs(in, in, out) is det.
+:- pred gather_labels_from_c_procs(list(c_procedure)::in,
+	list(label)::in, list(label)::out) is det.
 
 gather_labels_from_c_procs([], Labels, Labels).
 gather_labels_from_c_procs([c_procedure(_, _, _, Instrs) | Procs],
@@ -3724,8 +3734,8 @@
 	gather_labels_from_instrs(Instrs, Labels0, Labels1),
 	gather_labels_from_c_procs(Procs, Labels1, Labels).
 
-:- pred gather_labels_from_instrs(list(instruction), list(label), list(label)).
-:- mode gather_labels_from_instrs(in, in, out) is det.
+:- pred gather_labels_from_instrs(list(instruction)::in,
+	list(label)::in, list(label)::out) is det.
 
 gather_labels_from_instrs([], Labels, Labels).
 gather_labels_from_instrs([Instr | Instrs], Labels0, Labels) :-
@@ -3735,5 +3745,14 @@
 		Labels1 = Labels0
 	),
 	gather_labels_from_instrs(Instrs, Labels1, Labels).
+
+%-----------------------------------------------------------------------------%
+
+:- pred make_directory(string::in, io__state::di, io__state::uo) is det.
+
+make_directory(DirName) -->
+	{ string__format("[ -d %s ] || mkdir -p %s", [s(DirName), s(DirName)],
+		Command) },
+	io__call_system(Command, _Result).
 
 %-----------------------------------------------------------------------------%
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.113
diff -u -u -r1.113 mercury_compile.m
--- mercury_compile.m	1998/11/10 13:41:57	1.113
+++ mercury_compile.m	1998/11/15 07:03:57
@@ -1869,29 +1869,27 @@
 % The LLDS output pass
 
 :- pred mercury_compile__output_pass(module_info, list(c_procedure),
-		module_name, bool, io__state, io__state).
+	module_name, bool, io__state, io__state).
 :- mode mercury_compile__output_pass(in, in, in, out, di, uo) is det.
 
-mercury_compile__output_pass(HLDS0, LLDS0, ModuleName, CompileErrors) -->
+mercury_compile__output_pass(HLDS0, Procs0, ModuleName, CompileErrors) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
 	globals__io_lookup_bool_option(statistics, Stats),
 	{ base_type_info__generate_llds(HLDS0, BaseTypeInfos) },
 	{ base_type_layout__generate_llds(HLDS0, HLDS1, BaseTypeLayouts) },
 	{ stack_layout__generate_llds(HLDS1, HLDS,
-		StackLayouts, StackLayoutLabels) },
-	{ list__append(StackLayouts, BaseTypeLayouts, StaticData0) },
-	{ llds_common(LLDS0, StaticData0, ModuleName, LLDS1, 
-		StaticData, CommonData) },
-	{ list__append(BaseTypeInfos, StaticData, AllData) },
+		ProcLayouts, InternalLayouts, LayoutLabels) },
+	{ list__append(InternalLayouts, BaseTypeLayouts, StaticData0) },
+	{ llds_common(Procs0, StaticData0, ModuleName, Procs1, StaticData) },
+	{ list__condense([BaseTypeInfos, ProcLayouts, StaticData], AllData) },
 
 	{ get_c_interface_info(HLDS, C_InterfaceInfo) },
-	mercury_compile__chunk_llds(C_InterfaceInfo, LLDS1, AllData,
-		CommonData, LLDS2, NumChunks),
-	mercury_compile__output_llds(ModuleName, LLDS2, StackLayoutLabels,
+	mercury_compile__construct_c_file(C_InterfaceInfo, Procs1, AllData,
+		CFile, NumChunks),
+	mercury_compile__output_llds(ModuleName, CFile, LayoutLabels,
 		Verbose, Stats),
 
-	{ C_InterfaceInfo = c_interface_info(_ModuleName,
-		_C_headerCode, _C_BodyCode, C_ExportDecls, _C_ExportDefns) },
+	{ C_InterfaceInfo = c_interface_info(_, _, _, C_ExportDecls, _) },
 	export__produce_header_file(C_ExportDecls, ModuleName),
 
 	globals__io_lookup_bool_option(compile_to_c, CompileToC),
@@ -1904,34 +1902,38 @@
 
 	% Split the code up into bite-size chunks for the C compiler.
 
-:- pred mercury_compile__chunk_llds(c_interface_info, list(c_procedure),
-	list(c_module), list(c_module), c_file, int, io__state, io__state).
-% :- mode mercury_compile__chunk_llds(in, di, di, uo, out, di, uo) is det.
-:- mode mercury_compile__chunk_llds(in, in, in, in, out, out, di, uo) is det.
-
-mercury_compile__chunk_llds(C_InterfaceInfo, Procedures, BaseTypeData,
-		CommonDataModules,
-		c_file(ModuleName, C_HeaderCode, ModuleList), NumChunks) -->
-	{ C_InterfaceInfo = c_interface_info(ModuleName,
+:- pred mercury_compile__construct_c_file(c_interface_info, list(c_procedure),
+	list(comp_gen_c_data), c_file, int, io__state, io__state).
+:- mode mercury_compile__construct_c_file(in, in, in, out, out, di, uo) is det.
+
+mercury_compile__construct_c_file(C_InterfaceInfo, Procedures, AllData, CFile,
+		ComponentCount) -->
+	{ C_InterfaceInfo = c_interface_info(ModuleSymName,
 		C_HeaderCode0, C_BodyCode0, C_ExportDecls, C_ExportDefns) },
-	{ llds_out__sym_name_mangle(ModuleName, MangledModName) },
-	{ string__append(MangledModName, "_module", ModName) },
+	{ llds_out__sym_name_mangle(ModuleSymName, MangledModuleName) },
+	{ string__append(MangledModuleName, "_module", ModuleName) },
 	globals__io_lookup_int_option(procs_per_c_function, ProcsPerFunc),
 	{ get_c_body_code(C_BodyCode0, C_BodyCode) },
 	( { ProcsPerFunc = 0 } ->
 		% ProcsPerFunc = 0 really means infinity -
 		% we store all the procs in a single function.
-		{ ProcModules = [c_module(ModName, Procedures)] }
+		{ ChunkedModules = [comp_gen_c_module(ModuleName,
+			Procedures)] }
 	;
-		{ list__chunk(Procedures, ProcsPerFunc, ChunkList) },
-		{ mercury_compile__combine_chunks(ChunkList, ModName,
-			ProcModules) }
+		{ list__chunk(Procedures, ProcsPerFunc, ChunkedProcs) },
+		{ mercury_compile__combine_chunks(ChunkedProcs, ModuleName,
+			ChunkedModules) }
 	),
-	maybe_add_header_file_include(C_ExportDecls, ModuleName, C_HeaderCode0,
-		C_HeaderCode),
-	{ list__condense([C_BodyCode, BaseTypeData, CommonDataModules,
-		ProcModules, [c_export(C_ExportDefns)]], ModuleList) },
-	{ list__length(ModuleList, NumChunks) }.
+	maybe_add_header_file_include(C_ExportDecls, ModuleSymName,
+		C_HeaderCode0, C_HeaderCode),
+	{ CFile = c_file(ModuleSymName, C_HeaderCode,
+		C_BodyCode, C_ExportDefns, AllData, ChunkedModules) },
+	{ list__length(C_BodyCode, UserCCodeCount) },
+	{ list__length(C_ExportDefns, ExportCount) },
+	{ list__length(AllData, CompGenDataCount) },
+	{ list__length(ChunkedModules, CompGenCodeCount) },
+	{ ComponentCount is UserCCodeCount + ExportCount
+		+ CompGenDataCount + CompGenCodeCount }.
 
 :- pred maybe_add_header_file_include(c_export_decls, module_name,
 	c_header_info, c_header_info, io__state, io__state).
@@ -1967,33 +1969,33 @@
 		{ list__append(C_HeaderCode0, [Include], C_HeaderCode) }
 	).
 
-:- pred get_c_body_code(c_body_info, list(c_module)).
+:- pred get_c_body_code(c_body_info, list(user_c_code)).
 :- mode get_c_body_code(in, out) is det.
 
 get_c_body_code([], []).
 get_c_body_code([Code - Context | CodesAndContexts],
-			[c_code(Code, Context) | C_Modules]) :-
+		[user_c_code(Code, Context) | C_Modules]) :-
 	get_c_body_code(CodesAndContexts, C_Modules).
 
 :- pred mercury_compile__combine_chunks(list(list(c_procedure)), string,
-		list(c_module)).
+	list(comp_gen_c_module)).
 :- mode mercury_compile__combine_chunks(in, in, out) is det.
 
 mercury_compile__combine_chunks(ChunkList, ModName, Modules) :-
 	mercury_compile__combine_chunks_2(ChunkList, ModName, 0, Modules).
 
 :- pred mercury_compile__combine_chunks_2(list(list(c_procedure)),
-		string, int, list(c_module)).
+	string, int, list(comp_gen_c_module)).
 :- mode mercury_compile__combine_chunks_2(in, in, in, out) is det.
 
 mercury_compile__combine_chunks_2([], _ModName, _N, []).
-mercury_compile__combine_chunks_2([Chunk|Chunks], ModName, Num,
+mercury_compile__combine_chunks_2([Chunk | Chunks], ModuleName, Num,
 		[Module | Modules]) :-
 	string__int_to_string(Num, NumString),
-	string__append(ModName, NumString, ThisModuleName),
-	Module = c_module(ThisModuleName, Chunk),
+	string__append(ModuleName, NumString, ThisModuleName),
+	Module = comp_gen_c_module(ThisModuleName, Chunk),
 	Num1 is Num + 1,
-	mercury_compile__combine_chunks_2(Chunks, ModName, Num1, Modules).
+	mercury_compile__combine_chunks_2(Chunks, ModuleName, Num1, Modules).
 
 :- pred mercury_compile__output_llds(module_name, c_file, set_bbbtree(label),
 	bool, bool, io__state, io__state).
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.23
diff -u -u -r1.23 stack_layout.m
--- stack_layout.m	1998/11/12 03:15:46	1.23
+++ stack_layout.m	1998/11/13 12:07:31
@@ -169,7 +169,8 @@
 :- import_module list, set_bbbtree.
 
 :- pred stack_layout__generate_llds(module_info::in, module_info::out,
-	list(c_module)::out, set_bbbtree(label)::out) is det.
+	list(comp_gen_c_data)::out, list(comp_gen_c_data)::out,
+	set_bbbtree(label)::out) is det.
 
 :- implementation.
 
@@ -186,9 +187,10 @@
 		bool,		% generate tracing layout info?
 		bool,		% generate procedure id layout info?
 		bool,		% have static code addresses?
-		list(c_module),	% generated data
+		list(comp_gen_c_data),	% generated proc layouts
+		list(comp_gen_c_data),	% generated label layouts
 		set_bbbtree(label)
-				% the set of labels with stack layouts
+				% the set of labels with layouts
 	).
 
 %---------------------------------------------------------------------------%
@@ -196,8 +198,8 @@
 	% Process all the continuation information stored in the HLDS,
 	% converting it into LLDS data structures.
 
-stack_layout__generate_llds(ModuleInfo0, ModuleInfo, CModules,
-		StackLayoutLabels) :-
+stack_layout__generate_llds(ModuleInfo0, ModuleInfo,
+		ProcLayouts, InternalLayouts, LayoutLabels) :-
 	module_info_get_continuation_info(ModuleInfo0, ContinuationInfo),
 	continuation_info__get_all_proc_layouts(ContinuationInfo,
 		ProcLayoutList),
@@ -210,16 +212,17 @@
 	globals__lookup_bool_option(Globals, procid_stack_layout,
 		ProcInfoLayout),
 	globals__have_static_code_addresses(Globals, StaticCodeAddr),
-	set_bbbtree__init(StackLayoutLabels0),
+	set_bbbtree__init(LayoutLabels0),
 
 	LayoutInfo0 = stack_layout_info(ModuleName, CellCount, AgcLayout,
 		TraceLayout, ProcInfoLayout, StaticCodeAddr,
-		[], StackLayoutLabels0),
+		[], [], LayoutLabels0),
 	list__foldl(stack_layout__construct_layouts, ProcLayoutList,
 		LayoutInfo0, LayoutInfo),
 
-	stack_layout__get_cmodules(CModules, LayoutInfo, _),
-	stack_layout__get_label_set(StackLayoutLabels, LayoutInfo, _),
+	stack_layout__get_proc_layout_data(ProcLayouts, LayoutInfo, _),
+	stack_layout__get_internal_layout_data(InternalLayouts, LayoutInfo, _),
+	stack_layout__get_label_set(LayoutLabels, LayoutInfo, _),
 	stack_layout__get_cell_number(FinalCellCount, LayoutInfo, _),
 	module_info_set_cell_count(ModuleInfo0, FinalCellCount, ModuleInfo).
 
@@ -358,9 +361,9 @@
 				% is given and if the procedure is exported.
 				% Beware however that linkage/2 in llds_out.m
 				% assumes that this is `no'.
-	{ CModule = c_data(ModuleName, proc_layout(EntryLabel), Exported,
-		MaybeRvals, []) },
-	stack_layout__add_cmodule(CModule, EntryLabel).
+	{ CData = comp_gen_c_data(ModuleName, proc_layout(EntryLabel),
+		Exported, MaybeRvals, []) },
+	stack_layout__add_proc_layout_data(CData, EntryLabel).
 
 %---------------------------------------------------------------------------%
 
@@ -437,9 +440,9 @@
 	% { LayoutRvals = [yes(EntryAddrRval), yes(LabelNumRval
 	% 	| VarInfoRvals] }
 	{ LayoutRvals = [yes(EntryAddrRval) | VarInfoRvals] },
-	{ CModule = c_data(ModuleName, internal_layout(Label), no,
-		LayoutRvals, []) },
-	stack_layout__add_cmodule(CModule, Label).
+	{ CData = comp_gen_c_data(ModuleName, internal_layout(Label),
+		no, LayoutRvals, []) },
+	stack_layout__add_internal_layout_data(CData, Label).
 
 	% Construct the rvals required for accurate GC or for tracing.
 
@@ -915,76 +918,86 @@
 :- pred stack_layout__get_module_name(module_name::out,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__get_module_name(ModuleName, LayoutInfo, LayoutInfo) :-
-	LayoutInfo = stack_layout_info(ModuleName, _, _, _, _, _, _, _).
+:- pred stack_layout__get_cell_number(int::out,
+	stack_layout_info::in, stack_layout_info::out) is det.
 
-:- pred stack_layout__get_next_cell_number(int::out,
+:- pred stack_layout__get_agc_stack_layout(bool::out,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__get_next_cell_number(CNum0, LayoutInfo0, LayoutInfo) :-
-	LayoutInfo0 = stack_layout_info(A, CNum0, C, D, E, F, G, H),
-	CNum is CNum0 + 1,
-	LayoutInfo = stack_layout_info(A, CNum, C, D, E, F, G, H).
+:- pred stack_layout__get_trace_stack_layout(bool::out,
+	stack_layout_info::in, stack_layout_info::out) is det.
 
-:- pred stack_layout__get_cell_number(int::out,
+:- pred stack_layout__get_procid_stack_layout(bool::out,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__get_cell_number(CNum, LayoutInfo, LayoutInfo) :-
-	LayoutInfo = stack_layout_info(_, CNum, _, _, _, _, _, _).
+:- pred stack_layout__get_static_code_addresses(bool::out,
+	stack_layout_info::in, stack_layout_info::out) is det.
 
-:- pred stack_layout__get_agc_stack_layout(bool::out,
+:- pred stack_layout__get_proc_layout_data(list(comp_gen_c_data)::out,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__get_agc_stack_layout(AgcStackLayout, LayoutInfo, LayoutInfo) :-
-	LayoutInfo = stack_layout_info(_, _, AgcStackLayout, _, _, _, _, _).
+:- pred stack_layout__get_internal_layout_data(list(comp_gen_c_data)::out,
+	stack_layout_info::in, stack_layout_info::out) is det.
 
-:- pred stack_layout__get_trace_stack_layout(bool::out,
+:- pred stack_layout__get_label_set(set_bbbtree(label)::out,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__get_trace_stack_layout(TraceStackLayout, LayoutInfo,
-		LayoutInfo) :-
-	LayoutInfo = stack_layout_info(_, _, _, TraceStackLayout, _, _, _, _).
+stack_layout__get_module_name(A, LayoutInfo, LayoutInfo) :-
+	LayoutInfo = stack_layout_info(A, _, _, _, _, _, _, _, _).
 
-:- pred stack_layout__get_procid_stack_layout(bool::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
+stack_layout__get_cell_number(B, LayoutInfo, LayoutInfo) :-
+	LayoutInfo = stack_layout_info(_, B, _, _, _, _, _, _, _).
 
-stack_layout__get_procid_stack_layout(ProcIdStackLayout, LayoutInfo,
-		LayoutInfo) :-
-	LayoutInfo = stack_layout_info(_, _, _, _, ProcIdStackLayout, _, _, _).
+stack_layout__get_agc_stack_layout(C, LayoutInfo, LayoutInfo) :-
+	LayoutInfo = stack_layout_info(_, _, C, _, _, _, _, _, _).
 
-:- pred stack_layout__get_static_code_addresses(bool::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
+stack_layout__get_trace_stack_layout(D, LayoutInfo, LayoutInfo) :-
+	LayoutInfo = stack_layout_info(_, _, _, D, _, _, _, _, _).
 
-stack_layout__get_static_code_addresses(StaticCodeAdddr, LayoutInfo,
-		LayoutInfo) :-
-	LayoutInfo = stack_layout_info(_, _, _, _, _, StaticCodeAdddr, _, _).
+stack_layout__get_procid_stack_layout(E, LayoutInfo, LayoutInfo) :-
+	LayoutInfo = stack_layout_info(_, _, _, _, E, _, _, _, _).
 
-:- pred stack_layout__get_cmodules(list(c_module)::out,
+stack_layout__get_static_code_addresses(F, LayoutInfo, LayoutInfo) :-
+	LayoutInfo = stack_layout_info(_, _, _, _, _, F, _, _, _).
+
+stack_layout__get_proc_layout_data(G, LayoutInfo, LayoutInfo) :-
+	LayoutInfo = stack_layout_info(_, _, _, _, _, _, G, _, _).
+
+stack_layout__get_internal_layout_data(H, LayoutInfo, LayoutInfo) :-
+	LayoutInfo = stack_layout_info(_, _, _, _, _, _, _, H, _).
+
+stack_layout__get_label_set(I, LayoutInfo, LayoutInfo) :-
+	LayoutInfo = stack_layout_info(_, _, _, _, _, _, _, _, I).
+
+:- pred stack_layout__add_proc_layout_data(comp_gen_c_data::in, label::in,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__get_cmodules(CModules, LayoutInfo, LayoutInfo) :-
-	LayoutInfo = stack_layout_info(_, _, _, _, _, _, CModules, _).
+stack_layout__add_proc_layout_data(NewG, NewI, LayoutInfo0, LayoutInfo) :-
+	LayoutInfo0 = stack_layout_info(A, B, C, D, E, F, G0, H, I0),
+	G = [NewG | G0],
+	set_bbbtree__insert(I0, NewI, I),
+	LayoutInfo  = stack_layout_info(A, B, C, D, E, F, G , H, I).
 
-:- pred stack_layout__get_label_set(set_bbbtree(label)::out,
+:- pred stack_layout__add_internal_layout_data(comp_gen_c_data::in, label::in,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__get_label_set(StackLayoutLabels, LayoutInfo, LayoutInfo) :-
-	LayoutInfo = stack_layout_info(_, _, _, _, _, _, _, StackLayoutLabels).
+stack_layout__add_internal_layout_data(NewH, NewI, LayoutInfo0, LayoutInfo) :-
+	LayoutInfo0 = stack_layout_info(A, B, C, D, E, F, G, H0, I0),
+	H = [NewH | H0],
+	set_bbbtree__insert(I0, NewI, I),
+	LayoutInfo  = stack_layout_info(A, B, C, D, E, F, G, H , I ).
 
-:- pred stack_layout__add_cmodule(c_module::in, label::in,
+:- pred stack_layout__get_next_cell_number(int::out,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__add_cmodule(CModule, Label, LayoutInfo0, LayoutInfo) :-
-	LayoutInfo0 = stack_layout_info(A, B, C, D, E, F,
-		CModules0, StackLayoutLabels0),
-	CModules = [CModule | CModules0],
-	set_bbbtree__insert(StackLayoutLabels0, Label, StackLayoutLabels),
-	LayoutInfo = stack_layout_info(A, B, C, D, E, F,
-		CModules, StackLayoutLabels).
+stack_layout__get_next_cell_number(B0, LayoutInfo0, LayoutInfo) :-
+	LayoutInfo0 = stack_layout_info(A, B0, C, D, E, F, G, H, I),
+	B is B0 + 1,
+	LayoutInfo  = stack_layout_info(A, B,  C, D, E, F, G, H, I).
 
 :- pred stack_layout__set_cell_number(int::in,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__set_cell_number(CNum, LayoutInfo0, LayoutInfo) :-
-	LayoutInfo0 = stack_layout_info(A, _, C, D, E, F, G, H),
-	LayoutInfo = stack_layout_info(A, CNum, C, D, E, F, G, H).
+stack_layout__set_cell_number(B, LayoutInfo0, LayoutInfo) :-
+	LayoutInfo0 = stack_layout_info(A, _, C, D, E, F, G, H, I),
+	LayoutInfo  = stack_layout_info(A, B, C, D, E, F, G, H, I).
Index: compiler/transform_llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/transform_llds.m,v
retrieving revision 1.1
diff -u -u -r1.1 transform_llds.m
--- transform_llds.m	1998/10/30 05:11:12	1.1
+++ transform_llds.m	1998/11/13 11:42:35
@@ -3,11 +3,11 @@
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
-% 
+%
 % Module: transform_llds
-% 
+%
 % Main authors: petdr
-% 
+%
 % This module does source to source transformations of the llds data
 % structure.  This is sometimes necessary to avoid limits in some
 % compilers.
@@ -15,7 +15,7 @@
 % This module currently transforms computed gotos into a binary search
 % down to smaller computed gotos.  This avoids a limitation in the lcc
 % compiler.
-% 
+%
 %-----------------------------------------------------------------------------%
 
 :- module transform_llds.
@@ -38,7 +38,7 @@
 	globals__io_lookup_int_option(max_jump_table_size, Size),
 	(
 		{ Size = 0 }
-	->	
+	->
 		{ LLDS = LLDS0 }
 	;
 		transform_c_file(LLDS0, LLDS)
@@ -49,14 +49,14 @@
 :- pred transform_c_file(c_file, c_file, io__state, io__state).
 :- mode transform_c_file(in, out, di, uo) is det.
 
-transform_c_file(c_file(ModuleName, HeaderInfo, Modules0),
-		c_file(ModuleName, HeaderInfo, Modules)) -->
+transform_c_file(c_file(ModuleName, HeaderInfo, A, B, C, Modules0),
+		c_file(ModuleName, HeaderInfo, A, B, C, Modules)) -->
 	transform_c_module_list(Modules0, Modules).
 
 %-----------------------------------------------------------------------------%
 
-:- pred transform_c_module_list(list(c_module), list(c_module),
-		io__state, io__state).
+:- pred transform_c_module_list(list(comp_gen_c_module),
+	list(comp_gen_c_module), io__state, io__state).
 :- mode transform_c_module_list(in, out, di, uo) is det.
 
 transform_c_module_list([], []) --> [].
@@ -66,16 +66,13 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred transform_c_module(c_module, c_module, io__state, io__state).
+:- pred transform_c_module(comp_gen_c_module, comp_gen_c_module,
+	io__state, io__state).
 :- mode transform_c_module(in, out, di, uo) is det.
 
-transform_c_module(c_module(Name, Procedures0), c_module(Name, Procedures)) -->
+transform_c_module(comp_gen_c_module(Name, Procedures0),
+		comp_gen_c_module(Name, Procedures)) -->
 	transform_c_procedure_list(Procedures0, Procedures).
-transform_c_module(c_data(Name, DataName, Exported, Rvals, PredProcIds),
-		c_data(Name, DataName, Exported, Rvals, PredProcIds)) --> [].
-transform_c_module(c_code(Code, Context), c_code(Code, Context)) --> [].
-transform_c_module(c_export(Exports), c_export(Exports)) --> [].
-	
 
 %-----------------------------------------------------------------------------%
 
@@ -84,7 +81,7 @@
 :- mode transform_c_procedure_list(in, out, di, uo) is det.
 
 transform_c_procedure_list([], []) --> [].
-transform_c_procedure_list([P0 | P0s], [P | Ps]) --> 
+transform_c_procedure_list([P0 | P0s], [P | Ps]) -->
 	transform_c_procedure(P0, P),
 	transform_c_procedure_list(P0s, Ps).
 
@@ -108,20 +105,20 @@
 	{ max_label_int(Instrs0, 0, N) },
 	transform_instructions_2(Instrs0, ProcLabel, N, Instrs).
 
-:- pred transform_instructions_2(list(instruction), proc_label, int, 
+:- pred transform_instructions_2(list(instruction), proc_label, int,
 		list(instruction), io__state, io__state).
 :- mode transform_instructions_2(in, in, in, out, di, uo) is det.
 
 transform_instructions_2([], _, _, []) --> [].
-transform_instructions_2([Instr0 | Instrs0], ProcLabel, N0, Instrs) --> 
+transform_instructions_2([Instr0 | Instrs0], ProcLabel, N0, Instrs) -->
 	transform_instruction(Instr0, ProcLabel, N0, InstrsA, N),
 	transform_instructions_2(Instrs0, ProcLabel, N, InstrsB),
 	{ list__append(InstrsA, InstrsB, Instrs) }.
-	
+
 
 %-----------------------------------------------------------------------------%
 
-:- pred transform_instruction(instruction, proc_label, int, 
+:- pred transform_instruction(instruction, proc_label, int,
 		list(instruction), int, io__state, io__state).
 :- mode transform_instruction(in, in, in, out, out, di, uo) is det.
 
@@ -148,7 +145,7 @@
 	% instructions, Is, to do a binary search down to a jump_table
 	% whose size is sufficiently small.
 	%
-:- pred split_computed_goto(instruction, int, int, proc_label, int, 
+:- pred split_computed_goto(instruction, int, int, proc_label, int,
 		list(instruction), int, io__state, io__state).
 :- mode split_computed_goto(in, in, in, in, in, out, out, di, uo) is det.
 
@@ -182,9 +179,9 @@
 		{ ThenInstr = computed_goto(Rval, Start) - "Then section" },
 		{ ElseInstr = computed_goto(Index, End) - "Else section" },
 
-		split_computed_goto(ThenInstr, MaxSize, Mid, ProcLabel, N2, 
+		split_computed_goto(ThenInstr, MaxSize, Mid, ProcLabel, N2,
 				ThenInstrs, N3),
-		split_computed_goto(ElseInstr, MaxSize, Length - Mid, 
+		split_computed_goto(ElseInstr, MaxSize, Length - Mid,
 				ProcLabel, N3, ElseInstrs, N),
 
 		{ list__append(ThenInstrs, [ElseLabel | ElseInstrs], InstrsA) },
cvs diff: Diffing compiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/exceptions
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing trial
cvs diff: Diffing util



More information about the developers mailing list