mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 13:55:07 +00:00
Estimated hours taken: 38 Makes instmap and instmap_delta into ADTs. compiler/code_gen.m: compiler/code_info.m: compiler/cse_detection.m: compiler/det_analysis.m: compiler/dnf.m: compiler/goal_util.m: compiler/higher_order.m: compiler/hlds_goal.m: compiler/hlds_out.m: compiler/hlds_pred.m: compiler/live_vars.m: compiler/liveness.m: compiler/lookup_switch.m: compiler/mode_debug.m: compiler/mode_info.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/polymorphism.m: compiler/simplify.m: compiler/store_alloc.m: compiler/switch_detection.m: compiler/transform.m: compiler/uniq_modes.m: compiler/unused_args.m: Miscellaneous minor changes to use the new instmap.m compiler/constraint.m: Removed unnecessary duplication of code in constraint__checkpoint/4 and constraint__no_output_vars/2. compiler/det_util.m: Changed no_output_vars/4 to det_no_output_vars/4, moved body of code to instmap.m. compiler/instmap.m: Added abstract types instmap/0, instmap_delta/0. Added predicates: instmap__init_reachable/1, instmap__init_unreachable/1, instmap_delta_init_reachable/1, instmap_delta_init_unreachable/1, instmap__is_reachable/1, instmap__is_unreachable/1, instmap_delta_is_reachable/1, instmap_delta_is_unreachable/1, instmap__from_assoc_list/2, instmap_delta_from_assoc_list/2, instmap__vars/2, instmap__vars_list/2, instmap_delta_changed_vars/2, instmap_delta_lookup_var/3, instmap__set/3, instmap_delta_insert/4, instmap_delta_apply_instmap_delta/3, instmap_delta_restrict/3, instmap_delta_delete_vars/3, instmap__no_output_vars/4, instmap_delta_apply_sub/4, instmap__to_assoc_list/2, instmap_delta_to_assoc_list/2. Renamed predicates: instmap__lookup_var/3 (was instmap_lookup_var/3) instmap__lookup_vars/3 (was instmap_lookup_vars/3) instmap__apply_instmap_delta/3 (was apply_instmap_delta/3) instmap__merge/5 (was instmap_merge/5) instmap__restrict/3 (was instmap_restrict/3) Moved predicates: merge_instmap_delta/5 (from mode_util.m) Removed predicates: instmapping_lookup_var/3 compiler/mode_util.m: Moved merge_instmap_delta/5 to instmap.m
79 lines
2.9 KiB
Mathematica
79 lines
2.9 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.
|
|
%-----------------------------------------------------------------------------%
|
|
% File: transform.m
|
|
% Main author: bromage.
|
|
%
|
|
% This module defines the primitive operations that may be performed
|
|
% on a logic program. These include:
|
|
%
|
|
% - unfold (NYI)
|
|
% Replaces a goal with its possible expansions.
|
|
%
|
|
% - fold (NYI)
|
|
% Opposite of unfold (not surprisingly).
|
|
%
|
|
% - definition (NYI)
|
|
% Define a new predicate with a given goal.
|
|
%
|
|
% - identity (NYI)
|
|
% Apply an identity (such as the associative law for
|
|
% addition) to a goal.
|
|
%
|
|
% These operations form the basis of most high-level transformations.
|
|
%
|
|
% Also included is a conjunction rescheduler. Useful just in case
|
|
% your transformer upset the ordering in a conjunction.
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module transform.
|
|
:- interface.
|
|
:- import_module hlds_goal, llds, mode_info.
|
|
|
|
%:- pred unfold__in_proc(pred_id, proc_id, hlds__goal_expr,
|
|
% mode_info, mode_info).
|
|
%:- mode unfold__in_proc(in, in, out, mode_info_di, module_info_uo) is det.
|
|
|
|
:- pred transform__reschedule_conj(list(hlds__goal), list(hlds__goal),
|
|
mode_info, mode_info).
|
|
:- mode transform__reschedule_conj(in, out, mode_info_di, mode_info_uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
:- import_module list, map, set, std_util.
|
|
:- import_module mode_util, delay_info, term, require.
|
|
:- import_module varset, code_aux, prog_data, instmap.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% unfold__in_proc(
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
transform__reschedule_conj([], []) --> [].
|
|
transform__reschedule_conj([Goal0 | Goals0], Goals) -->
|
|
=(ModeInfo0),
|
|
{ mode_info_get_instmap(ModeInfo0, InstMap0) },
|
|
{ mode_info_get_delay_info(ModeInfo0, DelayInfo0) },
|
|
|
|
{ delay_info__wakeup_goals(DelayInfo0, WokenGoals, DelayInfo1) },
|
|
mode_info_set_delay_info(DelayInfo1),
|
|
( { WokenGoals \= [] } ->
|
|
{ list__append(WokenGoals, [Goal0 | Goals0], Goals1) },
|
|
transform__reschedule_conj(Goals1, Goals)
|
|
;
|
|
{ Goal0 = _Goal0Goal - Goal0Info },
|
|
{ goal_info_get_instmap_delta(Goal0Info, InstMapDelta) },
|
|
{ instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap1) },
|
|
mode_info_set_instmap(InstMap1),
|
|
transform__reschedule_conj(Goals0, Goals1),
|
|
{ Goals = [Goal0 | Goals1] }
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|