[m-dev.] diff: mlds_to_c.m: remove unnecessary (and broken) casts

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Feb 6 03:51:11 AEDT 2001


This is for both the main and release branches.

Estimated hours taken: 1

compiler/mlds_to_c.m:
	Fix a couple of XXXs: don't output some unnecessary casts.
	Only output the intermediate casts to `MR_Word' when
	casting to/from `character' or mlds__native_{char,bool,int}_type.
	This also fixes a bug that broke the hlc* grades when using
	lcc: casts from pointers to integers aren't allowed in
	constant expressions.

Workspace: /home/venus/fjh/ws-venus2/mercury
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.78
diff -u -d -r1.78 mlds_to_c.m
--- compiler/mlds_to_c.m	2001/01/29 06:47:16	1.78
+++ compiler/mlds_to_c.m	2001/02/05 14:59:04
@@ -2734,14 +2734,23 @@
 		mlds_output_rval(Exprn),
 		io__write_string(")")
 	;
+		{ Type = mlds__mercury_type(term__functor(term__atom("character"),
+				[], _), _)
+		; Type = mlds__native_char_type
+		; Type = mlds__native_bool_type
+		; Type = mlds__native_int_type
+		}
+	->
 		% We cast first to MR_Word, and then to MR_Box.
 		% This is done to avoid spurious warnings about "cast from
-		% pointer to integer of different size" from gcc.
-		% XXX The generated code would be more readable if we
-		%     only did this for the cases where it was necessary.
+		% integer to pointer of different size" from gcc.
 		io__write_string("((MR_Box) (MR_Word) ("),
 		mlds_output_rval(Exprn),
 		io__write_string("))")
+	;
+		io__write_string("((MR_Box) ("),
+		mlds_output_rval(Exprn),
+		io__write_string("))")
 	).
 
 :- pred mlds_output_unboxed_rval(mlds__type, mlds__rval, io__state, io__state).
@@ -2758,14 +2767,24 @@
 		mlds_output_rval(Exprn),
 		io__write_string(")")
 	;
+		{ Type = mlds__mercury_type(term__functor(term__atom("character"),
+				[], _), _)
+		; Type = mlds__native_char_type
+		; Type = mlds__native_bool_type
+		; Type = mlds__native_int_type
+		}
+	->
 		% We cast first to MR_Word, and then to the desired type.
 		% This is done to avoid spurious warnings about "cast from
 		% pointer to integer of different size" from gcc.
-		% XXX The generated code would be more readable if we
-		%     only did this for the cases where it was necessary.
 		io__write_string("("),
 		mlds_output_cast(Type),
 		io__write_string("(MR_Word) "),
+		mlds_output_rval(Exprn),
+		io__write_string(")")
+	;
+		io__write_string("("),
+		mlds_output_cast(Type),
 		mlds_output_rval(Exprn),
 		io__write_string(")")
 	).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list