Files
mercury/compiler/commit_gen.m
Zoltan Somogyi 1373003785 Delete the old tree.m module (which did a small subset of what cords now do),
Estimated hours taken: 6
Branches: main

Delete the old tree.m module (which did a small subset of what cords now do),
and switch to using cords instead. This is more standard, as well as very
slightly more efficient, because with cords, e.g. concatenating ten code
fragments of which eight are empty doesn't allocate ten cons cells.
My measurements show a 0.1% reduction in executable size and a 0.3% reduction
in compilation time. Both of those are in the noise; the main reason for the
change is more convenient coding.

compiler/tree.m:
	Remove this module.

compiler/libs.m:
	Remove the inclusion of tree.m.

compiler/notes/compiler_design.html:
	Remove the description of tree.m.

compiler/bytecode.m:
	Switch to using cords to represent code in the bytecode backend.

compiler/llds.m:
	Switch to using cords to represent code in the LLDS backend.

compiler/mlds_to_il.m:
	Switch to using cords to represent IL code being built.

compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/commit_gen.m:
compiler/dense_switch.m:
compiler/disj_gen.m:
compiler/ite_gen.m:
compiler/lookup_switch.m:
compiler/lookup_util.m:
compiler/middle_rec.m:
compiler/par_conj_gen.m:
compiler/pragma_c_gen.m:
compiler/proc_gen.m:
compiler/string_switch.m:
compiler/switch_case.m:
compiler/switch_gen.m:
compiler/tag_switch.m:
compiler/trace_gen.m:
compiler/unify_gen.m:
compiler/var_locn.m:
	Conform to the changes above.

library/cord.m:
	Add a predicate form of map.
2009-01-06 03:56:53 +00:00

122 lines
4.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 1997-1998, 2003-2007, 2009 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.
:- import_module parse_tree.prog_data.
:- import_module set.
%---------------------------------------------------------------------------%
:- pred generate_scope(scope_reason::in, code_model::in, hlds_goal_info::in,
set(prog_var)::in, hlds_goal::in, llds_code::out,
code_info::in, code_info::out) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module libs.compiler_util.
:- import_module ll_backend.code_gen.
:- import_module cord.
:- import_module list.
:- import_module maybe.
:- import_module pair.
:- import_module string.
%---------------------------------------------------------------------------%
generate_scope(Reason, OuterCodeModel, OuterGoalInfo,
ForwardLiveVarsBeforeGoal, 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 semantic analysis.
unexpected(this_file, "generate_scope: trace_goal")
;
generate_commit(OuterCodeModel, OuterGoalInfo,
ForwardLiveVarsBeforeGoal, Goal, Code, !CI)
).
:- pred generate_commit(code_model::in, hlds_goal_info::in, set(prog_var)::in,
hlds_goal::in, llds_code::out, code_info::in, code_info::out) is det.
generate_commit(OuterCodeModel, OuterGoalInfo, ForwardLiveVarsBeforeGoal,
Goal, Code, !CI) :-
AddTrailOps = should_add_trail_ops(!.CI, OuterGoalInfo),
AddRegionOps = should_add_region_ops(!.CI, OuterGoalInfo),
Goal = hlds_goal(_, InnerGoalInfo),
InnerCodeModel = goal_info_get_code_model(InnerGoalInfo),
(
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,
prepare_for_det_commit(AddTrailOps, AddRegionOps,
ForwardLiveVarsBeforeGoal, InnerGoalInfo, CommitInfo,
PreCommit, !CI),
code_gen.generate_goal(InnerCodeModel, Goal, GoalCode, !CI),
generate_det_commit(CommitInfo, Commit, !CI),
Code = PreCommit ++ 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,
prepare_for_semi_commit(AddTrailOps, AddRegionOps,
ForwardLiveVarsBeforeGoal, InnerGoalInfo, CommitInfo,
PreCommit, !CI),
code_gen.generate_goal(InnerCodeModel, Goal, GoalCode, !CI),
generate_semi_commit(CommitInfo, Commit, !CI),
Code = PreCommit ++ 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.
%---------------------------------------------------------------------------%