mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 21:35:49 +00:00
Estimated hours taken: 6 Eliminated a lot of the dependencies on the the `code_model' type, and move that type from llds.m into a new module `code_model'. The aim of this change is to improve the modularity of the compiler by reducing the number of places in the compiler front-end that depend on back-end concepts and the number of places in the MLDS back-end which depend on the LLDS. compiler/code_model.m: New module. Contains the code_model type and associated procedures. compiler/llds.m: Move the code_model type into code_model.m. compiler/hlds_goal.m: Move the goal_info_get_code_model procedure into code_model.m, to avoid having the HLDS modules import code_model. compiler/hlds_out.m: Delete `hlds_out__write_code_model', since it wasn't being used. compiler/hlds_pred.m: Move the proc_info_interface_code_model procedure into code_model.m, to avoid having the HLDS modules import code_model. compiler/goal_path.m: When computing the `maybe_cut' field for `some' goals, compute it by comparing the determinism rather than by comparing the goal_infos. compiler/unique_modes.m: Use determinism and test for soln_count = at_most_many rather than using code_model and testing for model_non. compiler/inlining.m: Test for determinism nondet/multi rather than testing for code_model model_non. compiler/hlds_pred.m: compiler/det_report.m: Change valid_code_model_for_eval_method, which succeeded unless the eval_method was minimal_model and the code_model was model_det, to valid_determinism_for_eval_method, which succeeds unless the eval_method is minimal_model and the determinism cannot fail. As well as avoiding a dependency on code_model in the HLDS modules, this also fixes a bug where det_report could give misleading error messages, saying that `multi' was a valid determinism for `minimal_model' predicates, when in fact the compiler will always report a determinism error if you declare a `minimal_model' predicate with determinism `multi'. (Actually the code in which this bug occurs is in fact unreachable, but this is no doubt also a bug... I'll address that one in a separate change.) compiler/lookup_switch.m: Simplify the code a bit by using globals__lookup_*_option rather than globals__get_option and then getopt__lookup_option. compiler/*.m: Add `import_module' declarations for `code_model', and in some cases remove `import_module' declarations for `llds'.
68 lines
2.1 KiB
Mathematica
68 lines
2.1 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-1998 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: commit_gen.m
|
|
%
|
|
% Main authors: conway, fjh, zs.
|
|
%
|
|
% The predicates of this module generate code for performing commits.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module commit_gen.
|
|
|
|
:- interface.
|
|
|
|
:- import_module hlds_goal, code_model, llds, code_info.
|
|
|
|
:- pred commit_gen__generate_commit(code_model::in, hlds_goal::in,
|
|
code_tree::out, code_info::in, code_info::out) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module code_gen, tree.
|
|
:- import_module std_util, require.
|
|
|
|
commit_gen__generate_commit(OuterCodeModel, Goal, Code) -->
|
|
{ Goal = _ - InnerGoalInfo },
|
|
{ goal_info_get_code_model(InnerGoalInfo, InnerCodeModel) },
|
|
(
|
|
{ OuterCodeModel = model_det },
|
|
(
|
|
{ InnerCodeModel = model_det },
|
|
code_gen__generate_goal(InnerCodeModel, Goal, Code)
|
|
;
|
|
{ InnerCodeModel = model_semi },
|
|
{ error("semidet model in det context") }
|
|
;
|
|
{ InnerCodeModel = model_non },
|
|
code_info__prepare_for_det_commit(CommitInfo,
|
|
PreCommit),
|
|
code_gen__generate_goal(InnerCodeModel, Goal, GoalCode),
|
|
code_info__generate_det_commit(CommitInfo, Commit),
|
|
{ Code = tree(PreCommit, tree(GoalCode, Commit)) }
|
|
)
|
|
;
|
|
{ OuterCodeModel = model_semi },
|
|
(
|
|
{ InnerCodeModel = model_det },
|
|
code_gen__generate_goal(InnerCodeModel, Goal, Code)
|
|
;
|
|
{ InnerCodeModel = model_semi },
|
|
code_gen__generate_goal(InnerCodeModel, Goal, Code)
|
|
;
|
|
{ InnerCodeModel = model_non },
|
|
code_info__prepare_for_semi_commit(CommitInfo,
|
|
PreCommit),
|
|
code_gen__generate_goal(InnerCodeModel, Goal, GoalCode),
|
|
code_info__generate_semi_commit(CommitInfo, Commit),
|
|
{ Code = tree(PreCommit, tree(GoalCode, Commit)) }
|
|
)
|
|
;
|
|
{ OuterCodeModel = model_non },
|
|
code_gen__generate_goal(InnerCodeModel, Goal, Code)
|
|
).
|