Files
mercury/compiler/commit_gen.m
Zoltan Somogyi ba93a52fe7 This diff changes a few types from being defined as equivalent to a pair
Estimated hours taken: 10
Branches: main

This diff changes a few types from being defined as equivalent to a pair
to being discriminated union types with their own function symbol. This
was motivated by an error message (one of many, but the one that broke
the camel's back) about "-" being used in an ambiguous manner. It will
reduce the number of such messages in the future, and will make compiler
data structures easier to inspect in the debugger.

The most important type changed by far is hlds_goal, whose function symbol
is now "hlds_goal". Second and third in importance are llds.instruction
(function symbol "llds_instr") and prog_item.m's item_and_context (function
symbol "item_and_context"). There are some others as well.

In several places, I rearranged predicates to factor the deconstruction of
goals into hlds_goal_expr and hlds_goal_into out of each clause into a single
point. In many places, I changed variable names that used "Goal" to refer
to just hlds_goal_exprs to use "GoalExpr" instead. I also changed variable
names that used "Item" to refer to item_and_contexts to use "ItemAndContext"
instead. This should make reading such code less confusing.

I renamed some function symbols and predicates to avoid ambiguities.

I only made one algorithmic change (at least intentionally).
In assertion.m, comparing two goals for equality now ignores goal_infos
for all kinds of goals, whereas previously it ignored them for most kinds
of goals, but for shorthand goals it was insisting on them being equal.
This seemed to me to be a bug. Pete, can you confirm this?
2007-01-06 09:23:59 +00:00

110 lines
4.0 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 1997-1998, 2003-2007 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 ll_backend.commit_gen.
:- interface.
:- import_module hlds.code_model.
:- import_module hlds.hlds_goal.
:- import_module ll_backend.code_info.
:- import_module ll_backend.llds.
%---------------------------------------------------------------------------%
:- pred generate_scope(scope_reason::in, add_trail_ops::in, code_model::in,
hlds_goal::in, code_tree::out, code_info::in, code_info::out) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module libs.compiler_util.
:- import_module libs.tree.
:- import_module ll_backend.code_gen.
:- import_module list.
:- import_module maybe.
:- import_module pair.
:- import_module string.
%---------------------------------------------------------------------------%
generate_scope(Reason, AddTrailOps, OuterCodeModel, Goal, Code, !CI) :-
(
Reason = trace_goal(_, MaybeTraceRuntimeCond, _, _, _),
MaybeTraceRuntimeCond = yes(_)
->
% These goals should have been transformed into other forms of goals
% by simplify.m at the end of semantics analysis.
unexpected(this_file, "generate_scope: trace_goal")
;
generate_commit(AddTrailOps, OuterCodeModel, Goal, Code, !CI)
).
:- pred generate_commit(add_trail_ops::in, code_model::in,
hlds_goal::in, code_tree::out, code_info::in, code_info::out) is det.
generate_commit(AddTrailOps, OuterCodeModel, Goal, Code, !CI) :-
Goal = hlds_goal(_, InnerGoalInfo),
goal_info_get_code_model(InnerGoalInfo, InnerCodeModel),
(
OuterCodeModel = model_det,
(
InnerCodeModel = model_det,
code_gen.generate_goal(InnerCodeModel, Goal, Code, !CI)
;
InnerCodeModel = model_semi,
unexpected(this_file, "generate_commit: " ++
"semidet model in det context")
;
InnerCodeModel = model_non,
code_info.prepare_for_det_commit(AddTrailOps, CommitInfo,
PreCommit, !CI),
code_gen.generate_goal(InnerCodeModel, Goal, GoalCode, !CI),
code_info.generate_det_commit(CommitInfo, Commit, !CI),
Code = tree(PreCommit, tree(GoalCode, Commit))
)
;
OuterCodeModel = model_semi,
(
InnerCodeModel = model_det,
code_gen.generate_goal(InnerCodeModel, Goal, Code, !CI)
;
InnerCodeModel = model_semi,
code_gen.generate_goal(InnerCodeModel, Goal, Code, !CI)
;
InnerCodeModel = model_non,
code_info.prepare_for_semi_commit(AddTrailOps, CommitInfo,
PreCommit, !CI),
code_gen.generate_goal(InnerCodeModel, Goal, GoalCode, !CI),
code_info.generate_semi_commit(CommitInfo, Commit, !CI),
Code = tree(PreCommit, tree(GoalCode, Commit))
)
;
OuterCodeModel = model_non,
code_gen.generate_goal(InnerCodeModel, Goal, Code, !CI)
).
%---------------------------------------------------------------------------%
:- func this_file = string.
this_file = "commit_gen.m".
%---------------------------------------------------------------------------%
:- end_module commit_gen.
%---------------------------------------------------------------------------%