[m-rev.] trivial diff: represent mlds switches using a d.u. type
Julien Fischer
juliensf at csse.unimelb.edu.au
Wed Aug 22 03:39:51 AEST 2007
Estimated hours taken: 0.5
Branches: main
Replace a pair with a specific d.u. type.
compiler/mlds.m:
Use a specific d.u. type to represent switches in the MLDS instead
of a pair.
compiler/ml_closure_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_simplify_switch.m:
compiler/ml_string_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
Conform to the above change.
Julien.
Index: ml_closure_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_closure_gen.m,v
retrieving revision 1.52
diff -u -r1.52 ml_closure_gen.m
--- ml_closure_gen.m 21 Aug 2007 15:50:40 -0000 1.52
+++ ml_closure_gen.m 21 Aug 2007 17:33:39 -0000
@@ -25,6 +25,8 @@
:- import_module list.
+%-----------------------------------------------------------------------------%
+
% ml_gen_closure(PredId, ProcId, Var, ArgVars, ArgModes,
% HowToConstruct, Context, Decls, Statements):
%
Index: ml_code_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.127
diff -u -r1.127 ml_code_util.m
--- ml_code_util.m 21 Aug 2007 15:50:40 -0000 1.127
+++ ml_code_util.m 21 Aug 2007 17:33:39 -0000
@@ -2256,8 +2256,10 @@
:- pred fixup_newobj_in_case(mlds_switch_case::in, mlds_switch_case::out,
fixup_newobj_info::in, fixup_newobj_info::out) is det.
-fixup_newobj_in_case(Conds - Statement0, Conds - Statement, !Fixup) :-
- fixup_newobj_in_statement(Statement0, Statement, !Fixup).
+fixup_newobj_in_case(Case0, Case, !Fixup) :-
+ Case0 = mlds_switch_case(Conds, Statement0),
+ fixup_newobj_in_statement(Statement0, Statement, !Fixup),
+ Case = mlds_switch_case(Conds, Statement).
:- pred fixup_newobj_in_maybe_statement(maybe(statement)::in,
maybe(statement)::out,
@@ -2646,9 +2648,13 @@
%
get_copy_out_option(Globals, CodeModel) = CopyOut :-
- ( CodeModel = model_non ->
+ (
+ CodeModel = model_non,
globals.lookup_bool_option(Globals, nondet_copy_out, CopyOut)
;
+ ( CodeModel = model_det
+ ; CodeModel = model_semi
+ ),
globals.lookup_bool_option(Globals, det_copy_out, CopyOut)
).
Index: ml_elim_nested.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.93
diff -u -r1.93 ml_elim_nested.m
--- ml_elim_nested.m 21 Aug 2007 15:50:40 -0000 1.93
+++ ml_elim_nested.m 21 Aug 2007 17:33:39 -0000
@@ -450,7 +450,6 @@
:- import_module counter.
:- import_module int.
:- import_module list.
-:- import_module pair.
:- import_module maybe.
:- import_module set.
:- import_module solutions.
@@ -1456,9 +1455,11 @@
:- pred flatten_case(mlds_switch_case::in, mlds_switch_case::out,
elim_info::in, elim_info::out) is det.
-flatten_case(Conds0 - Statement0, Conds - Statement, !Info) :-
+flatten_case(Case0, Case, !Info) :-
+ Case0 = mlds_switch_case(Conds0, Statement0),
list.map_foldl(fixup_case_cond, Conds0, Conds, !Info),
- flatten_statement(Statement0, Statement, !Info).
+ flatten_statement(Statement0, Statement, !Info),
+ Case = mlds_switch_case(Conds, Statement).
:- pred flatten_default(mlds_switch_default::in, mlds_switch_default::out,
elim_info::in, elim_info::out) is det.
@@ -2137,7 +2138,7 @@
cases_contains_defn(Cases, Defn) :-
list.member(Case, Cases),
- Case = _MatchConds - Statement,
+ Case = mlds_switch_case(_MatchConds, Statement),
statement_contains_defn(Statement, Defn).
:- pred default_contains_defn(mlds_switch_default::in, mlds_defn::out)
@@ -2259,9 +2260,11 @@
:- pred add_unchain_stack_to_case(mlds_switch_case::in,
mlds_switch_case::out, elim_info::in, elim_info::out) is det.
-add_unchain_stack_to_case(Conds0 - Statement0, Conds - Statement, !Info) :-
+add_unchain_stack_to_case(Case0, Case, !Info) :-
+ Case0 = mlds_switch_case(Conds0, Statement0),
list.map_foldl(fixup_case_cond, Conds0, Conds, !Info),
- add_unchain_stack_to_statement(Statement0, Statement, !Info).
+ add_unchain_stack_to_statement(Statement0, Statement, !Info),
+ Case = mlds_switch_case(Conds, Statement).
:- pred add_unchain_stack_to_default(mlds_switch_default::in,
mlds_switch_default::out, elim_info::in, elim_info::out) is det.
Index: ml_optimize.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_optimize.m,v
retrieving revision 1.52
diff -u -r1.52 ml_optimize.m
--- ml_optimize.m 21 Aug 2007 15:50:41 -0000 1.52
+++ ml_optimize.m 21 Aug 2007 17:33:39 -0000
@@ -194,8 +194,10 @@
:- func optimize_in_case(opt_info, mlds_switch_case) = mlds_switch_case.
-optimize_in_case(OptInfo, Conds - Statement0) = Conds - Statement :-
- Statement = optimize_in_statement(OptInfo, Statement0).
+optimize_in_case(OptInfo, Case0) = Case :-
+ Case0 = mlds_switch_case(Conds, Statement0),
+ Statement = optimize_in_statement(OptInfo, Statement0),
+ Case = mlds_switch_case(Conds, Statement).
:- func optimize_in_default(opt_info, mlds_switch_default) =
mlds_switch_default.
@@ -1136,9 +1138,11 @@
:- pred eliminate_var_in_case(mlds_switch_case::in, mlds_switch_case::out,
var_elim_info::in, var_elim_info::out) is det.
-eliminate_var_in_case(Conds0 - Statement0, Conds - Statement, !VarElimInfo) :-
+eliminate_var_in_case(Case0, Case, !VarElimInfo) :-
+ Case0 = mlds_switch_case(Conds0, Statement0),
list.map_foldl(eliminate_var_in_case_cond, Conds0, Conds, !VarElimInfo),
- eliminate_var_in_statement(Statement0, Statement, !VarElimInfo).
+ eliminate_var_in_statement(Statement0, Statement, !VarElimInfo),
+ Case = mlds_switch_case(Conds, Statement).
:- pred eliminate_var_in_default(
mlds_switch_default::in, mlds_switch_default::out,
Index: ml_simplify_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_simplify_switch.m,v
retrieving revision 1.22
diff -u -r1.22 ml_simplify_switch.m
--- ml_simplify_switch.m 21 Aug 2007 15:50:41 -0000 1.22
+++ ml_simplify_switch.m 21 Aug 2007 17:33:39 -0000
@@ -49,7 +49,6 @@
:- import_module list.
:- import_module map.
:- import_module maybe.
-:- import_module pair.
%-----------------------------------------------------------------------------%
@@ -109,7 +108,7 @@
Cases = [SingleCase],
Default = default_is_unreachable
->
- SingleCase = _MatchCondition - CaseStatement,
+ SingleCase = mlds_switch_case(_MatchCondition, CaseStatement),
Statement = CaseStatement
;
Stmt = Stmt0,
@@ -217,7 +216,7 @@
int::in, int::out, int::in, int::out) is det.
find_first_and_last_case_2(Case, !Min, !Max) :-
- Case = CaseConds - _CaseStatement,
+ Case = mlds_switch_case(CaseConds, _CaseStatement),
list.foldl2(find_first_and_last_case_3, CaseConds, !Min, !Max).
:- pred find_first_and_last_case_3(mlds_case_match_cond::in,
@@ -343,7 +342,7 @@
generate_case(Case, EndLabel, CaseLabelsMap0, CaseLabelsMap,
Decls, Statements, !Info) :-
- Case = MatchCondition - CaseStatement,
+ Case = mlds_switch_case(MatchCondition, CaseStatement),
ml_gen_new_label(ThisLabel, !Info),
insert_cases_into_map(MatchCondition, ThisLabel,
CaseLabelsMap0, CaseLabelsMap),
@@ -449,7 +448,7 @@
).
ml_switch_to_if_else_chain([Case | Cases], Default, SwitchRval, MLDS_Context) =
Statement :-
- Case = MatchConditions - CaseStatement,
+ Case = mlds_switch_case(MatchConditions, CaseStatement),
(
Cases = [],
Default = default_is_unreachable
Index: ml_string_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_string_switch.m,v
retrieving revision 1.31
diff -u -r1.31 ml_string_switch.m
--- ml_string_switch.m 21 Aug 2007 15:50:41 -0000 1.31
+++ ml_string_switch.m 21 Aug 2007 17:33:39 -0000
@@ -258,7 +258,8 @@
MLDS_Context),
CaseStatement = statement(ml_stmt_block([], [Comment, GoalStatement]),
MLDS_Context),
- MLDS_Cases = [[match_value(const(mlconst_int(Slot)))] - CaseStatement]
+ MLDS_Cases = [mlds_switch_case([match_value(const(mlconst_int(Slot)))],
+ CaseStatement)]
;
StringRval = const(mlconst_null(ml_string_type)),
NextSlotRval = const(mlconst_int(-2)),
Index: ml_switch_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_switch_gen.m,v
retrieving revision 1.31
diff -u -r1.31 ml_switch_gen.m
--- ml_switch_gen.m 21 Aug 2007 15:50:41 -0000 1.31
+++ ml_switch_gen.m 21 Aug 2007 17:33:39 -0000
@@ -445,7 +445,7 @@
unexpected(this_file, "ml_switch_gen.m: invalid tag type")
),
ml_gen_goal(CodeModel, Goal, Statement, !Info),
- MLDS_Case = [match_value(Rval)] - Statement.
+ MLDS_Case = mlds_switch_case([match_value(Rval)], Statement).
% Generate an appropriate default for a switch.
%
Index: ml_tag_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_tag_switch.m,v
retrieving revision 1.22
diff -u -r1.22 ml_tag_switch.m
--- ml_tag_switch.m 21 Aug 2007 15:50:41 -0000 1.22
+++ ml_tag_switch.m 21 Aug 2007 17:33:39 -0000
@@ -156,7 +156,7 @@
)
),
PrimaryTagRval = const(mlconst_int(PrimaryTag)),
- MLDS_Case = [match_value(PrimaryTagRval)] - Statement.
+ MLDS_Case = mlds_switch_case([match_value(PrimaryTagRval)], Statement).
:- pred gen_stag_switch(stag_goal_list::in, int::in, sectag_locn::in,
prog_var::in, code_model::in, can_fail::in, prog_context::in,
@@ -208,7 +208,7 @@
Case = Stag - stag_goal(_ConsId, Goal),
StagRval = const(mlconst_int(Stag)),
ml_gen_goal(CodeModel, Goal, Statement, !Info),
- MLDS_Case = [match_value(StagRval)] - Statement.
+ MLDS_Case = mlds_switch_case([match_value(StagRval)], Statement).
%-----------------------------------------------------------------------------%
Index: ml_tailcall.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_tailcall.m,v
retrieving revision 1.46
diff -u -r1.46 ml_tailcall.m
--- ml_tailcall.m 21 Aug 2007 15:50:41 -0000 1.46
+++ ml_tailcall.m 21 Aug 2007 17:33:39 -0000
@@ -86,7 +86,6 @@
:- import_module int.
:- import_module list.
:- import_module maybe.
-:- import_module pair.
:- import_module solutions.
%-----------------------------------------------------------------------------%
@@ -323,9 +322,10 @@
:- func mark_tailcalls_in_case(mlds_switch_case, at_tail, locals) =
mlds_switch_case.
-mark_tailcalls_in_case(Cond - Statement0, AtTail, Locals) =
- Cond - Statement :-
- Statement = mark_tailcalls_in_statement(Statement0, AtTail, Locals).
+mark_tailcalls_in_case(Case0, AtTail, Locals) = Case :-
+ Case0 = mlds_switch_case(Cond, Statement0),
+ Statement = mark_tailcalls_in_statement(Statement0, AtTail, Locals),
+ Case = mlds_switch_case(Cond, Statement).
:- func mark_tailcalls_in_default(mlds_switch_default, at_tail, locals) =
mlds_switch_default.
Index: ml_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.58
diff -u -r1.58 ml_util.m
--- ml_util.m 21 Aug 2007 15:50:42 -0000 1.58
+++ ml_util.m 21 Aug 2007 17:33:39 -0000
@@ -201,9 +201,6 @@
:- import_module ml_backend.ml_unify_gen.
:- import_module parse_tree.prog_type.
-:- import_module bool.
-:- import_module list.
-:- import_module pair.
:- import_module solutions.
%-----------------------------------------------------------------------------%
@@ -319,7 +316,7 @@
cases_contains_statement(Cases, SubStatement) :-
list.member(Case, Cases),
- Case = _MatchCond - Statement,
+ Case = mlds_switch_case(_MatchCond, Statement),
statement_contains_statement(Statement, SubStatement).
:- pred default_contains_statement(mlds_switch_default::in,
@@ -419,7 +416,7 @@
cases_contains_var(Cases, Name) :-
list.member(Case, Cases),
- Case = _MatchConds - Statement,
+ Case = mlds_switch_case(_MatchConds, Statement),
statement_contains_var(Statement, Name).
:- pred default_contains_var(mlds_switch_default::in, mlds_data::in)
Index: mlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.153
diff -u -r1.153 mlds.m
--- mlds.m 21 Aug 2007 15:50:42 -0000 1.153
+++ mlds.m 21 Aug 2007 17:33:39 -0000
@@ -349,7 +349,6 @@
:- import_module list.
:- import_module map.
:- import_module maybe.
-:- import_module pair.
:- import_module set.
%-----------------------------------------------------------------------------%
@@ -1120,7 +1119,8 @@
% Unlike C, cases do NOT fall through; if you want to achieve that
% effect, you need to use an explicit goto.
:- type mlds_switch_cases == list(mlds_switch_case).
-:- type mlds_switch_case == pair(mlds_case_match_conds, statement).
+:- type mlds_switch_case
+ ---> mlds_switch_case(mlds_case_match_conds, statement).
% Case_match_conds should be a _non-empty_ list of conditions;
% if _any_ of the conditions match, this case will be selected.
Index: mlds_to_c.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.222
diff -u -r1.222 mlds_to_c.m
--- mlds_to_c.m 21 Aug 2007 15:50:42 -0000 1.222
+++ mlds_to_c.m 21 Aug 2007 17:33:39 -0000
@@ -2952,7 +2952,7 @@
mlds_switch_case::in, io::di, io::uo) is det.
mlds_output_switch_case(Indent, FuncInfo, Context, Case, !IO) :-
- Case = (Conds - Statement),
+ Case = mlds_switch_case(Conds, Statement),
list.foldl(mlds_output_case_cond(Indent, Context), Conds, !IO),
mlds_output_statement(Indent + 1, FuncInfo, Statement, !IO),
mlds_indent(Context, Indent + 1, !IO),
Index: mlds_to_gcc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.134
diff -u -r1.134 mlds_to_gcc.m
--- mlds_to_gcc.m 21 Aug 2007 15:50:43 -0000 1.134
+++ mlds_to_gcc.m 21 Aug 2007 17:33:40 -0000
@@ -2938,7 +2938,7 @@
:- pred gen_case(defn_info::in, mlds_switch_case::in,
io__state::di, io__state::uo) is det.
-gen_case(DefnInfo, MatchConds - Code) -->
+gen_case(DefnInfo, mlds_switch_case(MatchConds, Code)) -->
list__foldl(gen_case_label(DefnInfo), MatchConds),
gen_statement(DefnInfo, Code),
gcc__gen_break.
Index: mlds_to_il.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.190
diff -u -r1.190 mlds_to_il.m
--- mlds_to_il.m 21 Aug 2007 15:50:43 -0000 1.190
+++ mlds_to_il.m 21 Aug 2007 17:33:40 -0000
@@ -515,8 +515,11 @@
:- func rename_switch_case(mlds_switch_case) = mlds_switch_case.
-rename_switch_case(Conds - Stmt)
- = list.map(rename_cond, Conds) - rename_statement(Stmt).
+rename_switch_case(Case0) = Case :-
+ Case0 = mlds_switch_case(Conds0, Stmt0),
+ Conds = list.map(rename_cond, Conds0),
+ Stmt = rename_statement(Stmt0),
+ Case = mlds_switch_case(Conds, Stmt).
:- func rename_cond(mlds_case_match_cond) = mlds_case_match_cond.
Index: mlds_to_java.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.97
diff -u -r1.97 mlds_to_java.m
--- mlds_to_java.m 21 Aug 2007 15:50:43 -0000 1.97
+++ mlds_to_java.m 21 Aug 2007 17:33:40 -0000
@@ -702,7 +702,7 @@
method_ptrs_in_switch_cases([], !CodeAddrs).
method_ptrs_in_switch_cases([Case | Cases], !CodeAddrs) :-
- Case = _Conditions - Statement,
+ Case = mlds_switch_case(_Conditions, Statement),
method_ptrs_in_statement(Statement, !CodeAddrs),
method_ptrs_in_switch_cases(Cases, !CodeAddrs).
@@ -2697,7 +2697,7 @@
output_switch_case(Indent, ModuleInfo, FuncInfo, Context, Case, ExitMethods,
!IO) :-
- Case = (Conds - Statement),
+ Case = mlds_switch_case(Conds, Statement),
ModuleName = FuncInfo ^ func_info_name ^ mod_name,
list.foldl(output_case_cond(Indent, ModuleInfo, ModuleName, Context),
Conds, !IO),
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list