[m-rev.] diff: nicer comments in .c files

Zoltan Somogyi zs at csse.unimelb.edu.au
Tue Dec 19 14:11:09 AEDT 2006


compiler/call_gen.m:
	If --auto-comment is set, mention the name of the predicate/function
	being called in the call comment. This is useful when the entry label
	being called has to be mangled.

compiler/code_info.m:
	Remember whether --auto-comment is set.

compiler/llds_out.m:
	Format comments more nicely.

Zoltan.

cvs diff: Diffing compiler
Index: compiler/call_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/call_gen.m,v
retrieving revision 1.188
diff -u -b -r1.188 call_gen.m
--- compiler/call_gen.m	14 Dec 2006 04:35:44 -0000	1.188
+++ compiler/call_gen.m	16 Dec 2006 17:38:10 -0000
@@ -103,7 +103,7 @@
     code_info.get_module_info(!.CI, ModuleInfo),
     Address = make_proc_entry_label(!.CI, ModuleInfo, PredId, ProcId, yes),
     code_info.get_next_label(ReturnLabel, !CI),
-    call_gen.call_comment(CodeModel, CallComment),
+    call_gen.call_comment(!.CI, PredId, CodeModel, CallComment),
     goal_info_get_context(GoalInfo, Context),
     goal_info_get_goal_path(GoalInfo, GoalPath),
     CallCode = node([
@@ -454,11 +454,31 @@
         FailHandlingCode = empty
     ).
 
-:- pred call_comment(code_model::in, string::out) is det.
+:- pred call_comment(code_info::in, pred_id::in, code_model::in, string::out)
+    is det.
 
-call_comment(model_det,  "branch to det procedure").
-call_comment(model_semi, "branch to semidet procedure").
-call_comment(model_non,  "branch to nondet procedure").
+call_comment(CI, PredId, CodeModel, Msg) :-
+    (
+        CodeModel = model_det,
+        BaseMsg = "branch to det procedure"
+    ;
+        CodeModel = model_semi,
+        BaseMsg = "branch to semidet procedure"
+    ;
+        CodeModel = model_non,
+        BaseMsg = "branch to nondet procedure"
+    ),
+    code_info.get_auto_comments(CI, AutoComments),
+    (
+        AutoComments = yes,
+        code_info.get_module_info(CI, ModuleInfo),
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
+        PredName = pred_info_name(PredInfo),
+        Msg = BaseMsg ++ " " ++ PredName
+    ;
+        AutoComments = no,
+        Msg = BaseMsg
+    ).
 
 %---------------------------------------------------------------------------%
 
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.337
diff -u -b -r1.337 code_info.m
--- compiler/code_info.m	7 Dec 2006 06:22:22 -0000	1.337
+++ compiler/code_info.m	16 Dec 2006 17:35:43 -0000
@@ -213,6 +213,8 @@
 
 :- pred get_opt_trail_ops(code_info::in, bool::out) is det.
 
+:- pred get_auto_comments(code_info::in, bool::out) is det.
+
 %---------------------------------------------------------------------------%
 
 :- implementation.
@@ -341,9 +343,12 @@
                 emit_trail_ops      :: bool,
                                     % Should we emit trail operations?
 
-                opt_trail_ops       :: bool
+                opt_trail_ops       :: bool,
                                     % Should we try to avoid emiting trail
                                     % operations?
+
+                auto_comments       :: bool
+                                    % The setting of --auto-comments.
             ).
 
 :- type code_info_loc_dep
@@ -510,6 +515,7 @@
         EmitTrailOps = no
     ),
     globals.lookup_bool_option(Globals, optimize_trail_usage, OptTrailOps),
+    globals.lookup_bool_option(Globals, auto_comments, AutoComments),
     CodeInfo0 = code_info(
         code_info_static(
             Globals,
@@ -523,7 +529,8 @@
             no,
             OptNoReturnCalls,
             EmitTrailOps,
-            OptTrailOps
+            OptTrailOps,
+            AutoComments
         ),
         code_info_loc_dep(
             Liveness,
@@ -586,6 +593,7 @@
 get_opt_no_return_calls(CI, CI ^ code_info_static ^ opt_no_resume_calls).
 get_emit_trail_ops(CI, CI ^ code_info_static ^ emit_trail_ops).
 get_opt_trail_ops(CI, CI ^ code_info_static ^ opt_trail_ops).
+get_auto_comments(CI, CI ^ code_info_static ^ auto_comments).
 get_forward_live_vars(CI, CI ^ code_info_loc_dep ^ forward_live_vars).
 get_instmap(CI, CI ^ code_info_loc_dep ^ instmap).
 get_zombies(CI, CI ^ code_info_loc_dep ^ zombies).
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.299
diff -u -b -r1.299 llds_out.m
--- compiler/llds_out.m	1 Dec 2006 15:04:03 -0000	1.299
+++ compiler/llds_out.m	18 Dec 2006 04:04:48 -0000
@@ -2131,7 +2131,7 @@
         ;
             io.write_string("\t\t/* ", !IO),
             io.write_string(Comment, !IO),
-            io.write_string("*/\n", !IO)
+            io.write_string(" */\n", !IO)
         )
     ).
 
cvs diff: Diffing compiler/notes
--------------------------------------------------------------------------
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