[m-rev.] diff: test constant propagation

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Feb 11 00:12:02 AEDT 2004


Estimated hours taken: 1
Branches: main

Improve the testing of constant propagation.

tests/hard_coded/Mmakefile:
tests/hard_coded/constant_prop_1.m:
tests/hard_coded/constant_prop_1.exp:
tests/hard_coded/constant_prop_2.m:
tests/hard_coded/constant_prop_2.exp:
tests/hard_coded/Mercury.options
	Add two new tests of constant propagation.
	For the first test, we test by grepping the generated target code
	for the expected constants.
	For the second test, we test by including a reference to an
	undefined external procedure "link_error" which will get
	optimized away iff the compiler does constant propagation.

Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.222
diff -u -d -r1.222 Mmakefile
--- tests/hard_coded/Mmakefile	10 Feb 2004 09:33:06 -0000	1.222
+++ tests/hard_coded/Mmakefile	10 Feb 2004 13:09:56 -0000
@@ -23,6 +23,8 @@
 	compare_spec \
 	comparison \
 	contains_char \
+	constant_prop_1 \
+	constant_prop_2 \
 	constraint \
 	constraint_order \
 	construct_test \
@@ -239,7 +241,7 @@
 endif
 
 # Tests of the Java foreign language interface only
-# work in IL grades
+# work in Java grades
 ifeq "$(filter java%,$(GRADE))" ""
 	JAVA_PROGS =
 else
@@ -456,6 +458,31 @@
 			< $@.tmp > $@; \
 		rm -f $@.tmp; \
 	fi
+
+# For the constant_prop_1 test case, we test that constant propagation
+# has been achieved by grepping the generated target code for particular
+# patterns that will only arise if the Mercury compiler did the intended
+# constant propagation.
+constant_prop_1.c: constant_prop_1.c_date
+	grep foobar $@
+	grep 1234 $@
+	grep 5678.0 $@
+constant_prop_1.s: constant_prop_1.s_date
+	grep foobar $@
+	grep 1234 $@
+	grep 5678.0 $@
+constant_prop_1.pic_s: constant_prop_1.pic_s_date
+	grep foobar $@
+	grep 1234 $@
+	grep 5678.0 $@
+constant_prop_1.java: constant_prop_1.java_date
+	grep foobar $@
+	grep 1234 $@
+	grep 5678.0 $@
+constant_prop_1.il: constant_prop_1.il_date
+	grep foobar $@
+	grep 1234 $@
+	grep 5678.0 $@
 
 #-----------------------------------------------------------------------------#
 
Index: tests/hard_coded/constant_prop_1.exp
===================================================================
RCS file: tests/hard_coded/constant_prop_1.exp
diff -N tests/hard_coded/constant_prop_1.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/constant_prop_1.exp	12 Jan 2004 07:30:34 -0000
@@ -0,0 +1,3 @@
+foobar
+1234
+5678.00000000000
Index: tests/hard_coded/constant_prop_1.m
===================================================================
RCS file: tests/hard_coded/constant_prop_1.m
diff -N tests/hard_coded/constant_prop_1.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/constant_prop_1.m	10 Feb 2004 13:07:05 -0000
@@ -0,0 +1,13 @@
+:- module constant_prop_1.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module string, int, float.
+
+main -->
+	io.write_string("foo" ++ "bar"), io.nl,
+	io.write_int(1 * 1000 + 2 * 100 + 3 * 10 + 4), io.nl,
+	io.write_float(5.0 * 1000.0 + 6.0 * 100.0 + 7.0 * 10.0 + 8.0), io.nl.
Index: tests/hard_coded/constant_prop_2.exp
===================================================================
RCS file: tests/hard_coded/constant_prop_2.exp
diff -N tests/hard_coded/constant_prop_2.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/constant_prop_2.exp	12 Jan 2004 07:30:52 -0000
@@ -0,0 +1,3 @@
+yes
+yes
+yes
Index: tests/hard_coded/constant_prop_2.m
===================================================================
RCS file: tests/hard_coded/constant_prop_2.m
diff -N tests/hard_coded/constant_prop_2.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/constant_prop_2.m	12 Jan 2004 07:27:42 -0000
@@ -0,0 +1,30 @@
+:- module constant_prop_2.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module string, int, float.
+
+main -->
+	( { "abc" ++ "xyz" = "abcxyz" } ->
+		io.write_string("yes"), io.nl
+	;
+		link_error
+	),
+	( { 5 * 10000 + 4 * 1000 + 3 * 100 + 2 * 10 + 1 = 54321 } ->
+		io.write_string("yes"), io.nl
+	;
+		link_error
+	),
+	( { 4.0 * 1000.0 + 3.0 * 100.0 + 2.0 * 10.0 + 1.0 = 4321.0 } ->
+		io.write_string("yes"), io.nl
+	;
+		link_error
+	).
+
+	% We should be able to optimize away all calls to this procedure
+	% at compile time, so we should not even emit a reference to it.
+:- pred link_error(io::di, io::uo) is det.
+:- external(link_error/2).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list