[m-rev.] diff: improve MLDS dumps

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jul 13 08:19:44 AEST 2001


Estimated hours taken: 1
Branches: main

Improve MLDS dumps: as well as dumping the raw MLDS,
also convert the MLDS to C and dump that.
This is useful for showing the intermediate stages,
and for debugging non-C targets.

compiler/mlds_to_c.m:
	Add an extra argument to output_mlds, specifying a suffix
	to add to the file names.

compiler/mercury_compile.m:
	In maybe_dump_mlds, also call mlds_to_c__output_mlds,
	passing it "_dump.<num>-<stage>" as the suffix.

compiler/modules.m:
	Put MLDS dumps in the current directory, even when --use-subdirs
	is enabled.  Handle the new ".c_dump*" and ".h_dump*" extensions.

compiler/mercury_compile.m:
compiler/mlds_to_gcc.m:
	Update to reflect the new interface to mlds_to_c__output_mlds
	(which is called when outputting C foreign_code).

compiler/options.m:
	Update the documentation of the --dump-mlds option.

doc/user_guide.texi:
	Document the --dump-mlds option.
	(Previously it was only documented in compiler/options.m.)

Workspace: /home/mars/fjh/ws2/mercury
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.208
diff -u -d -b -r1.208 mercury_compile.m
--- compiler/mercury_compile.m	2001/07/06 11:25:27	1.208
+++ compiler/mercury_compile.m	2001/07/12 21:57:46
@@ -3177,7 +3177,7 @@
 	globals__io_lookup_bool_option(statistics, Stats),
 
 	maybe_write_string(Verbose, "% Converting MLDS to C...\n"),
-	mlds_to_c__output_mlds(MLDS),
+	mlds_to_c__output_mlds(MLDS, ""),
 	maybe_write_string(Verbose, "% Finished converting MLDS to C.\n"),
 	maybe_report_stats(Stats).
 
@@ -3865,7 +3865,11 @@
 		{ string__append_list(
 			[BaseFileName, ".", StageNum, "-", StageName],
 			DumpFile) },
-		mercury_compile__dump_mlds(DumpFile, MLDS)
+		mercury_compile__dump_mlds(DumpFile, MLDS),
+
+		{ string__append_list(["_dump.", StageNum, "-", StageName],
+			DumpSuffix) },
+		mlds_to_c__output_mlds(MLDS, DumpSuffix)
 	;
 		[]
 	).
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.95
diff -u -d -b -r1.95 mlds_to_c.m
--- compiler/mlds_to_c.m	2001/07/12 15:44:54	1.95
+++ compiler/mlds_to_c.m	2001/07/12 21:55:44
@@ -22,8 +22,15 @@
 :- import_module mlds.
 :- import_module io.
 
-:- pred mlds_to_c__output_mlds(mlds, io__state, io__state).
-:- mode mlds_to_c__output_mlds(in, di, uo) is det.
+	% output_mlds(MLDS, Suffix):
+	%	Output C code to the appropriate C file and header file.
+	%	The file names are determined by the module name,
+	%	with the specified Suffix appended at the end.
+	%	(The suffix is used for debugging dumps.  For normal
+	%	output, the suffix should be the empty string.)
+	%	
+:- pred mlds_to_c__output_mlds(mlds, string, io__state, io__state).
+:- mode mlds_to_c__output_mlds(in, in, di, uo) is det.
 
 	% output an MLDS context in C #line format. 
 	% this is useful for other foreign language interfaces such as
@@ -64,7 +71,7 @@
 
 %-----------------------------------------------------------------------------%
 
-mlds_to_c__output_mlds(MLDS) -->
+mlds_to_c__output_mlds(MLDS, Suffix) -->
 	%
 	% We need to use the MLDS package name to compute the header file
 	% names, giving e.g. `mercury.io.h', `mercury.time.h' etc.,
@@ -90,11 +97,14 @@
 	% next time Mmake is run.
 	%
 	{ ModuleName = mlds__get_module_name(MLDS) },
-	module_name_to_file_name(ModuleName, ".c", yes, SourceFile),
+	module_name_to_file_name(ModuleName, ".c" ++ Suffix, 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),
+	module_name_to_file_name(ModuleSymName, ".h" ++ Suffix ++ ".tmp", yes,
+		TmpHeaderFile),
+	module_name_to_file_name(ModuleSymName, ".h" ++ Suffix, yes,
+		HeaderFile),
 	{ Indent = 0 },
 	output_to_file(SourceFile, mlds_output_src_file(Indent, MLDS)),
 	output_to_file(TmpHeaderFile, mlds_output_hdr_file(Indent, MLDS)),
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.45
diff -u -d -b -r1.45 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	2001/07/12 15:44:56	1.45
+++ compiler/mlds_to_gcc.m	2001/07/12 21:41:54
@@ -261,7 +261,7 @@
 		% them from the asm file!) and pass that to mlds_to_c.m
 		{ ForeignMLDS = mlds(ModuleName, ForeignCode, Imports,
 			list__map(make_public, ForeignDefns)) },
