[m-rev.] diff: Add completeness information to switches in bytecode representation.
Paul Bone
pbone at csse.unimelb.edu.au
Sun Sep 21 21:59:10 AEST 2008
Estimated hours taken: 0.5
Branches: main
Alter the program representation bytecode used by the the declartive debugger
and deep profiler. Modify the representation of a switch goal to include
information about whether it is complete.
mdbcomp/program_representation.m:
Create the new type 'switch_can_fail_rep'.
Include a field in the switch_rep alternative of the goal_expr_rep type.
Process an extra byte to give the completeness of a switch when reading in
switch goals.
Increment procrep file version number.
compiler/prog_rep.m:
Write out an extra byte for switches describing if the switch is complete.
runtime/mercury_deep_profiling.c:
Increment progrep file version number.
browser/declarative_tree.m:
deep_profiler/program_representation_utils.m:
tests/debugger/declarative/builtin_call_rep.exp:
tests/debugger/declarative/dependency.exp:
Conform to changes in mdbcomp/program_representation.m
Index: browser/declarative_tree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_tree.m,v
retrieving revision 1.59
diff -u -p -b -r1.59 declarative_tree.m
--- browser/declarative_tree.m 4 Sep 2008 11:40:59 -0000 1.59
+++ browser/declarative_tree.m 20 Sep 2008 13:42:47 -0000
@@ -1293,7 +1293,7 @@ match_goal_to_contour_event(Store, Goal,
"mismatch on disj"))
)
;
- GoalExpr = switch_rep(_SwitchVar, Cases),
+ GoalExpr = switch_rep(_SwitchVar, _SwitchCanFail, Cases),
(
Contour = [_ - ContourHeadNode | ContourTail],
ContourHeadNode = node_switch(_, Label),
Index: compiler/prog_rep.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_rep.m,v
retrieving revision 1.62
diff -u -p -b -r1.62 prog_rep.m
--- compiler/prog_rep.m 13 Aug 2008 07:38:08 -0000 1.62
+++ compiler/prog_rep.m 20 Sep 2008 13:42:47 -0000
@@ -284,9 +284,11 @@ goal_to_byte_list(hlds_goal(GoalExpr, Go
unexpected(this_file, "goal_expr_to_byte_list: complicated_unify")
)
;
- GoalExpr = switch(SwitchVar, _, Cases),
+ GoalExpr = switch(SwitchVar, CanFail, Cases),
cases_to_byte_list(Cases, InstMap0, Info, CasesBytes, !StackInfo),
+ CanFailByte = can_fail_to_byte(CanFail),
ExprBytes = [goal_type_to_byte(goal_switch)] ++
+ [CanFailByte] ++
var_to_byte_list(Info, SwitchVar) ++
length_to_byte_list(Cases) ++ CasesBytes
;
@@ -595,6 +597,11 @@ lineno_to_byte_list(VarNum) = Bytes :-
method_num_to_byte_list(VarNum) = Bytes :-
short_to_byte_list(VarNum, Bytes).
+:- func can_fail_to_byte(can_fail) = int.
+
+can_fail_to_byte(can_fail) = 0.
+can_fail_to_byte(cannot_fail) = 1.
+
%---------------------------------------------------------------------------%
:- func this_file = string.
Index: deep_profiler/program_representation_utils.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/program_representation_utils.m,v
retrieving revision 1.3
diff -u -p -b -r1.3 program_representation_utils.m
--- deep_profiler/program_representation_utils.m 17 Sep 2008 03:26:29 -0000 1.3
+++ deep_profiler/program_representation_utils.m 20 Sep 2008 13:42:47 -0000
@@ -157,10 +157,10 @@ print_goal_to_strings(VarTable, Indent,
cord.singleton(" (\n") ++ DisjString ++ indent(Indent) ++
cord.singleton(")\n")
;
- GoalExprRep = switch_rep(SwitchVarRep, CasesRep),
+ GoalExprRep = switch_rep(SwitchVarRep, CanFail, CasesRep),
lookup_var_name(VarTable, SwitchVarRep, SwitchVarName),
- string.format(" ( switch on %s\n", [s(SwitchVarName)],
- SwitchOpenString),
+ string.format(" ( %s switch on %s\n",
+ [s(string(CanFail)), s(SwitchVarName)], SwitchOpenString),
print_switch_to_strings(VarTable, Indent, CasesRep, no, SwitchString),
Strings = indent(Indent) ++ DetismString ++ GoalAnnotationString ++
cord.singleton(SwitchOpenString) ++ SwitchString ++
@@ -580,10 +580,10 @@ goal_annotate_coverage(Info, GoalPath, !
Disjuncts0, Disjuncts),
GoalExpr = disj_rep(Disjuncts)
;
- GoalExpr0 = switch_rep(Var, Cases0),
+ GoalExpr0 = switch_rep(Var, CanFail, Cases0),
switch_annotate_coverage(Info, Detism, GoalPath, !Coverage,
Cases0, Cases),
- GoalExpr = switch_rep(Var, Cases)
+ GoalExpr = switch_rep(Var, CanFail, Cases)
;
GoalExpr0 = ite_rep(Cond0, Then0, Else0),
ite_annotate_coverage(Info, GoalPath, !Coverage, Cond0, Cond,
Index: mdbcomp/program_representation.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/program_representation.m,v
retrieving revision 1.38
diff -u -p -b -r1.38 program_representation.m
--- mdbcomp/program_representation.m 20 Sep 2008 11:38:05 -0000 1.38
+++ mdbcomp/program_representation.m 20 Sep 2008 13:42:47 -0000
@@ -174,6 +174,9 @@
var_rep,
% The variable being switched on.
+ switch_can_fail_rep,
+ % Completeness of the switch.
+
list(case_rep(GoalAnnotation))
% The switch arms in the original order.
)
@@ -221,6 +224,10 @@
:- type case_rep == case_rep(unit).
+:- type switch_can_fail_rep
+ ---> switch_can_fail
+ ; switch_can_not_fail.
+
:- type atomic_goal_rep
---> unify_construct_rep(
var_rep,
@@ -702,7 +709,7 @@ goal_generates_internal_event(goal_rep(G
goal_expr_generates_internal_event(conj_rep(_)) = no.
goal_expr_generates_internal_event(disj_rep(_)) = yes.
-goal_expr_generates_internal_event(switch_rep(_, _)) = yes.
+goal_expr_generates_internal_event(switch_rep(_, _, _)) = yes.
goal_expr_generates_internal_event(ite_rep(_, _, _)) = yes.
goal_expr_generates_internal_event(negation_rep(_)) = yes.
goal_expr_generates_internal_event(scope_rep(_, _)) = no.
@@ -880,8 +887,6 @@ determinism_representation(failure_rep,
determinism_representation(cc_nondet_rep, 10).
determinism_representation(cc_multidet_rep, 14).
-%-----------------------------------------------------------------------------%
-
goal_type_to_byte(Type) = TypeInt :-
goal_type_byte(TypeInt, Type).
@@ -1028,7 +1033,7 @@ read_prog_rep_file(FileName, Result, !IO
%
:- func procrep_id_string = string.
-procrep_id_string = "Mercury deep profiler procrep version 3\n".
+procrep_id_string = "Mercury deep profiler procrep version 4\n".
:- pred read_module_reps(bytecode::in,
module_map(unit)::in, module_map(unit)::out,
@@ -1220,9 +1225,10 @@ read_goal(VarNumRep, ByteCode, StringTab
GoalExpr = ite_rep(Cond, Then, Else)
;
GoalType = goal_switch,
+ read_switch_can_fail(ByteCode, CanFail, !Pos),
read_var(VarNumRep, ByteCode, Var, !Pos),
read_cases(VarNumRep, ByteCode, StringTable, Info, Cases, !Pos),
- GoalExpr = switch_rep(Var, Cases)
+ GoalExpr = switch_rep(Var, CanFail, Cases)
;
GoalType = goal_assign,
read_var(VarNumRep, ByteCode, Target, !Pos),
@@ -1523,6 +1529,25 @@ read_determinism(ByteCode, Detism, !Pos)
error("read_goal: bad detism")
).
+:- pred read_switch_can_fail(bytecode::in, switch_can_fail_rep::out,
+ int::in, int::out) is semidet.
+
+read_switch_can_fail(Bytecode, CanFail, !Pos) :-
+ read_byte(Bytecode, CanFailByte, !Pos),
+ (
+ (
+ CanFailByte = 0,
+ CanFailPrime = switch_can_fail
+ ;
+ CanFailByte = 1,
+ CanFailPrime = switch_can_not_fail
+ )
+ ->
+ CanFail = CanFailPrime
+ ;
+ error("read_goal: bad switch_can_fail")
+ ).
+
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
Index: runtime/mercury_deep_profiling.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_profiling.c,v
retrieving revision 1.32
diff -u -p -b -r1.32 mercury_deep_profiling.c
--- runtime/mercury_deep_profiling.c 13 Aug 2008 07:38:08 -0000 1.32
+++ runtime/mercury_deep_profiling.c 20 Sep 2008 13:42:47 -0000
@@ -711,7 +711,7 @@ MR_write_out_procrep_id_string(FILE *fp)
** Must be the same as procrep_id_string in
** mdbcomp/program_representation.m
*/
- const char *id_string = "Mercury deep profiler procrep version 3\n";
+ const char *id_string = "Mercury deep profiler procrep version 4\n";
fputs(id_string, fp);
}
Index: tests/debugger/declarative/builtin_call_rep.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/builtin_call_rep.exp,v
retrieving revision 1.6
diff -u -p -b -r1.6 builtin_call_rep.exp
--- tests/debugger/declarative/builtin_call_rep.exp 3 Sep 2008 01:22:45 -0000 1.6
+++ tests/debugger/declarative/builtin_call_rep.exp 21 Sep 2008 11:44:19 -0000
@@ -5,11 +5,11 @@ Command echo enabled.
mdb> step
E2: C2 CALL func int.+/2-0 (det)
mdb> print proc_body
- proc_defn_rep([1, 2, 3], goal_rep(atomic_goal_rep("int.m", NN, [|]/2, builtin_call_rep/3), det_rep), empty, det_rep)
+ proc_defn_rep([1, 2, 3], goal_rep(atomic_goal_rep("int.m", NN, [|]/2, builtin_call_rep/3), det_rep, unit), empty, det_rep)
mdb> browse proc_body
browser> cd 2
browser> ls
-goal_rep(atomic_goal_rep("int.m", NN, [3], builtin_call_rep("int", "+", [1, 2, 3])), det_rep)
+goal_rep(atomic_goal_rep("int.m", NN, [3], builtin_call_rep("int", "+", [1, 2, 3])), det_rep, unit)
browser> quit
mdb> f
E3: C2 EXIT func int.+/2-0 (det)
Index: tests/debugger/declarative/dependency.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/dependency.exp,v
retrieving revision 1.17
diff -u -p -b -r1.17 dependency.exp
--- tests/debugger/declarative/dependency.exp 3 Sep 2008 01:22:45 -0000 1.17
+++ tests/debugger/declarative/dependency.exp 21 Sep 2008 11:44:00 -0000
@@ -26,18 +26,16 @@ proc_defn_rep(
conj_rep(
[|](
goal_rep(
- atomic_goal_rep(
- "dependency.m",
- 20,
- [|](2, []),
- plain_call_rep("dependency", "p", [|](2, []))),
- det_rep),
+ atomic_goal_rep("dependency.m", 20, [|](2, []), plain_call_rep/3),
+ det_rep,
+ unit),
[|](
- goal_rep(ite_rep(goal_rep/2, goal_rep/2, goal_rep/2), det_rep),
+ goal_rep(ite_rep/3, det_rep, unit),
[|](
- goal_rep(atomic_goal_rep/4, det_rep),
- [|](goal_rep/2, [|](goal_rep/2, [|]/2)))))),
- cc_multidet_rep),
+ goal_rep(atomic_goal_rep/4, det_rep, unit),
+ [|](goal_rep/3, [|](goal_rep/3, [|]/2)))))),
+ cc_multidet_rep,
+ unit),
empty,
cc_multidet_rep)
mdb> dd -d 3 -n 7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20080921/7eed1f40/attachment.sig>
More information about the reviews
mailing list