[m-rev.] diff: clean up `mmc --make' file name handling

Simon Taylor stayl at cs.mu.OZ.AU
Wed Sep 24 13:56:46 AEST 2003


Estimated hours taken: 3
Branches: main

Clean up the conversion of targets to file names by `mmc --make'.
Don't assume that every target can be converted simply by adding
an extension -- this isn't true for object files for foreign code
or fact tables.

compiler/make.m:
compiler/make.*.m:
	s/factt_object/fact_table_object/

	Instead of having one fact_table_object target for each module,
	have one for each fact table file.  Previously it wasn't possible
	to identify a fact_table_object target with a target file without
	additional information.

compiler/make.util.m:
compiler/make.*.m:
	make_util.target_extension now returns a `maybe' type, since
	foreign code and fact table targets can't be converted to
	file names by adding an extension.

	Add predicates module_target_to_file_name and
	module_target_to_search_file_name which are like
	module_name_to_file_name, but which handle the
	special cases for foreign code and fact tables
	correctly.

Index: make.dependencies.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.dependencies.m,v
retrieving revision 1.12
diff -u -u -r1.12 make.dependencies.m
--- make.dependencies.m	23 Dec 2002 12:32:57 -0000	1.12
+++ make.dependencies.m	24 Sep 2003 01:26:59 -0000
@@ -207,7 +207,7 @@
 	]).
 target_dependencies(Globals, foreign_object(PIC, _)) =
 	get_foreign_deps(Globals, PIC).
-target_dependencies(Globals, factt_object(PIC)) =
+target_dependencies(Globals, fact_table_object(PIC, _)) =
 	get_foreign_deps(Globals, PIC).
 
 :- func get_foreign_deps(globals, pic) = find_module_deps(dependency_file).
Index: make.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.18
diff -u -u -r1.18 make.m
--- make.m	23 Sep 2003 02:33:11 -0000	1.18
+++ make.m	23 Sep 2003 15:22:26 -0000
@@ -143,7 +143,7 @@
 			% `--target c' and `--target asm'.
 	;	target_code_to_object_code(pic)
 	;	foreign_code_to_object_code(pic, foreign_language)
-	;	fact_table_code_to_object_code(pic)
+	;	fact_table_code_to_object_code(pic, file_name)
 	.
 
 :- type module_compilation_task_type
@@ -174,7 +174,7 @@
 	;	object_code(pic)
 	;	foreign_il_asm(foreign_language)
 	;	foreign_object(pic, foreign_language)
-	;	factt_object(pic)
+	;	fact_table_object(pic, file_name)
 	.
 
 :- type c_header_type
