[m-rev.] diff: opt_debug improvement

Zoltan Somogyi zs at csse.unimelb.edu.au
Fri Nov 23 15:29:47 AEDT 2007


compiler/opt_debug.m:
	Dump instructions in blocks the same way we dump instructions outside
	blocks, to make it easier to understand the diff generated by the
	optimization phase that wraps instructions in blocks.

Zoltan.

Index: opt_debug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.200
diff -u -b -r1.200 opt_debug.m
--- opt_debug.m	19 Nov 2007 06:36:24 -0000	1.200
+++ opt_debug.m	22 Nov 2007 14:50:56 -0000
@@ -182,6 +182,36 @@
     io.nl(!IO),
     dump_instrs_2(Instrs, ProcLabel, PrintComments, !IO).
 
+    % Return a string representation of a list of instructions; the string
+    % is the same as what dump_instrs_2 would print. Returning it as a string
+    % is significantly more expensive (due to all the string appends required),
+    % but we use dump_instrs only for printing blocks, whose size should be
+    % naturally limited.
+    %
+:- func dump_instrs(proc_label, bool, list(instruction)) = string.
+
+dump_instrs(_ProcLabel, _PrintComments, []) = "".
+dump_instrs(ProcLabel, PrintComments, [Instr | Instrs]) = Str :-
+    Instr = llds_instr(Uinstr, Comment),
+    ( Uinstr = label(_) ->
+        InstrStr0 = dump_instr(ProcLabel, PrintComments, Uinstr)
+    ; Uinstr = comment(InstrComment) ->
+        string.foldl(dump_comment_char, InstrComment, "", InstrCommentStr),
+        InstrStr0 = "\t% " ++ InstrCommentStr
+    ;
+        InstrStr0 = "\t" ++ dump_instr(ProcLabel, PrintComments, Uinstr)
+    ),
+    (
+        PrintComments = yes,
+        Comment \= ""
+    ->
+        InstrStr = InstrStr0 ++ "\n\t\t" ++ Comment ++ "\n"
+    ;
+        InstrStr = InstrStr0 ++ "\n"
+    ),
+    InstrsStr = dump_instrs(ProcLabel, PrintComments, Instrs),
+    Str = InstrStr ++ InstrsStr.
+
 :- pred print_comment_char(char::in, io::di, io::uo) is det.
 
 print_comment_char(C, !IO) :-
@@ -191,6 +221,15 @@
         io.write_char(C, !IO)
     ).
 
+:- pred dump_comment_char(char::in, string::in, string::out) is det.
+
+dump_comment_char(C, !Str) :-
+    ( C = '\n' ->
+        !:Str = !.Str ++ "\n\t% "
+    ;
+        !:Str = !.Str ++ string.char_to_string(C)
+    ).
+
 dump_intlist([]) = "".
 dump_intlist([H | T]) =
     " " ++ int_to_string(H) ++ dump_intlist(T).
@@ -651,7 +690,7 @@
         Instr = block(RTemps, FTemps, Instrs),
         Str = "block(" ++ int_to_string(RTemps) ++ ", "
             ++ int_to_string(FTemps) ++ ",\n"
-            ++ dump_fullinstrs(ProcLabel, PrintComments, Instrs)
+            ++ dump_instrs(ProcLabel, PrintComments, Instrs)
             ++ ")"
     ;
         Instr = assign(Lval, Rval),
--------------------------------------------------------------------------
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