[m-dev.] for review: MLDS changes

Julien Fischer juliensf at students.cs.mu.oz.au
Tue Feb 20 14:20:26 AEDT 2001


For review by Fergus:

This is in relation to my previous changes to the MLDS.  This diff fixes
a bug involving the generation of constructors, makes the gcc backend
work with the MLDS changes and shifts some code for the detection of main
predicates from mercury_compile.m to ml_util.m.  All the MLDS changes
are now passing bootstrap in grade hlc.gc, so if these new ones are
alright I'll commit the whole lot.  

--------
Estimated hours taken: 2.

Fixed a bug in ml_unify_gen.m that caused du constructors to be generated
incorrectly.

Made mls_to_gcc.m consistent with changes to MLDS.

Shifted some code that detects whether a group of mlds__defns defines
the main/2 entry point to ml_util.  This eliminates some code duplication.

compiler/ml_unify_gen.m:
	Fixed a bug that with du constructors.
compiler/mlds_to_gcc.m:
	Changed so that it is consistent with MLDS changes.
compiler/mercury_compile.m:
compiler/ml_util.m:
	Shifted code that detects main/2 entry point.

Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.195
diff -u -r1.195 mercury_compile.m
--- compiler/mercury_compile.m	2001/02/11 13:13:11	1.195
+++ compiler/mercury_compile.m	2001/02/20 02:02:11
@@ -65,8 +65,8 @@
 :- import_module mlds_to_java.			% MLDS -> Java
 :- import_module mlds_to_ilasm.			% MLDS -> IL assembler
 :- import_module maybe_mlds_to_gcc.		% MLDS -> GCC back-end
+:- import_module ml_util.			% MLDS utility predicates 
 
-
 	% miscellaneous compiler modules
 :- import_module prog_data, hlds_module, hlds_pred, hlds_out, llds, rl.
 :- import_module mercury_to_mercury, mercury_to_goedel.
