Files
mercury/compiler/ml_disj_gen.m
Zoltan Somogyi ea4f95a7ed Use var_tables in lco.m, and when dumping goals.
Since this is the first converted module that dumps out goals when
debugging trace flags are enabled, this required generalizing the code
that does that, to take either varsets or var_tables as a means of
specifying the names of variables. We do this via a new type,
var_name_source, which contains either a varset or a var_table.

Almost all of this diff is there to implement this generalization.
A large part of it affects code in the parse_tree package that we use
to write out the parts of HLDS goals that are defined by types defined
in that package. Since we want to avoid making any part of the parse_tree
package dependent on the hlds package, this required defining the
var_name_source type in the parse_tree package, which in turn requires
var_table.m to be in that same package.

compiler/lco.m:
    Convert this module to use var_tables instead of varsets and vartypes.

compiler/var_table.m:
    Move this module from the hlds package to the parse_tree package.

    To make this, possible, move the parts that required access to the HLDS
    to hlds_pred.m, from where it was usually invoked.

    Export some utility predicates to allow the moved code to work
    in hlds_pred.m without access to the actual definition of the
    var_table type.

    Define the var_name_source type.

    Add some utility functions for use by code writing out variable names.

compiler/hlds_pred.m:
    Add the code moved from var_table.m.

compiler/vartypes.m:
    Move this module from the hlds package to the parse_tree package,
    for symmetry with var_table.m. It did not depend on being in hlds
    in any way.

compiler/hlds.m:
compiler/parse_tree.m:
    Move vartypes.m and var_table.m from the hlds package
    to the parse_tree package.

compiler/hlds_out_goal.m:
    Change all the predicates in this module to take a var_name_source
    instead of a prog_varset.

    Fix some comments.

compiler/hlds_out_util.m:
    Change some of the predicates in this module (those called from
    hlds_out_goal.m) to take a var_name_source instead of a prog_varset.

compiler/parse_tree_out_term.m:
    Provide variants of some existing predicates and functions that take
    var_name_sources instead of varsets. The code of the copies
    duplicates the logic of the originals, though I hope that this
    duplication can be done away with at the end of the transition.
    (The best solution would be to use a typeclass with methods
    that convert vars to their names, but we would want to ensure
    that the compiler can specialize all the affected predicates
    and functions to the two instances of this typeclass, which is
    something that we cannot do yet. In the meantime, the lack of
    any generalization in the old versions preserves their performance.)

