Files
mercury/compiler/passes_aux.m
Zoltan Somogyi 2833bfffb7 Divided the old hlds.m into four files:
Estimated hours taken: 10

hlds, hlds_module, hlds_pred, hlds_goal, hlds_data:
	Divided the old hlds.m into four files:

	hlds_module.m defines the data structures that deal with issues
	that are wider than a single predicate. These data structures are
	the module_info structure, dependency_info, the predicate table
	and the shape table.

	hlds_pred.m defined pred_info and proc_info, pred_id and proc_id.

	hlds_goal.m defines hlds__goal, hlds__goal_{expr,info}, and the
	other parts of goal structures.

	hlsd_data.m defines the HLDS types that deal with issues related
	to data and its representation: function symbols, types, insts, modes.
	It also defines the types related to determinism.

	hlds.m is now an empty module. I have not removed it from CVS
	because we may need the name hlds.m again, and CVS does not like
	the reuse of a name once removed.

other modules:
	Import the necessary part of hlds.

det_analysis:
	Define a type that was up to now improperly defined in hlds.m.

prog_io:
	Move the definition of type determinism to hlds_data. This decision
	may need to be revisited when prog_io is broken up.

dnf, lambda:
	Simplify the task of defining predicates.

llds:
	Fix some comments.

mercury_compile:
	If the option -d all is given, dump all HLDS stages.

shape, unused_args:
	Fix formatting.
1996-04-02 12:12:24 +00:00

119 lines
3.5 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 1995 University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
% Author: zs
% This file contains auxiliary routines for the passes of the front and back
% ends of the compiler.
:- module passes_aux.
:- interface.
:- import_module hlds_module, hlds_pred.
:- import_module string, io.
%-----------------------------------------------------------------------------%
:- pred write_progress_message(string::in, pred_id::in, module_info::in,
io__state::di, io__state::uo) is det.
:- pred maybe_report_stats(bool::in, io__state::di, io__state::uo) is det.
:- pred maybe_write_string(bool::input, string::input,
io__state::di, io__state::uo) is det.
:- pred maybe_flush_output(bool::in, io__state::di, io__state::uo) is det.
:- pred report_error(string::in, io__state::di, io__state::uo) is det.
:- pred invoke_system_command(string::in, bool::out,
io__state::di, io__state::uo) is det.
:- pred maybe_report_sizes(module_info::in, io__state::di, io__state::uo)
is det.
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module options, globals, hlds_out.
:- import_module bool, tree234, std_util.
write_progress_message(Message, PredId, ModuleInfo) -->
globals__io_lookup_bool_option(very_verbose, VeryVerbose),
( { VeryVerbose = yes } ->
io__write_string(Message),
hlds_out__write_pred_id(ModuleInfo, PredId),
io__write_string("\n")
;
[]
).
maybe_report_stats(yes) --> io__report_stats.
maybe_report_stats(no) --> [].
maybe_write_string(yes, String) --> io__write_string(String).
maybe_write_string(no, _) --> [].
maybe_flush_output(yes) --> io__flush_output.
maybe_flush_output(no) --> [].
report_error(ErrorMessage) -->
io__write_string("Error: "),
io__write_string(ErrorMessage),
io__write_string("\n"),
io__set_exit_status(1).
invoke_system_command(Command, Succeeded) -->
globals__io_lookup_bool_option(verbose, Verbose),
maybe_write_string(Verbose, "% Invoking system command `"),
maybe_write_string(Verbose, Command),
maybe_write_string(Verbose, "'...\n"),
io__call_system(Command, Result),
( { Result = ok(0) } ->
maybe_write_string(Verbose, "% done.\n"),
{ Succeeded = yes }
; { Result = ok(_) } ->
report_error("system command returned non-zero exit status."),
{ Succeeded = no }
;
report_error("unable to invoke system command."),
{ Succeeded = no }
).
maybe_report_sizes(HLDS) -->
globals__io_lookup_bool_option(statistics, Statistics),
( { Statistics = yes } ->
report_sizes(HLDS)
;
[]
).
:- pred report_sizes(module_info, io__state, io__state).
:- mode report_sizes(in, di, uo) is det.
report_sizes(ModuleInfo) -->
{ module_info_preds(ModuleInfo, Preds) },
tree_stats("Pred table", Preds),
{ module_info_types(ModuleInfo, Types) },
tree_stats("Type table", Types),
{ module_info_ctors(ModuleInfo, Ctors) },
tree_stats("Constructor table", Ctors).
:- pred tree_stats(string, map(_K, _V), io__state, io__state).
:- mode tree_stats(in, in, di, uo) is det.
tree_stats(Description, Tree) -->
{ tree234__count(Tree, Count) },
% { tree234__depth(Tree, Depth) },
io__write_string(Description),
io__write_string(": count = "),
io__write_int(Count),
% io__write_string(", depth = "),
% io__write_int(Depth),
io__write_string("\n").
%-----------------------------------------------------------------------------%