mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 13:23:53 +00:00
Estimated hours taken: 6 Branches: main This diff changes modes.m, unique_modes.m and mode_info.m to make them easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/modes.m: compiler/unique_modes.m: compiler/mode_info.m: Convert these modules to our current coding standards. Use state variable notation when appropriate, reordering arguments as necessary. Delete predicates whose only purpose was to ease programming with DCGs. Remove the IO state from the mode_info structure, and pass it separately to the (relatively few) predicates that need it. This avoids using complicated (and as yet unsupported) modes or lying to the compiler (we used to do the latter), and we are no longer forced into that choice by being limited to a single hidden (DCG) variable. Use more expressive variable names and factor out code as appropriate. compiler/*.m: Conform to the changes in the above two modules.
131 lines
4.1 KiB
Mathematica
131 lines
4.1 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1996-1997, 2003 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__inst.
|
|
:- import_module parse_tree__mercury_to_mercury.
|
|
:- import_module parse_tree__prog_data.
|
|
|
|
:- 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).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|