Files
mercury/compiler/mode_debug.m
Zoltan Somogyi 885fd4a387 Remove almost all dependencies by the modules of parse_tree.m on the modules
Estimated hours taken: 12
Branches: main

Remove almost all dependencies by the modules of parse_tree.m on the modules
of hlds.m. The only such dependencies remaining now are on type_util.m.

compiler/hlds_data.m:
compiler/prog_data.m:
	Move the cons_id type from hlds_data to prog_data, since several parts
	of the parse tree data structure depend on it (particularly insts).
	Remove the need to import HLDS modules in prog_data.m by making the
	cons_ids that refer to procedure ids refer to them via a new type
	that contains shrouded pred_ids and proc_ids. Since pred_ids and
	proc_ids are abstract types in hlds_data, add predicates to hlds_data
	to shroud and unshroud them.

	Also move some other types, e.g. mode_id and class_id, from hlds_data
	to prog_data.

compiler/hlds_data.m:
compiler/prog_util.m:
	Move predicates for manipulating cons_ids from hlds_data to prog_util.

compiler/inst.m:
compiler/prog_data.m:
	Move the contents of inst.m to prog_data.m, since that is where it
	belongs, and since doing so eliminates a circular dependency.
	The separation doesn't serve any purpose any more, since we don't
	need to import hlds_data.m anymore to get access to the cons_id type.

compiler/mode_util.m:
compiler/prog_mode.m:
compiler/parse_tree.m:
	Move the predicates in mode_util that don't depend on the HLDS to a new
	module prog_mode, which is part of parse_tree.m.

compiler/notes/compiler_design.m:
	Mention prog_mode.m, and delete the mention of inst.m.

compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
	Move the predicates that depend on HLDS out of mercury_to_mercury.m
	to hlds_out.m. Export from mercury_to_mercury.m the predicates needed
	by the moved predicates.

compiler/hlds_out.m:
compiler/prog_out.m:
	Move predicates for printing parts of the parse tree out of hlds_out.m
	to prog_out.m, since mercury_to_mercury.m needs to use them.

compiler/purity.m:
compiler/prog_out.m:
	Move predicates for printing purities from purity.m, which is part
	of check_hlds.m, to prog_out.m, since mercury_to_mercury.m needs to use
	them.

compiler/passes_aux.m:
compiler/prog_out.m:
	Move some utility predicates (e.g. for printing progress messages) from
	passes_aux.m to prog_out.m, since some predicates in submodules of
	parse_tree.m need to use them.

compiler/foreign.m:
compiler/prog_data.m:
	Move some types from foreign.m to prog_data.m to allow the elimination
	of some dependencies on foreign.m from submodules of parse_tree.m.

compiler/*.m:
	Conform to the changes above, mostly by updating lists of imported
	modules and module qualifications. In some cases, also do some local
	cleanups such as converting predicate declarations to predmode syntax
	and fixing white space.
2004-06-14 04:17:03 +00:00

131 lines
4.1 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 1996-1997, 2003-2004 The 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.
%-----------------------------------------------------------------------------%
%
% File: mode_debug.m.
% Main author: fjh.
%
% This module contains code for tracing the actions of the mode checker.
%
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- module check_hlds__mode_debug.
:- interface.
:- import_module check_hlds__mode_info.
:- import_module io.
% Print a debugging message which includes the port, message string,
% and the current instmap (but only if `--debug-modes' was enabled).
%
:- pred mode_checkpoint(port::in, string::in, mode_info::in, mode_info::out,
io::di, io::uo) is det.
:- type port
---> enter
; exit
; wakeup.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module check_hlds__modes.
:- import_module hlds__hlds_goal.
:- import_module hlds__hlds_module.
:- import_module hlds__instmap.
:- import_module hlds__passes_aux.
:- import_module libs__globals.
:- import_module libs__options.
:- import_module parse_tree__mercury_to_mercury.
:- import_module parse_tree__prog_data.
:- import_module parse_tree__prog_out.
:- import_module std_util, list, assoc_list, bool, map.
:- import_module term, varset.
%-----------------------------------------------------------------------------%
% This code is used to trace the actions of the mode checker.
mode_checkpoint(Port, Msg, !ModeInfo, !IO) :-
mode_info_get_module_info(!.ModeInfo, ModuleInfo),
module_info_globals(ModuleInfo, Globals),
globals__lookup_bool_option(Globals, debug_modes, DoCheckPoint),
( DoCheckPoint = yes ->
mode_checkpoint_2(Port, Msg, !ModeInfo, !IO)
;
true
).
:- pred mode_checkpoint_2(port::in, string::in, mode_info::in, mode_info::out,
io__state::di, io__state::uo) is det.
mode_checkpoint_2(Port, Msg, !ModeInfo, !IO) :-
mode_info_get_last_checkpoint_insts(!.ModeInfo, OldInsts),
mode_info_get_errors(!.ModeInfo, Errors),
( Port = enter ->
io__write_string("Enter ", !IO),
Detail = yes
; Port = wakeup ->
io__write_string("Wake ", !IO),
Detail = no
; Errors = [] ->
io__write_string("Exit ", !IO),
Detail = yes
;
io__write_string("Delay ", !IO),
Detail = no
),
io__write_string(Msg, !IO),
( Detail = yes ->
io__write_string(":\n", !IO),
globals__io_lookup_bool_option(statistics, Statistics, !IO),
maybe_report_stats(Statistics, !IO),
maybe_flush_output(Statistics, !IO),
mode_info_get_instmap(!.ModeInfo, InstMap),
( instmap__is_reachable(InstMap) ->
instmap__to_assoc_list(InstMap, NewInsts),
mode_info_get_varset(!.ModeInfo, VarSet),
mode_info_get_instvarset(!.ModeInfo, InstVarSet),
write_var_insts(NewInsts, OldInsts, VarSet, InstVarSet,
!IO)
;
NewInsts = [],
io__write_string("\tUnreachable\n", !IO)
),
mode_info_set_last_checkpoint_insts(NewInsts, !ModeInfo)
;
true
),
io__write_string("\n", !IO),
io__flush_output(!IO).
:- pred write_var_insts(assoc_list(prog_var, inst)::in,
assoc_list(prog_var, inst)::in, prog_varset::in, inst_varset::in,
io__state::di, io__state::uo) is det.
write_var_insts([], _, _, _, !IO).
write_var_insts([Var - Inst | VarInsts], OldInsts, VarSet, InstVarSet, !IO) :-
io__write_string("\t", !IO),
mercury_output_var(Var, VarSet, no, !IO),
io__write_string(" ::", !IO),
(
assoc_list__search(OldInsts, Var, OldInst),
Inst = OldInst
->
io__write_string(" unchanged\n", !IO)
;
io__write_string("\n", !IO),
mercury_output_structured_inst(Inst, 2, InstVarSet, !IO)
),
write_var_insts(VarInsts, OldInsts, VarSet, InstVarSet, !IO).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%