[m-rev.] for review: mmc --make for external foreign files improvements

Peter Ross pro at missioncriticalit.com
Fri Dec 20 02:35:07 AEDT 2002


The log message diff:
--- zzlog.make	2002-12-18 15:32:55.000000000 +0100
+++ zzlog.make2	2002-12-19 16:31:36.000000000 +0100
@@ -21,6 +21,7 @@
 	s,/,\\\\,g in the C# filename as the MS C# compiler doesn't
 	understand / as a directory seperator.
 	Add the referenced dlls to the C# compilers command line.
+	Export maybe_pic_object_file_extension.
 
 compiler/handle_options.m:
 	Fix a bug where copmute_grade incorrectly generated `hl.il'
@@ -40,8 +41,9 @@
 
 compiler/make.module_target.m:
 	Always create a directory to hold the target file before
-	building the target file.
-
+	building the target file.  This fixes a bug where the target
+	directory wasn't always being created before building the
+	target file.

 compiler/make.program_target.m:
 	Determine the targets needed to be built for all the external




The code interdiff:

diff -u compiler/compile_target_code.m compiler/compile_target_code.m
--- compiler/compile_target_code.m
+++ compiler/compile_target_code.m
@@ -15,6 +15,7 @@
 
 :- import_module parse_tree__prog_data, parse_tree__prog_io.
 :- import_module parse_tree__modules.
+:- import_module libs__globals.
 
 :- import_module bool, list, io, std_util.
 
@@ -141,9 +142,22 @@
 		list(module_name)) = string.
 
 %-----------------------------------------------------------------------------%
+
+	% maybe_pic_object_file_extension(G, P, E) is true iff
+	% E is the extension which should be used on object files according
+	% 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.
+
+	% Same as above except the globals, G, are obtained from the io__state.
+:- pred maybe_pic_object_file_extension(pic::in, string::out,
+		io__state::di, io__state::uo) is det.
+
+%-----------------------------------------------------------------------------%
 :- implementation.
 
-:- import_module libs__globals, libs__options, libs__handle_options.
+:- import_module libs__options, libs__handle_options.
 :- import_module hlds__passes_aux, libs__trace_params.
 :- import_module parse_tree__prog_out.
 
@@ -616,13 +630,6 @@
 	invoke_system_command(ErrorStream, verbose_commands,
 		Command, Succeeded).
 
-:- pred maybe_pic_object_file_extension(pic::in, string::out,
-		io__state::di, io__state::uo) is det.
-maybe_pic_object_file_extension(pic, ObjExt) -->
-	globals__io_lookup_string_option(pic_object_file_extension, ObjExt).
-maybe_pic_object_file_extension(non_pic, ObjExt) -->
-	globals__io_lookup_string_option(object_file_extension, ObjExt).
-
 %-----------------------------------------------------------------------------%
 
 compile_java_file(ErrorStream, ModuleName, Succeeded) -->
@@ -1273,3 +1280,15 @@
 	).
 
 %-----------------------------------------------------------------------------%
+
+maybe_pic_object_file_extension(Globals, pic, Ext) :-
+	globals__lookup_string_option(Globals, pic_object_file_extension, Ext).
+maybe_pic_object_file_extension(Globals, non_pic, Ext) :-
+	globals__lookup_string_option(Globals, object_file_extension, Ext).
+
+maybe_pic_object_file_extension(PIC, ObjExt) -->
+	globals__io_get_globals(Globals),
+	{ maybe_pic_object_file_extension(Globals, PIC, ObjExt) }.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
diff -u compiler/make.dependencies.m compiler/make.dependencies.m
--- compiler/make.dependencies.m
+++ compiler/make.dependencies.m
@@ -189,7 +189,7 @@
 			long_interface `of` non_intermod_direct_imports,
 			short_interface `of` non_intermod_indirect_imports
 		]).
-target_dependencies(_, foreign_asm(_)) =
+target_dependencies(_, foreign_il_asm(_)) =
 	combine_deps_list([
 		il_asm `of` self,
 		il_asm `of` filter(maybe_keep_std_lib_module, direct_imports)
@@ -583,8 +583,8 @@
 %
 % filter(F, P, MN, S, Ms, I0, I, IO0, IO)
 % 	Filter the set of module_names returned from P called with MN, I0, IO0
-% 	as its input arguments with F.  The first argument to F will be MN.
-% 	and the second argument the 
+% 	as its input arguments with F.  The first argument to F will be MN
+% 	and the second argument be one of the module_names returned from P.
 %
 :- pred filter(pred(module_name, module_name)::pred(in, in) is semidet,
 		pred(module_name, bool, set(module_name), make_info, make_info,
@@ -603,7 +603,9 @@
 %
 % If the current module we are compiling is not in the standard library
 % and the module we are importing is then remove it, otherwise keep it.
-% This is because in the removal case we need to import mercury.dll instead.
+% When compiling with `--target il', if the current module is not in the
+% standard library, we link with mercury.dll rather than the DLL file for
+% the imported module.
 %
 :- pred maybe_keep_std_lib_module(module_name::in,
 		module_name::in) is semidet.