-		mlds_to_c__output_mlds(ForeignMLDS),
+		mlds_to_c__output_mlds(ForeignMLDS, ""),
 		% XXX currently the only foreign code we handle is C;
 		%     see comments above (at the declaration for
 		%     mlds_to_c__compile_to_asm)
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.169
diff -u -d -b -r1.169 modules.m
--- compiler/modules.m	2001/07/06 11:25:30	1.169
+++ compiler/modules.m	2001/07/12 21:58:08
@@ -729,7 +729,8 @@
 		% output files intended for use by the user,
 		% and phony Mmake targets names go in the current directory
 		%
-		{ Ext = ".m"
+		{
+			( Ext = ".m"
 		% executable files
 		; Ext = ""
 		; Ext = ".split"
@@ -744,10 +745,14 @@
 		; Ext = ".split.$(EXT_FOR_SHARED_LIB)"
 		; Ext = ".init"
 		% output files intended for use by the user
+			% (the .h_dump* and .c_dump* MLDS dumps also
+			% fit into this category, but for efficiency,
+			% to keep this as a switch, we deal with them below)
 		; Ext = ".h"
 		; Ext = ".err"
 		; Ext = ".ugly"
 		; Ext = ".hlds_dump"
+			; Ext = ".mlds_dump"
 		; Ext = ".dependency_graph"
 		; Ext = ".order"
 		; Ext = ".rla"
@@ -769,6 +774,12 @@
 		% requires .h.tmp files to be in the same directory as
 		% the .h files
 		; Ext = ".h.tmp"
+			)
+		;
+			% output files intended for use by the user
+			( string__prefix(Ext, ".c_dump")
+			; string__prefix(Ext, ".h_dump")
+			)
 		}
 	->
 		{ FileName0 = BaseName }
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.326
diff -u -d -b -r1.326 options.m
--- compiler/options.m	2001/07/06 14:13:58	1.326
+++ compiler/options.m	2001/07/12 22:03:37
@@ -1850,7 +1850,8 @@
 		"\t(see the Mercury User's Guide for details).",
 		"--dump-mlds <stage number or name>",
 		"\tDump the MLDS (medium level intermediate representation) after",
-		"\tthe specified stage to `<module>.mlds_dump.<num>-<name>'.",
+		"\tthe specified stage to `<module>.mlds_dump.<num>-<name>',",
+		"\t`<module>.c_dump.<num>-<name>' and `<module>.h_dump.<num>-<name>'.",
 		"\tStage numbers range from 1-99.",
 		"\tMultiple dump options accumulate.",
 		"--dump-rl",
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.260
diff -u -d -b -r1.260 user_guide.texi
--- doc/user_guide.texi	2001/07/06 14:14:07	1.260
+++ doc/user_guide.texi	2001/07/12 22:08:25
@@ -3727,7 +3727,7 @@
 @itemx --dump-hlds @var{stage}
 @findex -d
 @findex --dump-hlds
-Dump the HLDS (intermediate representation) after
+Dump the HLDS (a high-level intermediate representation) after
 the specified stage number or stage name to
 @file{@var{module}.hlds_dump. at var{num}- at var{name}}.
 Stage numbers range from 1 to 99; not all stage numbers are valid.
@@ -3763,6 +3763,21 @@
 P - path information,
 T - type and typeclass information,
 U - unify and compare predicates.
+
+ at sp 1
+ at item @var{stage}
+ at itemx --dump-mlds @var{stage}
+ at findex --dump-mlds
+Dump the MLDS (a C-like intermediate representation) after
+the specified stage number or stage name.  The raw form of the
+MLDS is dumped to
+ at file{@var{module}.mlds_dump. at var{num}- at var{name}}.
+The MLDS is also converted to a C source file/header file pair,
+which is dumped to @file{@var{module}.c_dump. at var{num}- at var{name}}
+and @file{@var{module}.h_dump. at var{num}- at var{name}}.
+Stage numbers range from 1 to 99; not all stage numbers are valid.
+The special stage name @samp{all} causes the dumping of all stages.
+Multiple dump options accumulate.
 
 @ifset aditi
 @sp 1

-- 
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