[m-dev.] diff: MLDS back-end: avoid unnecessary recompilation

Fergus Henderson fjh at cs.mu.OZ.AU
Wed May 24 16:04:32 AEST 2000


Estimated hours taken: 0.75

Avoid unnecessary recompilation for the MLDS back-end.
Previously Mmake was rerunning the C compiler on almost
every C file whenever anything changed.

compiler/mlds_to_c.m:
	Write the header file out to `foo.h.tmp' and then use
	`update_interface' to avoid updating the time stamp
	on `foo.h' if it hasn't changed.

compiler/modules.m:
	Ensure that `.h.tmp' files get named the same way
	that `.h' files get named.

Workspace: /home/pgrad/fjh/ws/hg
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.32
diff -u -d -r1.32 mlds_to_c.m
--- compiler/mlds_to_c.m	2000/05/22 18:00:09	1.32
+++ compiler/mlds_to_c.m	2000/05/24 04:39:50
@@ -56,21 +56,32 @@
 	% don't, then we get name clashes with the standard C header files.
 	% For example, `time.h' clashes with the standard <time.h> header.
 	%
-	% But to keep the Mmake auto-dependencies working (or at least
-	% _mostly_ working!), we still want to name the `.c' file based
-	% on just the Mercury module name, giving e.g. `time.c', not
-	% `mercury.time.c'.
-	%
+	% But to keep the Mmake auto-dependencies working, we still
+	% want to name the `.c' file based on just the Mercury module
+	% name, giving e.g. `time.c', not `mercury.time.c'.
 	% Hence the different treatment of SourceFile and HeaderFile below.
 	%
+	% We write the header file out to <module>.h.tmp and then
+	% call `update_interface' to move the <module>.h.tmp file to
+	% <module>.h; this avoids updating the timestamp on the `.h'
+	% file if it hasn't changed.
+	% 
+	% We output the source file before outputting the header,
+	% since the Mmake dependencies say the header file depends
+	% on the source file, and so if we wrote them out in the
+	% other order this might lead to unnecessary recompilation
+	% next time Mmake is run.
+	%
 	{ ModuleName = mlds__get_module_name(MLDS) },
 	module_name_to_file_name(ModuleName, ".c", yes, SourceFile),
 	{ MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName) },
 	{ ModuleSymName = mlds_module_name_to_sym_name(MLDS_ModuleName) },
+	module_name_to_file_name(ModuleSymName, ".h.tmp", yes, TmpHeaderFile),
 	module_name_to_file_name(ModuleSymName, ".h", yes, HeaderFile),
 	{ Indent = 0 },
-	mlds_output_to_file(HeaderFile, mlds_output_hdr_file(Indent, MLDS)),
-	mlds_output_to_file(SourceFile, mlds_output_src_file(Indent, MLDS)).
+	mlds_output_to_file(SourceFile, mlds_output_src_file(Indent, MLDS)),
+	mlds_output_to_file(TmpHeaderFile, mlds_output_hdr_file(Indent, MLDS)),
+	update_interface(HeaderFile).
 	%
 	% XXX at some point we should also handle output of any non-C
 	%     foreign code (Ada, Fortran, etc.) to appropriate files.
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.127
diff -u -d -r1.127 modules.m
--- compiler/modules.m	2000/05/21 02:58:48	1.127
+++ compiler/modules.m	2000/05/24 04:39:43
@@ -631,6 +631,10 @@
 		; Ext = ".int3s"
 		; Ext = ".opts"
 		; Ext = ".trans_opts"
+		% The current interface to `mercury_update_interface'
+		% requires .h.tmp files to be in the same directory as
+		% the .h files
+		; Ext = ".h.tmp"
 		}
 	->
 		{ FileName0 = BaseName }
@@ -700,7 +704,7 @@
 	globals__io_lookup_bool_option(highlevel_code, HighLevelCode),
 	{
 		HighLevelCode = yes,
-		Ext = ".h",
+		( Ext = ".h" ; Ext = ".h.tmp" ),
 		ModuleName = unqualified(UnqualModuleName),
 		mercury_std_library_module(UnqualModuleName),
 		\+ string__prefix(FileName0, "mercury.")

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- 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