tools/sort_imports:
tools/filter_sort_imports:
    A new tool that automatically sorts any occurrences of consecutive
    ":- import_module" declarations in the named files. The sorting is done
    in filter_sort_imports; sort_imports loops over the named files.

    After automatically replacing all occurrences of hlds.{vartypes,var_table}
    in import_module declarations with their parse_tree versions, the updated
    import_module declarations were usually out of order with respect to
    their neighbours. I used this script to fix that, and some earlier
    out-of-order imports.

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_heap_ops.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_trail_ops.m:
compiler/analysis.m:
compiler/arg_info.m:
compiler/build_mode_constraints.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/check_promise.m:
compiler/closure_analysis.m:
compiler/closure_gen.m:
compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/common.m:
compiler/compile_target_code.m:
compiler/complexity.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/continuation_info.m:
compiler/convert_parse_tree.m:
compiler/coverage_profiling.m:
compiler/cse_detection.m:
compiler/ctgc.datastruct.m:
compiler/ctgc.util.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/direct_arg_in_out.m:
compiler/disj_gen.m:
compiler/distance_granularity.m:
compiler/equiv_type_hlds.m:
compiler/exception_analysis.m:
compiler/file_names.m:
compiler/float_regs.m:
compiler/follow_vars.m:
compiler/format_call.m:
compiler/generate_dep_d_files.m:
compiler/get_dependencies.m:
compiler/goal_expr_to_goal.m:
compiler/goal_mode.m:
compiler/goal_path.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/granularity.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_clauses.m:
compiler/hlds_code_util.m:
compiler/hlds_error_util.m:
compiler/hlds_goal.m:
compiler/hlds_llds.m:
compiler/hlds_out_pred.m:
compiler/hlds_rtti.m:
compiler/hlds_statistics.m:
compiler/inlining.m:
compiler/inst_check.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/instance_method_clauses.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/intermod_analysis.m:
compiler/interval.m:
compiler/introduce_exists_casts.m:
compiler/introduce_parallelism.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/llds.m:
compiler/llds_out_data.m:
compiler/llds_out_file.m:
compiler/llds_out_util.m:
compiler/lookup_switch.m:
compiler/loop_inv.m:
compiler/make.module_target.m:
compiler/make.util.m:
compiler/make_goal.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_types.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/middle_rec.m:
compiler/ml_accurate_gc.m:
compiler/ml_args_util.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_commit_gen.m:
compiler/ml_disj_gen.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_gen_info.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_unify_gen.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_c_func.m:
compiler/mlds_to_c_global.m:
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_type.m:
compiler/mmc_analysis.m:
compiler/mode_comparison.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/mode_ordering.m:
compiler/modecheck_call.m:
compiler/modecheck_coerce.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/module_cmds.m:
compiler/old_type_constraints.m:
compiler/opt_debug.m:
compiler/optimize.m:
compiler/options_file.m:
compiler/ordering_mode_constraints.m:
compiler/par_loop_control.m:
compiler/parse_item.m:
compiler/parse_string_format.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_to_term.m:
compiler/parse_util.m:
compiler/pd_debug.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/peephole.m:
compiler/polymorphism.m:
compiler/polymorphism_info.m:
compiler/polymorphism_lambda.m:
compiler/polymorphism_type_class_info.m:
compiler/polymorphism_type_info.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/pred_name.m:
compiler/pred_table.m:
compiler/prog_item.m:
compiler/prog_rep.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/push_goals_together.m:
compiler/qual_info.m:
compiler/quantification.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.points_to_graph.m:
compiler/rbmm.points_to_info.m:
compiler/rbmm.region_resurrection_renaming.m:
compiler/rbmm.region_transformation.m:
compiler/recompilation.used_file.m:
compiler/recompilation.version.m:
compiler/recompute_instmap_deltas.m:
compiler/resolve_unify_functor.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
compiler/set_of_var.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_conj.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/simplify_goal_scope.m:
compiler/simplify_goal_switch.m:
compiler/simplify_goal_unify.m:
compiler/simplify_info.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/smm_common.m:
compiler/ssdebug.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/stack_opt.m:
compiler/stm_expand.m:
compiler/store_alloc.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.domain.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.lbu.m:
compiler/structure_reuse.lfu.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_constr_data.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/term_constr_main_types.m:
compiler/term_constr_util.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/term_util.m:
compiler/trace_gen.m:
compiler/trailing_analysis.m:
compiler/transform_llds.m:
compiler/try_expand.m:
compiler/tupling.m:
compiler/type_assign.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_debug.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_gen_construct.m:
compiler/unify_gen_deconstruct.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/var_locn.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2022-04-18 02:00:38 +10:00