diff -u compiler/make.m compiler/make.m
--- compiler/make.m
+++ compiler/make.m
@@ -157,7 +157,7 @@
 	;	java_code
 	;	asm_code(pic)
 	;	object_code(pic)
-	;	foreign_asm(foreign_language)
+	;	foreign_il_asm(foreign_language)
 	;	foreign_object(pic, foreign_language)
 	;	factt_object(pic)
 	.
diff -u compiler/make.module_target.m compiler/make.module_target.m
--- compiler/make.module_target.m
+++ compiler/make.module_target.m
@@ -396,9 +396,6 @@
 	compile_target_code__compile_csharp_file(ErrorStream, Imports,
 		CSharpFile, DLLFile, Succeeded).
 
-:- pred foreign_code_file(module_name::in, pic::in, foreign_language::in,
-		foreign_code_file::out, io::di, io::uo) is det.
-
 %-----------------------------------------------------------------------------%
 
 :- pred maybe_make_directory_for_target_file(target_file::in,
@@ -416,6 +413,9 @@
 
 %-----------------------------------------------------------------------------%
 
+:- pred foreign_code_file(module_name::in, pic::in, foreign_language::in,
+		foreign_code_file::out, io::di, io::uo) is det.
+
 foreign_code_file(ModuleName, PIC, Lang, ForeignCodeFile) -->
 	globals__io_get_globals(Globals),
 	{
@@ -449,21 +449,9 @@
 get_object_extension(Globals, PIC) = Ext :-
 	globals__get_target(Globals, CompilationTarget),
 	( CompilationTarget = c,
-		( PIC = non_pic,
-			globals__lookup_string_option(Globals,
-					object_file_extension, Ext)
-		; PIC = pic,
-			globals__lookup_string_option(Globals,
-					pic_object_file_extension, Ext)
-		)
+		maybe_pic_object_file_extension(Globals, PIC, Ext)
 	; CompilationTarget = asm,
-		( PIC = non_pic,
-			globals__lookup_string_option(Globals,
-					object_file_extension, Ext)
-		; PIC = pic,
-			globals__lookup_string_option(Globals,
-					pic_object_file_extension, Ext)
-		)
+		maybe_pic_object_file_extension(Globals, PIC, Ext)
 	; CompilationTarget = il,
 		Ext = ".dll"
 	; CompilationTarget = java,
@@ -573,7 +561,7 @@
 			( PIC = pic -> ["--pic"] ; [] ).
 compilation_task(Globals, object_code(PIC)) =
 	target_code_to_object_code(PIC) - get_pic_flags(Globals, PIC).
-compilation_task(_, foreign_asm(Lang)) =
+compilation_task(_, foreign_il_asm(Lang)) =
 	foreign_code_to_object_code(non_pic, Lang) - [].
 compilation_task(Globals, foreign_object(PIC, Lang)) =
 	foreign_code_to_object_code(PIC, Lang) - get_pic_flags(Globals, PIC).
diff -u compiler/make.program_target.m compiler/make.program_target.m
--- compiler/make.program_target.m
+++ compiler/make.program_target.m
@@ -180,7 +180,7 @@
 	->
 		{ ForeignObjectTargets = list__map(
 				(func(L) =
-					target(ModuleName - foreign_asm(L))
+					target(ModuleName - foreign_il_asm(L))
 				), set__to_sorted_list(Langs)) }
 	;
 		{ ForeignObjectTargets = [] }
diff -u compiler/make.util.m compiler/make.util.m
--- compiler/make.util.m
+++ compiler/make.util.m
@@ -621,50 +621,36 @@
 target_extension(_, java_code) = ".java".
 target_extension(_, asm_code(non_pic)) = ".s".
 target_extension(_, asm_code(pic)) = ".pic_s".
-target_extension(Globals, object_code(non_pic)) = Ext :-
-	globals__lookup_string_option(Globals, object_file_extension, Ext).
-target_extension(Globals, object_code(pic)) = Ext :-
-	globals__lookup_string_option(Globals, pic_object_file_extension, Ext).
+target_extension(Globals, object_code(PIC)) = Ext :-
+	maybe_pic_object_file_extension(Globals, PIC, Ext).
 target_extension(Globals, foreign_object(PIC, c)) = Ext :-
-	( PIC = non_pic,
-		globals__lookup_string_option(Globals,
-				object_file_extension, Ext)
-	; PIC = pic,
-		globals__lookup_string_option(Globals,
-				pic_object_file_extension, Ext)
-	).
-target_extension(Globals, foreign_object(PIC, csharp)) = Ext :-
-	( PIC = non_pic,
-		globals__lookup_string_option(Globals,
-				object_file_extension, Ext)
-	; PIC = pic,
-		globals__lookup_string_option(Globals,
-				pic_object_file_extension, Ext)
-	).
-target_extension(Globals, foreign_object(PIC, managed_cplusplus)) = Ext :-
-	( PIC = non_pic,
-		globals__lookup_string_option(Globals,
-				object_file_extension, Ext)
-	; PIC = pic,
-		globals__lookup_string_option(Globals,
-				pic_object_file_extension, Ext)
-	).
-target_extension(Globals, foreign_object(PIC, il)) = Ext :-
-	( PIC = non_pic,
-		globals__lookup_string_option(Globals,
-				object_file_extension, Ext)
-	; PIC = pic,
-		globals__lookup_string_option(Globals,
-				pic_object_file_extension, Ext)
-	).
-target_extension(_, foreign_asm(c)) = ".dll".
-target_extension(_, foreign_asm(csharp)) = ".dll".
-target_extension(_, foreign_asm(managed_cplusplus)) = ".dll".
-target_extension(_, foreign_asm(il)) = ".dll".
-target_extension(Globals, factt_object(non_pic)) = Ext :-
-	globals__lookup_string_option(Globals, object_file_extension, Ext).
-target_extension(Globals, factt_object(pic)) = Ext :-
-	globals__lookup_string_option(Globals, pic_object_file_extension, Ext).
+	maybe_pic_object_file_extension(Globals, PIC, Ext).
+
+		% Note we use the bogus extension "XXX bogus ext" so that
+		% this predicate remains nondet.
+target_extension(_, foreign_object(PIC, csharp)) = "XXX bogus ext" :-
+	( PIC = pic
+	; PIC = non_pic
+	),
+	unexpected(this_file, "C# foreign_object").
+target_extension(_, foreign_object(PIC, managed_cplusplus)) = "XXX bogus ext" :-
+	( PIC = pic
+	; PIC = non_pic
+	),
+	unexpected(this_file, "MC++ foreign_object").
+target_extension(_, foreign_object(PIC, il)) = "XXX bogus ext" :-
+	( PIC = pic
+	; PIC = non_pic
+	),
+	unexpected(this_file, "il foreign_object").
+target_extension(_, foreign_il_asm(c)) = "XXX bogus ext" :-
+	unexpected(this_file, "C foreign_il_asm").
+
+target_extension(_, foreign_il_asm(csharp)) = ".dll".
+target_extension(_, foreign_il_asm(managed_cplusplus)) = ".dll".
+target_extension(_, foreign_il_asm(il)) = ".dll".
+target_extension(Globals, factt_object(PIC)) = Ext :-
+	maybe_pic_object_file_extension(Globals, PIC, Ext).
 
 linked_target_file_name(ModuleName, executable, FileName) -->
 	globals__io_lookup_string_option(executable_file_extension, Ext),
@@ -714,7 +700,7 @@
 search_for_file_type(asm_code(_)) = no.
 search_for_file_type(object_code(_)) = no.
 search_for_file_type(foreign_object(_, _)) = no.
-search_for_file_type(foreign_asm(_)) = no.
+search_for_file_type(foreign_il_asm(_)) = no.
 search_for_file_type(factt_object(_)) = no.
 
 target_is_grade_or_arch_dependent(Target) :-
@@ -740,7 +726,7 @@
 target_is_grade_or_arch_dependent(asm_code(_), yes).
 target_is_grade_or_arch_dependent(object_code(_), yes).
 target_is_grade_or_arch_dependent(foreign_object(_, _), yes).
-target_is_grade_or_arch_dependent(foreign_asm(_), yes).
+target_is_grade_or_arch_dependent(foreign_il_asm(_), yes).
 target_is_grade_or_arch_dependent(factt_object(_), yes).
 
 %-----------------------------------------------------------------------------%
@@ -776,8 +762,13 @@
 write_dependency_file(file(FileName, _)) --> io__write_string(FileName).
 
 write_target_file(ModuleName0 - FileType) -->
+	( { FileType = factt_object(_) } ->
+		io__write_string("fact table object files for ")
+	;
+		[]
+	),
 	{
-		( FileType = foreign_asm(Lang)
+		( FileType = foreign_il_asm(Lang)
 		; FileType = foreign_object(_, Lang)
 		),
 		ForeignName = foreign_language_module_name(ModuleName0, Lang)
@@ -851,3 +842,8 @@
 		set__delete(Info0 ^ command_line_targets, Target) }.
 
 %-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+this_file = "make.util.m".
+
+%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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