[m-rev.] diff: fix `mmc --make' bug

Simon Taylor stayl at cs.mu.OZ.AU
Tue Sep 23 12:33:30 AEST 2003


Estimated hours taken: 1
Branches: main

Fix a bug which caused `mmc --make foo.o' to fail.

compiler/make.m:
compiler/make.util.m:
	Avoid returning multiple possible file types for object files.

compiler/compile_target_code.m:
	For the (in, out, in) mode of maybe_pic_object_file_extension,
	always return `non_pic' if the platform doesn't need special
	handling for PIC.

tests/mmc_make/Mmakefile:
tests/mmc_make/build_object:
	Test case.

Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.46
diff -u -u -r1.46 compile_target_code.m
--- compiler/compile_target_code.m	6 Aug 2003 12:38:08 -0000	1.46
+++ compiler/compile_target_code.m	23 Sep 2003 02:22:19 -0000
@@ -156,7 +156,7 @@
 	% to the value of P.
 :- pred maybe_pic_object_file_extension(globals, pic, string).
 :- mode maybe_pic_object_file_extension(in, in, out) is det.
-:- mode maybe_pic_object_file_extension(in, out, in) is nondet.
+:- mode maybe_pic_object_file_extension(in, out, in) is semidet.
 
 	% Same as above except the globals, G, are obtained from the io__state.
 :- pred maybe_pic_object_file_extension(pic::in, string::out,
@@ -1727,13 +1727,40 @@
 
 %-----------------------------------------------------------------------------%
 
-maybe_pic_object_file_extension(Globals, pic, Ext) :-
-	globals__lookup_string_option(Globals, pic_object_file_extension, Ext).
-maybe_pic_object_file_extension(Globals, link_with_pic, ObjExt) :-
-	globals__lookup_string_option(Globals,
-		link_with_pic_object_file_extension, ObjExt).
-maybe_pic_object_file_extension(Globals, non_pic, Ext) :-
-	globals__lookup_string_option(Globals, object_file_extension, Ext).
+:- pragma promise_pure(maybe_pic_object_file_extension/3).
+maybe_pic_object_file_extension(Globals::in, PIC::in, Ext::out) :-
+	( PIC = non_pic,
+		globals__lookup_string_option(Globals,
+			object_file_extension, Ext)
+	; PIC = pic,
+		globals__lookup_string_option(Globals,
+			pic_object_file_extension, Ext)
+	; PIC = link_with_pic,
+		globals__lookup_string_option(Globals,
+			link_with_pic_object_file_extension, Ext)
+	).
+maybe_pic_object_file_extension(Globals::in, PIC::out, Ext::in) :-
+	(
+		% This test must come first -- if the architecture doesn't
+		% need special treatment for PIC, we should always return
+		% `non_pic'.  `mmc --make' depends on this.
+		globals__lookup_string_option(Globals,
+			object_file_extension, Ext)
+	->
+		PIC = non_pic
+	;
+		globals__lookup_string_option(Globals,
+			pic_object_file_extension, Ext)
+	->
+		PIC = pic
+	;
+		globals__lookup_string_option(Globals,
+			link_with_pic_object_file_extension, Ext)
+ 	->
+		PIC = link_with_pic
+	;
+		fail
+	).
 
 maybe_pic_object_file_extension(PIC, ObjExt) -->
 	globals__io_get_globals(Globals),
Index: compiler/make.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.17
diff -u -u -r1.17 make.m
--- compiler/make.m	15 Mar 2003 03:08:56 -0000	1.17
+++ compiler/make.m	23 Sep 2003 01:58:46 -0000
@@ -319,7 +319,10 @@
 	    (pred(TargetFile0::out) is nondet :-
 		(
 			Suffix = target_extension(Globals,
-				ModuleTargetType)
+				ModuleTargetType),
+			% Allowing these will cause multiple solutions,
+			% which will cause classification to fail.
+			ModuleTargetType \= factt_object(_)
 		->
 			ModuleNameStr = ModuleNameStr0,
 			TargetType0 = module_target(ModuleTargetType)
Index: compiler/make.util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.util.m,v
retrieving revision 1.15
diff -u -u -r1.15 make.util.m
--- compiler/make.util.m	15 Mar 2003 03:08:56 -0000	1.15
+++ compiler/make.util.m	23 Sep 2003 00:40:03 -0000
@@ -672,11 +672,15 @@
 target_extension(_, asm_code(pic)) = ".pic_s".
 target_extension(Globals, object_code(PIC)) = Ext :-
 	maybe_pic_object_file_extension(Globals, PIC, Ext).
-target_extension(Globals, foreign_object(PIC, c)) = Ext :-
-	maybe_pic_object_file_extension(Globals, PIC, Ext).
 
 		% Note we use the bogus extension "bogus ext" so that
 		% the reverse mode of this function remains nondet.
+target_extension(_, foreign_object(PIC, c)) = "bogus ext" :-
+	( PIC = pic
+	; PIC = link_with_pic
+	; PIC = non_pic
+	),
+	unexpected(this_file, "C foreign_object").
 target_extension(_, foreign_object(PIC, csharp)) = "bogus ext" :-
 	( PIC = pic
 	; PIC = link_with_pic
Index: tests/mmc_make//Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/mmc_make/Mmakefile,v
retrieving revision 1.2
diff -u -u -r1.2 Mmakefile
--- tests/mmc_make//Mmakefile	19 Feb 2003 03:15:34 -0000	1.2
+++ tests/mmc_make//Mmakefile	23 Sep 2003 02:02:31 -0000
@@ -35,6 +35,9 @@
 	$(MCM) --rebuild --verbose-make rebuild > rebuild.err2 2>&1
 	grep '^Making rebuild$(EXT_FOR_EXE)$$' rebuild.err2
 
+# The compiler used to fail when invoked as `mmc --make build_object.o'.
+build_object.runtest: build_object.o
+
 .PHONY: install_libs
 install_libs: start_runtests_local
 	cd lib; \
Index: tests/mmc_make//build_object.m
===================================================================
RCS file: tests/mmc_make//build_object.m
diff -N tests/mmc_make//build_object.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make//build_object.m	23 Sep 2003 02:02:49 -0000
@@ -0,0 +1,9 @@
+:- module build_object.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+main --> io__write_string("Hello, world\n").
--------------------------------------------------------------------------
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