@@ -318,11 +318,8 @@
 	solutions(
 	    (pred(TargetFile0::out) is nondet :-
 		(
-			Suffix = target_extension(Globals,
-				ModuleTargetType),
-			% Allowing these will cause multiple solutions,
-			% which will cause classification to fail.
-			ModuleTargetType \= factt_object(_)
+			yes(Suffix) = target_extension(Globals,
+				ModuleTargetType)
 		->
 			ModuleNameStr = ModuleNameStr0,
 			TargetType0 = module_target(ModuleTargetType)
@@ -348,7 +345,8 @@
 			TargetType0 = linked_target(executable)
 		;
 			string__append(Suffix1, "s", Suffix),
-			Suffix1 = target_extension(Globals, ModuleTargetType),
+			yes(Suffix1) = target_extension(Globals,
+						ModuleTargetType),
 
 			% Not yet implemented. `build_all' targets
 			% are only used by tools/bootcheck, so it
Index: make.module_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.module_target.m,v
retrieving revision 1.24
diff -u -u -r1.24 make.module_target.m
--- make.module_target.m	6 Aug 2003 12:38:09 -0000	1.24
+++ make.module_target.m	24 Sep 2003 03:54:24 -0000
@@ -371,27 +371,17 @@
 					Imports, ForeignCodeFile),
 			Succeeded).
 
-build_target_2(ModuleName, fact_table_code_to_object_code(PIC), _,
-		Imports, _, ErrorStream, Succeeded, Info, Info) -->
-	list__map_foldl(fact_table_foreign_code_file(ModuleName, PIC),
-			Imports ^ fact_table_deps, FactTableForeignCodes),
-	{ CompileTargetCode =
-	    (pred(Succeeded1::out, di, uo) is det -->
-		list__map_foldl(compile_foreign_code_file(ErrorStream, PIC,
-				Imports),
-			FactTableForeignCodes, ForeignCodeSucceeded),
-		{
-			\+ list__member(no, ForeignCodeSucceeded)
-		->
-			Succeeded1 = yes
-		;
-			Succeeded1 = no
-		}
-	    ) },
+build_target_2(ModuleName, fact_table_code_to_object_code(PIC, FactTableFile),
+		_, Imports, _, ErrorStream, Succeeded, Info, Info) -->
+	fact_table_foreign_code_file(ModuleName, PIC, FactTableFile,
+		FactTableForeignCode),
 
 	% Run the compilation in a child process so it can
 	% be killed if an interrupt arrives.
-	call_in_forked_process(CompileTargetCode, Succeeded).
+	call_in_forked_process(
+			compile_foreign_code_file(ErrorStream, PIC,
+					Imports, FactTableForeignCode),
+			Succeeded).
 
 :- pred build_object_code(module_name::in, compilation_target::in, pic::in,
 	io__output_stream::in, module_imports::in, bool::out,
@@ -644,8 +634,8 @@
 	foreign_code_to_object_code(non_pic, Lang) - [].
 compilation_task(_, foreign_object(PIC, Lang)) =
 	foreign_code_to_object_code(PIC, Lang) - get_pic_flags(PIC).
-compilation_task(_, factt_object(PIC)) =
-	fact_table_code_to_object_code(PIC) - get_pic_flags(PIC).
+compilation_task(_, fact_table_object(PIC, FactTable)) =
+	fact_table_code_to_object_code(PIC, FactTable) - get_pic_flags(PIC).
 
 :- func get_pic_flags(pic) = list(string).
 
@@ -808,31 +798,20 @@
 	foreign_code_file(ModuleName, PIC, Lang, ForeignCodeFile),
 	{ ForeignObjectFile = ForeignCodeFile ^ object_file }.
 
-touched_files(TargetFile, fact_table_code_to_object_code(PIC),
-		[TargetFile], ForeignObjectFiles, Info0, Info) -->
+touched_files(TargetFile, fact_table_code_to_object_code(PIC, FactTableName),
+		[TargetFile], [FactTableObjectFile], Info, Info) -->
 	{ TargetFile = ModuleName - _ },
-	get_module_dependencies(ModuleName, MaybeImports, Info0, Info),
-	{ MaybeImports = yes(Imports0) ->
-		Imports = Imports0
-	;
-		% This error should have been caught earlier.
-		% We shouldn't be attempting to build a target
-		% if we couldn't find the dependencies for the
-		% module.
-		unexpected(this_file, "touched_files: no module dependencies")
-	},
-	list__map_foldl(fact_table_foreign_code_file(ModuleName, PIC),
-			Imports ^ fact_table_deps, FactTableForeignCodes),
-	{ ForeignObjectFiles = list__map((func(F) = F ^ object_file),
-			FactTableForeignCodes) }.
+	globals__io_get_globals(Globals),
+	{ ObjExt = get_object_extension(Globals, PIC) },
+	fact_table_file_name(ModuleName, FactTableName, ObjExt, yes,
+		FactTableObjectFile).
 
 external_foreign_code_files(PIC, Imports, ForeignFiles) -->
 	%
 	% Find externally compiled foreign code files for
 	% `:- pragma foreign_proc' declarations.
 	%
-	globals__io_get_globals(Globals),
-	{ ObjExt = target_extension(Globals, object_code(PIC)) },
+	maybe_pic_object_file_extension(PIC, ObjExt),
 	globals__io_get_target(CompilationTarget),
 	{ ModuleName = Imports ^ module_name },
 	(
Index: make.program_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.21
diff -u -u -r1.21 make.program_target.m
--- make.program_target.m	6 Aug 2003 12:38:09 -0000	1.21
+++ make.program_target.m	24 Sep 2003 01:39:49 -0000
@@ -196,12 +196,13 @@
 	% tables exist.
 	%
 	( { CompilationTarget = c ; CompilationTarget = asm } ->
-		{ Imports ^ fact_table_deps \= [] ->
-			ObjectTargets = [target(ModuleName - factt_object(PIC))
-					| ForeignObjectTargets]
-		;
-			ObjectTargets = ForeignObjectTargets
-		}
+		{ FactObjectTargets = list__map(
+			(func(FactFile) =
+				target(ModuleName -
+					fact_table_object(PIC, FactFile))
+			),
+			Imports ^ fact_table_deps) },
+		{ ObjectTargets = FactObjectTargets ++ ForeignObjectTargets }
 	;
 		{ ObjectTargets = ForeignObjectTargets }
 	).
@@ -994,26 +995,21 @@
 		), FactTableFiles, !Info),
 
 	{ CCodeModule = foreign_language_module_name(ModuleName, c) },
-	remove_file(CCodeModule, ".c", !Info),
+	remove_target_file(CCodeModule, c_code, !Info),
 
 	%
 	% Remove object and assembler files.
 	%
 	list__foldl2(
 	    (pred(PIC::in, !.Info::in, !:Info::out, di, uo) is det -->
-		globals__io_get_globals(Globals),
-		{ ObjExt = target_extension(Globals, object_code(PIC)) },
-		{ AsmExt = target_extension(Globals, asm_code(PIC)) },
 		remove_target_file(ModuleName, object_code(PIC), !Info),
 		remove_target_file(ModuleName, asm_code(PIC), !Info),
-		remove_file(CCodeModule, ObjExt, !Info),
-		remove_file(CCodeModule, AsmExt, !Info),
+		remove_target_file(ModuleName, foreign_object(PIC, c), !Info),
 		list__foldl2(
 		    (pred(FactTableFile::in, !.Info::in, !:Info::out,
 				di, uo) is det -->
-			fact_table_file_name(ModuleName, FactTableFile,
-				ObjExt, no, FactTableObjFile),
-			remove_file(FactTableObjFile, !Info)
+			remove_target_file(ModuleName,
+				fact_table_object(PIC, FactTableFile), !Info)
 		    ), FactTableFiles, !Info)
 	    ),
 	    [pic, link_with_pic, non_pic], !Info),
@@ -1024,14 +1020,15 @@
 	{ CSharpModule = foreign_language_module_name(ModuleName, csharp) },
 	remove_file(CSharpModule, foreign_language_file_extension(csharp),
 		!Info),
-	remove_file(CSharpModule, ".dll", !Info),
+	remove_target_file(CSharpModule, foreign_il_asm(csharp), !Info),
 	
 	{ McppModule = foreign_language_module_name(ModuleName,
 				managed_cplusplus) },
 	remove_file(McppModule,
 		foreign_language_file_extension(managed_cplusplus),
 		!Info),
-	remove_file(McppModule, ".dll", !Info).
+	remove_target_file(McppModule, foreign_il_asm(managed_cplusplus),
+		!Info).
 
 :- pred make_module_realclean(module_name::in, make_info::in, make_info::out,
 		io__state::di, io__state::uo) is det.
Index: make.util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.util.m,v
retrieving revision 1.16
diff -u -u -r1.16 make.util.m
--- make.util.m	23 Sep 2003 02:33:11 -0000	1.16
+++ make.util.m	24 Sep 2003 03:52:22 -0000
@@ -169,9 +169,9 @@
 :- func make_dependency_list(list(module_name), module_target_type) =
 		list(dependency_file).
 
-:- func target_extension(globals, module_target_type) = string.
+:- func target_extension(globals, module_target_type) = maybe(string).
 :- mode target_extension(in, in) = out is det.
-:- mode target_extension(in, out) = in is nondet.
+:- mode target_extension(in, out) = in(bound(yes(ground))) is nondet.
 
 :- pred linked_target_file_name(module_name, linked_target_type, file_name,
 		io__state, io__state).
@@ -462,12 +462,12 @@
 get_timestamp_file_timestamp(ModuleName - FileType,
 		MaybeTimestamp, Info0, Info) -->
 	globals__io_get_globals(Globals),
-	{ TimestampExt = timestamp_extension(Globals, FileType) ->
-		Ext = TimestampExt	
+	( { TimestampExt = timestamp_extension(Globals, FileType) } ->
+		module_name_to_file_name(ModuleName,
+			TimestampExt, no, FileName)
 	;
-		Ext = target_extension(Globals, FileType)
-	},
-	module_name_to_file_name(ModuleName, Ext, no, FileName),
+		module_target_to_file_name(ModuleName, FileType, no, FileName)
+	),
 
 	% We should only ever look for timestamp files
 	% in the current directory. Timestamp files are
@@ -558,13 +558,20 @@
 	;
 		{ Info = Info0 },
 		globals__io_get_globals(Globals),
-		{ Ext = target_extension(Globals, FileType) },
-		( { Search = yes } ->
-			module_name_to_search_file_name(ModuleName,
-				Ext, FileName)
+		{ MaybeExt = target_extension(Globals, FileType) },
+		(
+			{ MaybeExt = yes(Ext) },
+			( { Search = yes } ->
+				module_name_to_search_file_name(ModuleName,
+					Ext, FileName)
+			;
+				module_name_to_file_name(ModuleName,
+					Ext, no, FileName)
+			)
 		;
-			module_name_to_file_name(ModuleName,
-				Ext, no, FileName)
+			{ MaybeExt = no },
+			module_target_to_file_name(ModuleName, FileType,
+				no, Search, FileName)
 		)
 	).
 
@@ -629,8 +636,8 @@
 
 remove_target_file(ModuleName, FileType, Info0, Info) -->
 	globals__io_get_globals(Globals),
-	remove_file(ModuleName, target_extension(Globals, FileType),
-		Info0, Info1),
+	module_target_to_file_name(ModuleName, FileType, no, FileName),
+	remove_file(FileName, Info0, Info1),
 	( { TimestampExt = timestamp_extension(Globals, FileType) } ->
 		remove_file(ModuleName, TimestampExt, Info1, Info)
 	;
@@ -653,68 +660,32 @@
 make_dependency_list(ModuleNames, FileType) =
 	list__map((func(Module) = target(Module - FileType)), ModuleNames).
 
-target_extension(_, source) = ".m".
-target_extension(_, errors) = ".err".
-target_extension(_, private_interface) = ".int0".
-target_extension(_, long_interface) = ".int".
-target_extension(_, short_interface) = ".int2".
-target_extension(_, unqualified_short_interface) = ".int3".
-target_extension(_, intermodule_interface) = ".opt".
-target_extension(_, aditi_code) = ".rlo".
-target_extension(_, c_header(mih)) = ".mih".
-target_extension(_, c_header(mh)) = ".mh".
-target_extension(_, c_code) = ".c".
-target_extension(_, il_code) = ".il".
-target_extension(_, il_asm) = ".dll". % XXX ".exe" if the module contains main.
-target_extension(_, java_code) = ".java".
-target_extension(_, asm_code(non_pic)) = ".s".
-target_extension(_, asm_code(link_with_pic)) = ".s".
-target_extension(_, asm_code(pic)) = ".pic_s".
-target_extension(Globals, object_code(PIC)) = Ext :-
+target_extension(_, source) = yes(".m").
+target_extension(_, errors) = yes(".err").
+target_extension(_, private_interface) = yes(".int0").
+target_extension(_, long_interface) = yes(".int").
+target_extension(_, short_interface) = yes(".int2").
+target_extension(_, unqualified_short_interface) = yes(".int3").
+target_extension(_, intermodule_interface) = yes(".opt").
+target_extension(_, aditi_code) = yes(".rlo").
+target_extension(_, c_header(mih)) = yes(".mih").
+target_extension(_, c_header(mh)) = yes(".mh").
+target_extension(_, c_code) = yes(".c").
+target_extension(_, il_code) = yes(".il").
+
+	% XXX ".exe" if the module contains main.
+target_extension(_, il_asm) = yes(".dll").
+target_extension(_, java_code) = yes(".java").
+target_extension(_, asm_code(non_pic)) = yes(".s").
+target_extension(_, asm_code(link_with_pic)) = yes(".s").
+target_extension(_, asm_code(pic)) = yes(".pic_s").
+target_extension(Globals, object_code(PIC)) = yes(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
-	; PIC = non_pic
-	),
-	unexpected(this_file, "C# foreign_object").
-target_extension(_, foreign_object(PIC, managed_cplusplus)) = "bogus ext" :-
-	( PIC = pic
-	; PIC = link_with_pic
-	; PIC = non_pic
-	),
-	unexpected(this_file, "MC++ foreign_object").
-target_extension(_, foreign_object(PIC, il)) = "bogus ext" :-
-	( PIC = pic
-	; PIC = link_with_pic
-	; PIC = non_pic
-	),
-	unexpected(this_file, "il foreign_object").
-target_extension(_, foreign_object(PIC, java)) = "bogus ext" :-
-	( PIC = pic
-	; PIC = link_with_pic
-	; PIC = non_pic
-	),
-	unexpected(this_file, "Java foreign_object").
-target_extension(_, foreign_il_asm(c)) = "bogus ext" :-
-	unexpected(this_file, "C foreign_il_asm").
-target_extension(_, foreign_il_asm(java)) = "bogus ext" :-
-	unexpected(this_file, "Java 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).
+	% These all need to be handled as special cases.
+target_extension(_, foreign_object(_, _)) = no.
+target_extension(_, foreign_il_asm(_)) = no.
+target_extension(_, fact_table_object(_, _)) = no.
 
 linked_target_file_name(ModuleName, executable, FileName) -->
 	globals__io_lookup_string_option(executable_file_extension, Ext),
@@ -726,6 +697,68 @@
 	globals__io_lookup_string_option(shared_library_extension, Ext),
 	module_name_to_lib_file_name("lib", ModuleName, Ext, no, FileName).
 
+:- pred module_target_to_file_name(module_name::in, module_target_type::in,
+		bool::in, file_name::out, io__state::di, io__state::uo) is det.
+
+module_target_to_file_name(ModuleName, TargetType, MkDir, FileName) -->
+	module_target_to_file_name(ModuleName, TargetType,
+		MkDir, no, FileName).
+
+:- pred module_target_to_search_file_name(module_name::in,
+		module_target_type::in, file_name::out,
+		io__state::di, io__state::uo) is det.
+
+module_target_to_search_file_name(ModuleName, TargetType, FileName) -->
+	module_target_to_file_name(ModuleName, TargetType, no, yes, FileName).
+
+:- pred module_target_to_file_name(module_name::in, module_target_type::in,
+		bool::in, bool::in, file_name::out,
+		io__state::di, io__state::uo) is det.
+
+module_target_to_file_name(ModuleName, TargetType, MkDir, Search, FileName) -->
+    globals__io_get_globals(Globals),
+    { target_extension(Globals, TargetType) = MaybeExt },
+    (
+	{ MaybeExt = yes(Ext) },
+	( { Search = yes } ->
+		module_name_to_search_file_name(ModuleName,
+			Ext, FileName)
+	;		
+		module_name_to_file_name(ModuleName,
+			Ext, MkDir, FileName)
+	)
+    ;
+	{ MaybeExt = no },
+	( { TargetType = foreign_object(PIC, Lang) } ->
+		(
+			{ ForeignModuleName = foreign_language_module_name(
+					ModuleName, Lang) }
+		->
+			module_target_to_file_name(ForeignModuleName,
+				object_code(PIC), MkDir, Search, FileName)
+		;
+			{ error("module_target_to_file_name_2") }
+		)
+	; { TargetType = foreign_il_asm(Lang) } ->
+		(
+			{ ForeignModuleName = foreign_language_module_name(
+					ModuleName, Lang) }
+		->
+			module_target_to_file_name(ForeignModuleName,
+				il_asm, MkDir, Search, FileName)
+		;
+			{ error("module_target_to_file_name_2") }
+		)
+	; { TargetType = fact_table_object(PIC, FactFile) } ->
+		maybe_pic_object_file_extension(PIC, Ext),
+		fact_table_file_name(ModuleName, FactFile, Ext,
+			MkDir, FileName)
+	;
+		{ error("module_target_to_file_name_2") }
+	)
+    ).
+
+
 	% Note that we need a timestamp file for `.err' files because
 	% errors are written to the `.err' file even when writing interfaces.
 	% The timestamp is only updated when compiling to target code.
@@ -765,7 +798,7 @@
 search_for_file_type(object_code(_)) = no.
 search_for_file_type(foreign_object(_, _)) = no.
 search_for_file_type(foreign_il_asm(_)) = no.
-search_for_file_type(factt_object(_)) = no.
+search_for_file_type(fact_table_object(_, _)) = no.
 
 target_is_grade_or_arch_dependent(Target) :-
 	target_is_grade_or_arch_dependent(Target, yes).
@@ -791,7 +824,7 @@
 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_il_asm(_), yes).
-target_is_grade_or_arch_dependent(factt_object(_), yes).
+target_is_grade_or_arch_dependent(fact_table_object(_, _), yes).
 
 %-----------------------------------------------------------------------------%
 
@@ -825,25 +858,9 @@
 write_dependency_file(target(TargetFile)) --> write_target_file(TargetFile).
 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_il_asm(Lang)
-		; FileType = foreign_object(_, Lang)
-		),
-		ForeignName = foreign_language_module_name(ModuleName0, Lang)
-	->
-		ModuleName = ForeignName
-	;
-		ModuleName = ModuleName0
-	},
-	prog_out__write_sym_name(ModuleName),
-	globals__io_get_globals(Globals),
-	io__write_string(target_extension(Globals, FileType)).
+write_target_file(ModuleName - FileType) -->
+	module_target_to_file_name(ModuleName, FileType, no, FileName),
+	io__write_string(FileName).
 
 maybe_make_linked_target_message(TargetFile) -->
 	verbose_msg(
--------------------------------------------------------------------------
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