399 lines
14 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 2009-2012 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: ml_disj_gen.m.
% Authors: fjh, zs.
%
% Generate MLDS code for disjunctions.
%
%---------------------------------------------------------------------------%
%
% Code for empty disjunctions (`fail')
%
%
% model_semi goal:
% <succeeded = fail>
% ===>
% succeeded = MR_FALSE;
%
% model_non goal:
% <fail && CONT()>
% ===>
% /* fall through */
%
%---------------------------------------------------------------------------%
%
% Code for non-empty disjunctions
%
%
% model_det disj:
%
% model_det Goal:
% <do (Goal ; Goals)>
% ===>
% <do Goal>
% /* <Goals> will never be reached */
%
% model_semi Goal:
% <do (Goal ; Goals)>
% ===>
% MR_bool succeeded;
%
% <succeeded = Goal>;
% if (!succeeded) {
% <do Goals>;
% }
%
% model_semi disj:
%
% model_det Goal:
% <succeeded = (Goal ; Goals)>
% ===>
% MR_bool succeeded;
%
% <do Goal>
% succeeded = MR_TRUE
% /* <Goals> will never be reached */
%
% model_semi Goal:
% <succeeded = (Goal ; Goals)>
% ===>
% MR_bool succeeded;
%
% <succeeded = Goal>;
% if (!succeeded) {
% <succeeded = Goals>;
% }
%
% model_non disj:
%
% model_det Goal:
% <(Goal ; Goals) && SUCCEED()>
% ===>
% <Goal>
% SUCCEED();
% <Goals && SUCCEED()>
%
% model_semi Goal:
% <(Goal ; Goals) && SUCCEED()>
% ===>
% MR_bool succeeded;
%
% <succeeded = Goal>
% if (succeeded) SUCCEED();
% <Goals && SUCCEED()>
%
% model_non Goal:
% <(Goal ; Goals) && SUCCEED()>
% ===>
% <Goal && SUCCEED()>
% <Goals && SUCCEED()>
%
% The implementation of lookup disjunctions is modelled on the code in
% disj_gen.m that does the same thing for the LLDS backend. Any changes here
% may need to be reflected there as well.
%
%---------------------------------------------------------------------------%
:- module ml_backend.ml_disj_gen.
:- interface.
:- import_module hlds.
:- import_module hlds.code_model.
:- import_module hlds.hlds_goal.
:- import_module ml_backend.ml_gen_info.
:- import_module ml_backend.mlds.
:- import_module parse_tree.
:- import_module parse_tree.prog_data.
:- import_module list.
:- pred ml_gen_disj(list(hlds_goal)::in, hlds_goal_info::in, code_model::in,
prog_context::in, list(mlds_stmt)::out,
ml_gen_info::in, ml_gen_info::out) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module backend_libs.
:- import_module backend_libs.builtin_ops.
:- import_module hlds.goal_form.
:- import_module hlds.hlds_module.
:- import_module libs.
:- import_module libs.globals.
:- import_module libs.optimization_options.
:- import_module ml_backend.ml_code_gen.
:- import_module ml_backend.ml_code_util.
:- import_module ml_backend.ml_global_data.
:- import_module ml_backend.ml_util.
:- import_module parse_tree.set_of_var.
:- import_module parse_tree.var_table.
:- import_module bool.
:- import_module maybe.
:- import_module require.
ml_gen_disj(Disjuncts, GoalInfo, CodeModel, Context, Stmts, !Info) :-
% Note that we place each arm of the disjunction into a block. This is so
% that we can avoid having to figure out how to merge their declarations
% with the declarations of the other disjuncts.
(
Disjuncts = [],
% Handle empty disjunctions (a.ka. `fail').
ml_gen_failure(CodeModel, Context, Stmts, !Info)
;
Disjuncts = [_FirstDisjunct | LaterDisjuncts],
LaterDisjuncts = [],
unexpected($pred, "single disjunct")
;
Disjuncts = [FirstDisjunct | LaterDisjuncts],
LaterDisjuncts = [_ | _],
% Start every disjunct with EntryPackedWordMap to prevent
% later disjuncts from trying to use map entries added by
% earlier disjuncts.
ml_gen_info_get_packed_word_map(!.Info, EntryPackedWordMap),
(
CodeModel = model_non,
( if
ml_gen_info_get_target(!.Info, Target),
allow_lookup_disj(Target) = yes,
ml_gen_info_get_module_info(!.Info, ModuleInfo),
module_info_get_globals(ModuleInfo, Globals),
globals.get_opt_tuple(Globals, OptTuple),
OptTuple ^ ot_use_static_ground_cells =
use_static_ground_cells,
DisjNonLocals = goal_info_get_nonlocals(GoalInfo),
all_disjuncts_are_conj_of_unify(DisjNonLocals, Disjuncts),
% Since the MLDS backend implements trailing by a
% HLDS-to-HLDS transform (which is in add_trail_ops.m),
% if we get here, then trailing is not enabled, and we do
% not have to worry about resetting the trail at the
% starts of all non-first disjuncts.
NonLocals = goal_info_get_nonlocals(GoalInfo),
OutVars = set_of_var.to_sorted_list(NonLocals),
list.map_foldl(ml_generate_constants_for_arm(OutVars),
Disjuncts, Solns, !Info)
then
ml_gen_lookup_disj(OutVars, Solns, Context, Stmts, !Info)
else
ml_gen_ordinary_model_non_disj(FirstDisjunct, LaterDisjuncts,
EntryPackedWordMap, Context, Stmts,
[], ReachableConstVarMaps, !Info),
ml_gen_record_consensus_const_var_map(ReachableConstVarMaps,
!Info)
)
;
( CodeModel = model_det
; CodeModel = model_semi
),
ml_gen_ordinary_model_det_semi_disj(FirstDisjunct, LaterDisjuncts,
EntryPackedWordMap, CodeModel, Context, Stmts,
[], ReachableConstVarMaps, !Info),
ml_gen_record_consensus_const_var_map(ReachableConstVarMaps,
!Info)
),
% Start the code *after* the whole disjunction with
% EntryPackedWordMap as well, to prevent that code from trying to use
% map entries added by a disjunct that may have failed or may not
% have been taken.
ml_gen_info_set_packed_word_map(EntryPackedWordMap, !Info)
).
% Disable generation of lookup disjunctions on some backends.
% ml_generate_constants_for_arm expects the mark_static_terms pass to have
% been run, which is not true when static_ground_cells is disabled.
%
:- func allow_lookup_disj(mlds_target_lang) = bool.
allow_lookup_disj(ml_target_c) = yes.
allow_lookup_disj(ml_target_csharp) = yes.
allow_lookup_disj(ml_target_java) = yes.
%---------------------------------------------------------------------------%
:- pred ml_gen_ordinary_model_det_semi_disj(hlds_goal::in, list(hlds_goal)::in,
packed_word_map::in, code_model::in, prog_context::in,
list(mlds_stmt)::out,
list(ml_ground_term_map)::in, list(ml_ground_term_map)::out,
ml_gen_info::in, ml_gen_info::out) is det.
ml_gen_ordinary_model_det_semi_disj(FirstDisjunct, LaterDisjuncts,
EntryPackedWordMap, CodeModel, Context, Stmts,
!ReachableConstVarMaps, !Info) :-
ml_gen_info_set_packed_word_map(EntryPackedWordMap, !Info),
(
LaterDisjuncts = [],
ml_gen_goal_as_branch_block(CodeModel, FirstDisjunct, Stmt,
!ReachableConstVarMaps, !Info),
Stmts = [Stmt]
;
LaterDisjuncts = [FirstLaterDisjunct | LaterLaterDisjuncts],
% model_det/model_semi disj:
%
% model_det goal:
% <Goal ; Goals>
% ===>
% <Goal>
% /* <Goals> will never be reached */
%
% model_semi goal:
% <Goal ; Goals>
% ===>
% {
% MR_bool succeeded;
%
% <succeeded = Goal>;
% if (!succeeded) {
% <Goals>;
% }
% }
FirstDisjunct = hlds_goal(_, FirstGoalInfo),
FirstCodeModel = goal_info_get_code_model(FirstGoalInfo),
(
FirstCodeModel = model_det,
ml_gen_goal_as_branch_block(model_det, FirstDisjunct, Stmt,
!ReachableConstVarMaps, !Info),
Stmts = [Stmt]
;
FirstCodeModel = model_semi,
ml_gen_goal_as_branch_block(model_semi, FirstDisjunct, FirstStmt,
!ReachableConstVarMaps, !Info),
ml_gen_test_success(Succeeded, !Info),
ml_gen_ordinary_model_det_semi_disj(FirstLaterDisjunct,
LaterLaterDisjuncts, EntryPackedWordMap, CodeModel, Context,
LaterStmts, !ReachableConstVarMaps, !Info),
LaterStmt = ml_gen_block([], [], LaterStmts, Context),
IfStmt = ml_stmt_if_then_else(ml_unop(logical_not, Succeeded),
LaterStmt, no, Context),
Stmts = [FirstStmt, IfStmt]
;
FirstCodeModel = model_non,
% simplify.m should wrap commits around these disjunctions
% if overall they are model_semi.
unexpected($pred,
"model_non disjunct in model_det or model_semi disjunction")
)
).
%---------------------------------------------------------------------------%
:- pred ml_gen_ordinary_model_non_disj(hlds_goal::in, list(hlds_goal)::in,
packed_word_map::in, prog_context::in, list(mlds_stmt)::out,
list(ml_ground_term_map)::in, list(ml_ground_term_map)::out,
ml_gen_info::in, ml_gen_info::out) is det.
ml_gen_ordinary_model_non_disj(FirstDisjunct, LaterDisjuncts,
EntryPackedWordMap, Context, Stmts, !ReachableConstVarMaps, !Info) :-
ml_gen_info_set_packed_word_map(EntryPackedWordMap, !Info),
(
LaterDisjuncts = [],
ml_gen_goal_as_branch_block(model_non, FirstDisjunct, Stmt,
!ReachableConstVarMaps, !Info),
Stmts = [Stmt]
;
LaterDisjuncts = [FirstLaterDisjunct | LaterLaterDisjuncts],
% model_non disj:
%
% <(Goal ; Goals) && SUCCEED()>
% ===>
% <Goal && SUCCEED()>
% <Goals && SUCCEED()>
ml_gen_goal_as_branch_block(model_non, FirstDisjunct, FirstStmt,
!ReachableConstVarMaps, !Info),
ml_gen_ordinary_model_non_disj(FirstLaterDisjunct, LaterLaterDisjuncts,
EntryPackedWordMap, Context, LaterStmts,
!ReachableConstVarMaps, !Info),
Stmts = [FirstStmt | LaterStmts]
).
%---------------------------------------------------------------------------%
:- pred ml_gen_lookup_disj(list(prog_var)::in, list(list(mlds_rval))::in,
prog_context::in, list(mlds_stmt)::out,
ml_gen_info::in, ml_gen_info::out) is det.
ml_gen_lookup_disj(OutVars, Solns, Context, Stmts, !Info) :-
ml_gen_info_get_module_info(!.Info, ModuleInfo),
module_info_get_name(ModuleInfo, ModuleName),
MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
ml_gen_info_get_target(!.Info, Target),
ml_gen_info_get_var_table(!.Info, VarTable),
lookup_var_entries(VarTable, OutVars, OutVarEntries),
MLDS_FieldTypes =
list.map(var_table_entry_to_mlds_type(ModuleInfo), OutVarEntries),
ml_gen_info_get_global_data(!.Info, GlobalData0),
ml_gen_static_vector_type(MLDS_ModuleName, Context, Target,
MLDS_FieldTypes, StructTypeNum, StructType, FieldIds,
GlobalData0, GlobalData1),
ml_construct_disjunction_vector(ModuleInfo, StructType, Solns,
RowInitializers),
list.length(RowInitializers, NumRows),
ml_gen_static_vector_defn(MLDS_ModuleName, StructTypeNum, RowInitializers,
VectorCommon, GlobalData1, GlobalData),
ml_gen_info_set_global_data(GlobalData, !Info),
ml_gen_info_new_aux_var_name(mcav_slot, SlotVar, !Info),
SlotVarType = mlds_builtin_type_int(int_type_int),
% We never need to trace ints.
SlotVarGCStmt = gc_no_stmt,
SlotVarDefn = ml_gen_mlds_var_decl(SlotVar, SlotVarType,
SlotVarGCStmt, Context),
SlotVarLval = ml_local_var(SlotVar, SlotVarType),
SlotVarRval = ml_lval(SlotVarLval),
ml_generate_field_assigns(OutVars, MLDS_FieldTypes, FieldIds,
VectorCommon, StructType, SlotVarRval, Context, LookupStmts, !Info),
ml_gen_call_current_success_cont(Context, CallContStmt, !Info),
InitSlotVarStmt = ml_stmt_atomic(
assign(SlotVarLval, ml_const(mlconst_int(0))),
Context),
IncrSlotVarStmt = ml_stmt_atomic(
assign(SlotVarLval,
ml_binop(int_add(int_type_int), SlotVarRval,
ml_const(mlconst_int(1)))),
Context),
LoopBodyStmt = ml_stmt_block([], [],
LookupStmts ++ [CallContStmt, IncrSlotVarStmt], Context),
LoopCond = ml_binop(int_lt(int_type_int), SlotVarRval,
ml_const(mlconst_int(NumRows))),
LoopStmt = ml_stmt_while(loop_at_least_once, LoopCond, LoopBodyStmt,
[SlotVar], Context),
Stmt = ml_stmt_block([SlotVarDefn], [],
[InitSlotVarStmt, LoopStmt], Context),
Stmts = [Stmt].
:- pred ml_construct_disjunction_vector(module_info::in, mlds_type::in,
list(list(mlds_rval))::in, list(mlds_initializer)::out) is det.
ml_construct_disjunction_vector(_ModuleInfo, _StructType, [], []).
ml_construct_disjunction_vector(ModuleInfo, StructType,
[Soln | Solns], [RowInitializer | RowInitializers]) :-
FieldInitializers = list.map(wrap_init_obj, Soln),
RowInitializer = init_struct(StructType, FieldInitializers),
ml_construct_disjunction_vector(ModuleInfo, StructType,
Solns, RowInitializers).
%---------------------------------------------------------------------------%
:- end_module ml_backend.ml_disj_gen.
%---------------------------------------------------------------------------%