[m-rev.] for review: --dump-hlds-pred-id and --debug-opt-pred-id

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri May 9 20:02:28 AEST 2003


Add two new options that can help reduce the amount of clutter you have to
wade through when debugging.

doc/user_guide.texi:
compiler/options.m:
	Add two new options, --dump-hlds-pred-id and --debug-opt-pred-id.
	Both take an integer argument, and treat it as a pred_id.
	--dump-hlds-pred-id restricts all HLDS dumps to the specified pred,
	and --debug-opt-pred-id similarly restricts the output of --debug-opt
	to the specified pred.

compiler/hlds_out.m:
compiler/handle_options.m:
	Implement --dump-hlds-pred-id.

compiler/optimize.m:
	Implement --debug-opt-pred-id.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.183
diff -u -b -r1.183 handle_options.m
--- compiler/handle_options.m	8 May 2003 03:35:16 -0000	1.183
+++ compiler/handle_options.m	9 May 2003 09:47:48 -0000
@@ -630,7 +630,18 @@
 			% dump options do not print these annotations.
 		globals__io_lookup_string_option(dump_hlds_options,
 			DumpOptions0),
-		{ string__append(DumpOptions0, AllDumpOptions, DumpOptions) },
+		{ string__append(DumpOptions0, AllDumpOptions, DumpOptions1) },
+		globals__io_set_option(dump_hlds_options, string(DumpOptions1))
+	;
+		[]
+	),
+
+	globals__io_lookup_int_option(dump_hlds_pred_id, DumpHLDSPredId),
+	( { DumpHLDSPredId >= 0 } ->
+		globals__io_lookup_string_option(dump_hlds_options,
+			DumpOptions2),
+		{ string__replace_all(DumpOptions2, "M", "", DumpOptions3) },
+		{ string__replace_all(DumpOptions3, "T", "", DumpOptions) },
 		globals__io_set_option(dump_hlds_options, string(DumpOptions))
 	;
 		[]
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.305
diff -u -b -r1.305 hlds_out.m
--- compiler/hlds_out.m	28 Apr 2003 11:56:48 -0000	1.305
+++ compiler/hlds_out.m	9 May 2003 09:12:58 -0000
@@ -779,50 +779,53 @@
 	io__write_string("%-------- Predicates --------\n\n"),
 	hlds_out__write_indent(Indent),
 	{ map__keys(PredTable, PredIds) },
-	hlds_out__write_preds_2(Indent, ModuleInfo, PredIds, PredTable).
+	list__foldl(hlds_out__maybe_write_pred(Indent, ModuleInfo, PredTable),
+		PredIds).
 
-:- pred hlds_out__write_preds_2(int, module_info, list(pred_id), pred_table,
-	io__state, io__state).
-:- mode hlds_out__write_preds_2(in, in, in, in, di, uo) is det.
+:- pred hlds_out__maybe_write_pred(int::in, module_info::in, pred_table::in,
+	pred_id::in, io__state::di, io__state::uo) is det.
 
-hlds_out__write_preds_2(Indent, ModuleInfo, PredIds0, PredTable) -->
-        globals__io_lookup_string_option(dump_hlds_options, Verbose),
+hlds_out__maybe_write_pred(Indent, ModuleInfo, PredTable, PredId, !IO) :-
+        globals__io_lookup_string_option(dump_hlds_options, Verbose, !IO),
+	globals__io_lookup_int_option(dump_hlds_pred_id, DumpPredId, !IO),
+	pred_id_to_int(PredId, PredIdInt),
+	map__lookup(PredTable, PredId, PredInfo),
 	(
-		{ PredIds0 = [PredId|PredIds] }
+		% If the user requested one predicate/function to be dumped,
+		% we dump it even if the condition of the nested if-then-else
+		% says it shouldn't be dumped, and we don't dump anything else.
+		DumpPredId > 0
 	->
-		{ map__lookup(PredTable, PredId, PredInfo) },
+		( PredIdInt = DumpPredId ->
+			hlds_out__write_pred(Indent, ModuleInfo, PredId, PredInfo, !IO)
+		;
+			true
+		)
+	;
 		(
-			{ \+ string__contains_char(Verbose, 'I') },
-			{ pred_info_is_imported(PredInfo) }
-		->
-			[]
+			\+ string__contains_char(Verbose, 'I'),
+			pred_info_is_imported(PredInfo)
 		;
-			% for pseudo-imported predicates (i.e. unification
+			% For pseudo-imported predicates (i.e. unification
 			% preds), only print them if we are using a local
-			% mode for them
-			{ \+ string__contains_char(Verbose, 'I') },
-			{ pred_info_is_pseudo_imported(PredInfo) },
-			{ pred_info_procids(PredInfo, ProcIds) },
-			{ hlds_pred__in_in_unification_proc_id(ProcId) },
-			{ ProcIds = [ProcId] }
-		->
-			[]
+			% mode for them.
+			\+ string__contains_char(Verbose, 'I'),
+			pred_info_is_pseudo_imported(PredInfo),
+			pred_info_procids(PredInfo, ProcIds),
+			hlds_pred__in_in_unification_proc_id(ProcId),
+			ProcIds = [ProcId]
 		;
 			% We dump unification and other compiler-generated
 			% special predicates if suboption 'U' is on. We don't
 			% need that information to understand how the program
 			% has been transformed.
-			{ \+ string__contains_char(Verbose, 'U') },
-			{ is_unify_or_compare_pred(PredInfo) }
+			\+ string__contains_char(Verbose, 'U'),
+			is_unify_or_compare_pred(PredInfo)
+		)
 		->
-			[]
-		;
-			hlds_out__write_pred(Indent, ModuleInfo, PredId,
-				PredInfo)
-		),
-		hlds_out__write_preds_2(Indent, ModuleInfo, PredIds, PredTable)
+		true
 	;
-		[]
+		hlds_out__write_pred(Indent, ModuleInfo, PredId, PredInfo, !IO)
 	).
 
 :- pred hlds_out__write_pred(int, module_info, pred_id, pred_info,
Index: compiler/optimize.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/optimize.m,v
retrieving revision 1.37
diff -u -b -r1.37 optimize.m
--- compiler/optimize.m	9 May 2003 05:51:52 -0000	1.37
+++ compiler/optimize.m	9 May 2003 09:14:44 -0000
@@ -95,37 +95,39 @@
 	io__state::di, io__state::uo) is det.
 
 optimize__init_opt_debug_info(Name, Arity, PredProcId, Instrs0, Counter,
-		OptDebugInfo) -->
-	globals__io_lookup_bool_option(debug_opt, DebugOpt),
+		OptDebugInfo, !IO) :-
+	globals__io_lookup_bool_option(debug_opt, DebugOpt, !IO),
+	globals__io_lookup_int_option(debug_opt_pred_id, DebugOptPredId, !IO),
+	PredProcId = proc(PredId, ProcId),
+	pred_id_to_int(PredId, PredIdInt),
+	proc_id_to_int(ProcId, ProcIdInt),
 	(
-		{ DebugOpt = yes },
-		{ MangledName = name_mangle(Name) },
-		{ PredProcId = proc(PredId, ProcId) },
-		{ pred_id_to_int(PredId, PredIdInt) },
-		{ proc_id_to_int(ProcId, ProcIdInt) },
-		{ string__int_to_string(Arity, ArityStr) },
-		{ string__int_to_string(PredIdInt, PredIdStr) },
-		{ string__int_to_string(ProcIdInt, ProcIdStr) },
-		{ string__append_list([MangledName, "_", ArityStr,
-			".pred", PredIdStr, ".proc", ProcIdStr], BaseName) },
-		{ OptDebugInfo = opt_debug_info(BaseName, 0) },
+		DebugOpt = yes,
+		( DebugOptPredId > 0 => DebugOptPredId = PredIdInt )
+	->
+		MangledName = name_mangle(Name),
+		string__int_to_string(Arity, ArityStr),
+		string__int_to_string(PredIdInt, PredIdStr),
+		string__int_to_string(ProcIdInt, ProcIdStr),
+		string__append_list([MangledName, "_", ArityStr,
+			".pred", PredIdStr, ".proc", ProcIdStr], BaseName),
+		OptDebugInfo = opt_debug_info(BaseName, 0),
 
-		{ string__append_list([BaseName, ".opt0"], FileName) },
-		io__open_output(FileName, Res),
-		( { Res = ok(FileStream) } ->
-			io__set_output_stream(FileStream, OutputStream),
-			{ counter__allocate(NextLabel, Counter, _) },
-			opt_debug__msg(yes, NextLabel, "before optimization"),
-			opt_debug__dump_instrs(yes, Instrs0),
-			io__set_output_stream(OutputStream, _),
-			io__close_output(FileStream)
+		string__append_list([BaseName, ".opt0"], FileName),
+		io__open_output(FileName, Res, !IO),
+		( Res = ok(FileStream) ->
+			io__set_output_stream(FileStream, OutputStream, !IO),
+			counter__allocate(NextLabel, Counter, _),
+			opt_debug__msg(yes, NextLabel, "before optimization", !IO),
+			opt_debug__dump_instrs(yes, Instrs0, !IO),
+			io__set_output_stream(OutputStream, _, !IO),
+			io__close_output(FileStream, !IO)
 		;
-			{ string__append("cannot open ", FileName, ErrorMsg) },
-			{ error(ErrorMsg) }
+			string__append("cannot open ", FileName, ErrorMsg),
+			error(ErrorMsg)
 		)
 	;
-		{ DebugOpt = no },
-		{ OptDebugInfo = no_opt_debug_info }
+		OptDebugInfo = no_opt_debug_info
 	).
 
 :- pred optimize__maybe_opt_debug(list(instruction)::in, counter::in,
Index: compiler/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.410
diff -u -b -r1.410 options.m
--- compiler/options.m	7 May 2003 00:50:21 -0000	1.410
+++ compiler/options.m	9 May 2003 09:15:37 -0000
@@ -108,6 +108,7 @@
 		;	debug_modes
 		;	debug_det
 		;	debug_opt
+		;	debug_opt_pred_id
 		;	debug_pd	% pd = partial deduction/deforestation
 		;	debug_rl_gen
 		;	debug_rl_opt
@@ -159,6 +160,7 @@
 		;	auto_comments
 		;	show_dependency_graph
 		;	dump_hlds
+		;	dump_hlds_pred_id
 		;	dump_hlds_alias
 		;	dump_hlds_options
 		;	dump_mlds
@@ -738,6 +740,7 @@
 	debug_modes		- 	bool(no),
 	debug_det		- 	bool(no),
 	debug_opt		- 	bool(no),
+	debug_opt_pred_id	- 	int(-1),
 	debug_pd		-	bool(no),
 	debug_rl_gen		-	bool(no),
 	debug_rl_opt		-	bool(no),
@@ -789,6 +792,7 @@
 	auto_comments		-	bool(no),
 	show_dependency_graph	-	bool(no),
 	dump_hlds		-	accumulating([]),
+	dump_hlds_pred_id	-	int(-1),
 	dump_hlds_alias		-	string(""),
 	dump_hlds_options	-	string(""),
 	dump_mlds		-	accumulating([]),
@@ -1345,6 +1349,7 @@
 long_option("debug-determinism",	debug_det).
 long_option("debug-det",		debug_det).
 long_option("debug-opt",		debug_opt).
+long_option("debug-opt-pred-id",	debug_opt_pred_id).
 long_option("debug-pd",			debug_pd).
 long_option("debug-rl-gen",		debug_rl_gen).
 long_option("debug-rl-opt",		debug_rl_opt).
@@ -1415,6 +1420,7 @@
 long_option("show-dependency-graph",	show_dependency_graph).
 long_option("dump-hlds",		dump_hlds).
 long_option("hlds-dump",		dump_hlds).
+long_option("dump-hlds-pred-id",	dump_hlds_pred_id).
 long_option("dump-hlds-alias",		dump_hlds_alias).
 long_option("dump-hlds-options",	dump_hlds_options).
 long_option("dump-mlds",		dump_mlds).
@@ -2533,6 +2539,9 @@
 		"\tOutput detailed debugging traces of determinism analysis.",
 		"--debug-opt",
 		"\tOutput detailed debugging traces of the optimization process.",
+		"--debug-opt-pred-id <n>",
+		"\tOutput detailed debugging traces of the optimization process",
+		"\tonly for the predicate/function with the specified pred id.",
 		"--debug-pd",
 		"\tOutput detailed debugging traces of the partial",
 		"\tdeduction and deforestation process.",
@@ -2714,6 +2723,9 @@
 		"\tthe specified stage to `<module>.hlds_dump.<num>-<name>'.",
 		"\tStage numbers range from 1-99.",
 		"\tMultiple dump options accumulate.",
+		"--dump-hlds-pred-id <n>",
+		"\tDump the HLDS only of the predicate/function with the given",
+		"\tpred id.",
 % This option is for developers only
 %		"-D, --dump-hlds-alias <dump-alias>",
 %		"\tWith `--dump-hlds', include extra detail in the dump.",
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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