@@ -563,10 +563,7 @@
 mercury_compile__mlds_has_main(MLDS) =
 	(
 		MLDS = mlds(_, _, _, Defns),
-		list__member(Defn, Defns),
-		Defn = mlds__defn(Name, _, _, _),
-		Name = function(FuncName, _, _, _), 
-		FuncName = pred(predicate, _, "main", 2)
+		defns_contain_main(Defns)
 	->
 		yes
 	;
Index: compiler/ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.28
diff -u -r1.28 ml_unify_gen.m
--- compiler/ml_unify_gen.m	2001/02/10 11:21:30	1.28
+++ compiler/ml_unify_gen.m	2001/02/20 02:02:11
@@ -1191,19 +1199,31 @@
 	% Generate an rval containing the address of the local static constant
 	% for a given variable.
 	%
-:- pred ml_gen_static_const_addr(prog_var, mlds__rval,
+:- pred ml_gen_static_const_addr(prog_var, mlds__type, mlds__rval,
 		ml_gen_info, ml_gen_info).
-:- mode ml_gen_static_const_addr(in, out, in, out) is det.
-ml_gen_static_const_addr(Var, ConstAddrRval) -->
+:- mode ml_gen_static_const_addr(in, in, out, in, out) is det.
+ml_gen_static_const_addr(Var, Type, ConstAddrRval) -->
 	ml_lookup_static_const_name(Var, ConstName),
-	ml_qualify_var(ConstName, ConstLval),
+	ml_gen_var_lval(ConstName, Type, ConstLval),
 	{ ConstAddrRval = mem_addr(ConstLval) }.
 
 :- pred ml_cons_name(cons_id, ctor_name, ml_gen_info, ml_gen_info).
 :- mode ml_cons_name(in, out, in, out) is det.
 
-ml_cons_name(ConsId, ConsName) -->
-	{ hlds_out__cons_id_to_string(ConsId, ConsName) }.
+ml_cons_name(HLDS_ConsId, QualifiedConsId) -->
+	( 
+		{ HLDS_ConsId = cons(SymName, Arity),
+	    	SymName = qualified(SymModuleName, ConsName) } 
+	->
+		{ ConsId = ctor_id(ConsName, Arity) },
+		{ ModuleName = mercury_module_name_to_mlds(SymModuleName) }
+	;
+		{ hlds_out__cons_id_to_string(HLDS_ConsId, ConsName) },
+		{ ConsId = ctor_id(ConsName, 0) },
+		{ ModuleName = mercury_module_name_to_mlds(unqualified("")) }
+	),
+	{ QualifiedConsId = qual(ModuleName, ConsId) }.
 
 :- pred ml_gen_cons_args(list(mlds__lval), list(prog_type),
 		list(uni_mode), module_info, list(mlds__rval)).
Index: compiler/ml_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.6
diff -u -r1.6 ml_util.m
--- compiler/ml_util.m	2001/02/08 12:54:07	1.6
+++ compiler/ml_util.m	2001/02/20 02:02:11
@@ -18,7 +18,13 @@
 :- import_module list, std_util.
 
 %-----------------------------------------------------------------------------%
+	% succeeds iff the definitions contain the entry point to
+	% the main/2 predicate.
+	%
+:- pred defns_contain_main(mlds__defns).
+:- mode defns_contain_main(in) is semidet.
 
+%-----------------------------------------------------------------------------%
 	% return `true' if the statement is a tail call which
 	% can be optimized into a jump back to the start of the
 	% function
@@ -115,10 +121,16 @@
 :- implementation.
 
 :- import_module rtti.
-:- import_module bool, list, std_util.
+:- import_module bool, list, std_util, prog_data.
 
 %-----------------------------------------------------------------------------%
 
+defns_contain_main(Defns) :-
+	list__member(Defn, Defns),
+	Defn = mlds__defn(Name, _, _, _),
+	Name = function(FuncName, _, _, _), 
+	FuncName = pred(predicate, _, "main", 2).
+
 can_optimize_tailcall(Name, Call) :-
 	Call = call(_Signature, FuncRval, MaybeObject, _CallArgs,
 		_Results, IsTailCall),
@@ -330,6 +342,6 @@
 	rval_contains_var(Rval, Name).
 lval_contains_var(mem_ref(Rval, _Type), Name) :-
 	rval_contains_var(Rval, Name).
-lval_contains_var(var(Name), Name).  /* this is where we can succeed! */
+lval_contains_var(var(Name, _Type), Name).  /* this is where we can succeed! */
 
 %-----------------------------------------------------------------------------%
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.31
diff -u -r1.31 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	2001/02/10 11:21:31	1.31
+++ compiler/mlds_to_gcc.m	2001/02/20 02:02:11
@@ -1054,6 +1054,8 @@
 	{ sorry(this_file, "`protected' access") }.
 add_var_access_flag(default, _GCC_Defn) -->
 	{ sorry(this_file, "`default' access") }.
+add_var_access_flag(local, _GCC_Defn) -->
+	{ sorry(this_file, "`local' access") }.
 
 :- pred add_var_virtuality_flag(mlds__virtuality, gcc__var_decl,
 	io__state, io__state).
@@ -1128,6 +1130,8 @@
 	{ sorry(this_file, "`protected' access") }.
 add_field_access_flag(default, _GCC_Defn) -->
 	{ sorry(this_file, "`default' access") }.
+add_field_access_flag(local, _GCC_Defn) -->
+	{ sorry(this_file, "`local' access") }.
 
 :- pred add_field_per_instance_flag(mlds__per_instance, gcc__field_decl,
 	io__state, io__state).
@@ -1209,6 +1213,8 @@
 	{ sorry(this_file, "`protected' access") }.
 add_func_access_flag(default, _GCC_Defn) -->
 	{ sorry(this_file, "`default' access") }.
+add_func_access_flag(local, _GCC_Defn) -->
+	{ sorry(this_file, "`local' access") }.
 
 :- pred add_func_per_instance_flag(mlds__per_instance, gcc__func_decl,
 	io__state, io__state).
@@ -1935,6 +1941,8 @@
 build_type(mlds__rtti_type(RttiName), InitializerSize, _GlobalInfo,
 		GCC_Type) -->
 	build_rtti_type(RttiName, InitializerSize, GCC_Type).
+build_type(mlds__unknown_type, _, _, _) -->
+	{ unexpected(this_file, "build_type: unknown type") }.
 
 :- pred build_mercury_type(mercury_type, builtin_type, gcc__type,
 		io__state, io__state).
@@ -3035,7 +3043,7 @@
 	build_rval(PointerRval, DefnInfo, PointerExpr),
 	gcc__build_pointer_deref(PointerExpr, Expr).
 
-build_lval(var(qual(ModuleName, VarName)), DefnInfo, Expr) -->
+build_lval(var(qual(ModuleName, VarName), _VarType), DefnInfo, Expr) -->
 	%
 	% Look up the variable in the symbol table.
 	% We try the symbol table for local vars first,

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list