[m-dev.] diff: fix switches in IL

Tyson Dowd trd at cs.mu.OZ.AU
Thu Nov 9 16:02:07 AEDT 2000


Hi,


===================================================================


Estimated hours taken: 1

Get switches working in the IL backend (and fix a few problems
encountered on the way).

compiler/ilasm.m:
	Implement conv, switch and aligned.

compiler/mlds_to_il.m:
	Fix the implementation of computed goto, it was trying to do a
	little too much (I had imagined that we would embed the code on
	the arms of the switch somehow, but of course we just use MLDS labels
	as the references, and the corresponding code is put underneath an
	MLDS label later).
	Implement cast_to_unsigned unop.
	Put the runtime init module name in private_builting__c_code, as 
	this is where handwritten code goes.  When we implement pragma export
	in IL, we might be able to put it in private_builtin.

compiler/mlds_to_ilasm.m:
	Use "public class" instead of "class" -- the managed C++ compiler has
	changed a little.



Index: compiler/ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilasm.m,v
retrieving revision 1.2
diff -u -r1.2 ilasm.m
--- compiler/ilasm.m	2000/10/22 07:27:19	1.2
+++ compiler/ilasm.m	2000/11/09 04:53:16
@@ -918,7 +918,7 @@
 	output_signed(Signed).
 
 output_instr(conv(SimpleType)) --> 
-	io__write_string("conv"),
+	io__write_string("conv."),
 	output_simple_type_opcode(SimpleType).
 
 output_instr(div(Signed)) --> 
@@ -998,12 +998,13 @@
 	output_overflow(OverFlow),
 	output_signed(Signed).
 	
-	% XXX we really should implement this since we will use it
-	% eventually.
-output_instr(switch(_)) --> { error("output not implemented") }.
+output_instr(switch(Targets)) --> 
+	io__write_string("switch ("),
+	io__write_list(Targets, ", ", output_target),
+	io__write_string(")").
 
-	% XXX should be implemented
-output_instr(unaligned(_)) --> { error("output not implemented") }.
+output_instr(unaligned(_)) --> 
+	io__write_string("unaligned.").
 
 output_instr(box(Type)) --> 
 	io__write_string("box\t"),
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.5
diff -u -r1.5 mlds_to_il.m
--- compiler/mlds_to_il.m	2000/11/08 07:23:09	1.5
+++ compiler/mlds_to_il.m	2000/11/09 04:53:17
@@ -884,15 +884,11 @@
 statement_to_il(statement(computed_goto(Rval, MLDSLabels), _Context), 
 		Instrs) -->
 	load(Rval, RvalLoadInstrs),
-	list__map_foldl(
-		(pred(_A::in, X::out, in, out) is det 
-			--> il_info_make_next_label(X)), MLDSLabels, Labels),
-	{ Targets = list__map(func(L) = label_target(L), Labels) },
-	{ LabelInstrs = list__map(func(L) = label(L), Labels) },
+	{ Targets = list__map(func(L) = label_target(L), MLDSLabels) },
 	{ Instrs = tree__list([
 		comment_node("computed goto"),
 		RvalLoadInstrs,
-		node([switch(Targets) | LabelInstrs])
+		instr_node(switch(Targets))
 		]) }.
 
 
@@ -1300,8 +1296,7 @@
 unaryop_to_il(std_unop(mkbody),	_, comment_node("mkbody (a no-op)")) --> [].
 unaryop_to_il(std_unop(unmkbody), _, comment_node("unmkbody (a no-op)")) --> [].
 
-unaryop_to_il(std_unop(cast_to_unsigned), _,
-	throw_unimplemented("unimplemented cast_to_unsigned unop")) --> [].
+unaryop_to_il(std_unop(cast_to_unsigned), _, instr_node(conv(uint32))) --> [].
 		% XXX implement this using string__hash
 unaryop_to_il(std_unop(hash_string), _,
 	throw_unimplemented("unimplemented hash_string unop")) --> [].
@@ -2483,7 +2478,7 @@
 	].
 
 :- func runtime_init_module_name = ilds__class_name.
-runtime_init_module_name = ["mercury", "private_builtin"].
+runtime_init_module_name = ["mercury", "private_builtin__c_code"].
 
 :- func runtime_init_method_name = ilds__member_name.
 runtime_init_method_name = id("init_runtime").
Index: compiler/mlds_to_ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_ilasm.m,v
retrieving revision 1.2
diff -u -r1.2 mlds_to_ilasm.m
--- compiler/mlds_to_ilasm.m	2000/10/22 07:27:20	1.2
+++ compiler/mlds_to_ilasm.m	2000/11/09 04:53:17
@@ -588,7 +588,7 @@
 	( { ClassName = il_generic_class_name } ->
 		io__write_string("MR_Box")
 	;
-		io__write_string("class "),
+		io__write_string("public class "),
 		write_managed_cpp_class_name(ClassName),
 		io__write_string(" *")
 	).


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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