[m-rev.] for review: module to read trace counts (2)
Peter Wang
wangp at students.cs.mu.OZ.AU
Tue Jan 18 13:42:17 AEDT 2005
On Friday 14 January 2005 05:40 pm, Zoltan Somogyi wrote:
> On 14-Jan-2005, Peter Wang <wangp at students.cs.mu.OZ.AU> wrote:
> > I think the name mdbcomp__proc_id is just wrong, given what's now inside.
> > I can rename it easily at this point with a search & replace on the diff,
> > if there are suggestions.
>
> How about mdbcomp__prim_data?
Ok, done.
> > +% XXX: This is duplicated in browser/util.m but moving that in here
> > means this +% module will need to be imported into most of the debugger,
> > which has a +% conflicting definition of module_name.
>
> The right solution that would be to rename every occurrence of
> "module_name" that uses mdb's definition to use a different name, maybe
> "flat_module_name". You should always avoid duplication of types unless
> there is no other choice; that isn't the case here.
Done.
There was a duplicate definition of special_pred_id in the debugger, except
that the debugger's version had three function symbols instead of four.
I've made the debugger use the four-function-symbol definition now. I just
need the okay on that before committing.
Below is a partial diff containing the more important changes since the
last one.
Peter
For review by anyone.
Estimated hours taken: 17
This adds a module mdbcomp__trace_counts that reads in the
.mercury_trace_counts files produced by the compiler's trace mechanism.
The format of said files was slightly changed.
As the new module is to be used by the compiler and the debugger, it is
placed in the mdbcomp module. This required bringing some types from the
compiler into a new module within mdbcomp.
browser/trace_counts.m:
New module for reading execution trace summaries.
browser/prim_data.m:
New module holding types and predicates moved in from the compiler.
Types:
pred_or_func, sym_name, module_name, proc_label,
special_pred_id, trace_port
Predicates:
string_to_sym_name, insert_module_qualifier
The mode field of proc_label is now an int instead of a proc_id
to avoid pulling proc_id into mdbcomp.
mdb's trace_port_type was a duplicate of the trace_port type,
so has been removed in favour of the latter.
browser/mdbcomp.m:
Add trace_counts and prim_data to the mdbcomp module.
browser/declarative_execution.m:
Renamed mdb's definition of module_name to flat_module_name
to avoid conflicts with the definition in mdbcomp__prim_data.
runtime/mercury_trace_base.c:
In the format of .mercury_trace_counts, write module and predicate
names now use quoted atom syntax so that names with spaces and
non-printable characters can be machine-parsed.
browser/:
compiler/:
Many changes to account for movement and changes of types, and the
change to proc_label.
Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.20
diff -u -r1.20 debugger_interface.m
--- browser/debugger_interface.m 27 Oct 2003 06:24:43 -0000 1.20
+++ browser/debugger_interface.m 17 Jan 2005 23:51:35 -0000
@@ -34,6 +34,7 @@
:- import_module list, bool, std_util.
:- import_module mdb__interactive_query.
:- import_module mdb__util.
+:- import_module mdbcomp__prim_data.
:- import_module io, require.
@@ -83,7 +84,7 @@
match(event_number),
match(call_number),
match(depth_number),
- match(trace_port_type),
+ match(trace_port),
pred_match,
match(string), % definition module name
match(string), % pred name
@@ -191,7 +192,7 @@
event_number,
call_number,
depth_number,
- trace_port_type,
+ trace_port,
pred_or_func,
string, % declaration module name
string, % definition module name
@@ -207,7 +208,7 @@
event_number,
call_number,
depth_number,
- trace_port_type,
+ trace_port,
string, % name type
string, % module type
string, % definition module
@@ -283,7 +284,7 @@
in, in, in, in, in, in, di, uo), "ML_DI_output_current_slots_user").
:- pred output_current_slots_user(event_number, call_number, depth_number,
- trace_port_type, pred_or_func, /* declarated module name */ string,
+ trace_port, pred_or_func, /* declarated module name */ string,
/* definition module name */ string, /* pred name */ string, arity,
/* mode num */ int, determinism, goal_path_string, line_number,
io__output_stream, io__state, io__state).
@@ -310,7 +311,7 @@
in, in, in, in, in, in, in, di, uo), "ML_DI_output_current_slots_comp").
:- pred output_current_slots_comp(event_number, call_number, depth_number,
- trace_port_type, /* name type */ string, /* module type */ string,
+ trace_port, /* name type */ string, /* module type */ string,
/* definition module */ string, /* pred name */ string, arity,
/* mode num */ int, determinism, goal_path_string, line_number,
io__output_stream, io__state, io__state).
@@ -407,7 +408,7 @@
in, in, in), "ML_DI_found_match_user").
:- pred found_match_user(event_number, call_number, depth_number,
- trace_port_type, pred_or_func, /* declarated module name */ string,
+ trace_port, pred_or_func, /* declarated module name */ string,
/* defined module name */ string, /* pred name */ string, arity,
/* mode num */ int, determinism, /* the arguments */ list(univ),
% XXX we could provide better ways of
@@ -472,7 +473,7 @@
in, in, in), "ML_DI_found_match_comp").
:- pred found_match_comp(event_number, call_number, depth_number,
- trace_port_type, /* name type */ string, /* module type */ string,
+ trace_port, /* name type */ string, /* module type */ string,
/* definition module name */ string, /* pred name */ string, arity,
/* mode num */ int, determinism, /* the arguments */ list(univ),
% XXX we could provide better ways of
Index: browser/declarative_execution.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_execution.m,v
retrieving revision 1.30
diff -u -r1.30 declarative_execution.m
--- browser/declarative_execution.m 9 Jan 2005 01:14:02 -0000 1.30
+++ browser/declarative_execution.m 17 Jan 2005 23:53:32 -0000
@@ -19,6 +19,7 @@
:- interface.
:- import_module mdb__util.
+:- import_module mdbcomp__prim_data.
:- import_module mdbcomp__program_representation.
:- import_module list, std_util, io, bool.
@@ -194,29 +195,24 @@
% A module name should consist of a base name and a list of the names
% of the enclosing modules. For now, we have them all in one string.
-:- type module_name == string.
-
-:- type special_pred_id
- ---> unify
- ; index
- ; compare.
+:- type flat_module_name == string.
:- type proc_id
---> proc(
- module_name, % defining module
+ flat_module_name, % defining module
pred_or_func,
- module_name, % declaring module
- string, % name
- int, % arity
- int % mode number
+ flat_module_name, % declaring module
+ string, % name
+ int, % arity
+ int % mode number
)
; uci_proc(
- module_name, % defining module
- special_pred_id,% indirectly defines pred name
- module_name, % type module
- string, % type name
- int, % type arity
- int % mode number
+ flat_module_name, % defining module
+ special_pred_id, % indirectly defines pred name
+ flat_module_name, % type module
+ string, % type name
+ int, % type arity
+ int % mode number
).
% Should be a foreign type, MR_Proc_Layout *. This is a
@@ -582,12 +578,14 @@
get_special_pred_id_name(unify) = "__Unify__".
get_special_pred_id_name(index) = "__Index__".
get_special_pred_id_name(compare) = "__Compare__".
+get_special_pred_id_name(initialise) = "__Initialise__".
:- func get_special_pred_id_arity(special_pred_id) = int.
get_special_pred_id_arity(unify) = 2.
get_special_pred_id_arity(index) = 2.
get_special_pred_id_arity(compare) = 3.
+get_special_pred_id_arity(initialise) = 1.
get_pred_attributes(ProcId, Module, Name, Arity, PredOrFunc) :-
(
@@ -946,7 +944,7 @@
store__set_ref_value(ArgRef, Val, S2, S),
store__extract_ref_value(S, Ref, Node).
-:- func trace_node_port(trace_node(trace_node_id)) = trace_port_type.
+:- func trace_node_port(trace_node(trace_node_id)) = trace_port.
:- pragma export(trace_node_port(in) = out,
"MR_DD_trace_node_port").
Index: browser/declarative_oracle.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_oracle.m,v
retrieving revision 1.31
diff -u -r1.31 declarative_oracle.m
--- browser/declarative_oracle.m 5 Jan 2005 12:25:54 -0000 1.31
+++ browser/declarative_oracle.m 17 Jan 2005 23:54:43 -0000
@@ -123,6 +123,7 @@
:- import_module mdb__tree234_cc.
:- import_module mdb__set_cc.
:- import_module mdb__util.
+:- import_module mdbcomp__prim_data.
:- import_module map, bool, std_util, set, int, bimap, counter, assoc_list,
exception, list.
Index: browser/declarative_tree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_tree.m,v
retrieving revision 1.13
diff -u -r1.13 declarative_tree.m
--- browser/declarative_tree.m 9 Jan 2005 01:14:02 -0000 1.13
+++ browser/declarative_tree.m 17 Jan 2005 23:55:29 -0000
@@ -43,6 +43,7 @@
:- import_module mdb__declarative_debugger.
:- import_module mdb__io_action.
+:- import_module mdbcomp__prim_data.
:- import_module mdbcomp__program_representation.
:- import_module mdb__util.
@@ -1576,7 +1577,7 @@
---> plain_call_info(
file_name :: string,
line_number :: int,
- module_name :: string,
+ flat_module_name:: string,
pred_name :: string
).
Index: browser/declarative_user.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_user.m,v
retrieving revision 1.34
diff -u -r1.34 declarative_user.m
--- browser/declarative_user.m 6 Jan 2005 03:20:09 -0000 1.34
+++ browser/declarative_user.m 17 Jan 2005 23:55:55 -0000
@@ -70,6 +70,7 @@
:- import_module mdb__io_action.
:- import_module mdb__util.
:- import_module mdb__declarative_execution.
+:- import_module mdbcomp__prim_data.
:- import_module mdbcomp__program_representation.
:- import_module mdb.parse.
Index: browser/io_action.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/io_action.m,v
retrieving revision 1.5
diff -u -r1.5 io_action.m
--- browser/io_action.m 9 Aug 2004 03:05:20 -0000 1.5
+++ browser/io_action.m 17 Jan 2005 23:14:37 -0000
@@ -16,8 +16,8 @@
:- interface.
-:- import_module mdb__util.
:- import_module mdb__browser_term.
+:- import_module mdbcomp__prim_data.
:- import_module list, map, std_util, io.
:- type io_action
Index: browser/mdbcomp.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/mdbcomp.m,v
retrieving revision 1.1
diff -u -r1.1 mdbcomp.m
--- browser/mdbcomp.m 27 Oct 2003 06:00:32 -0000 1.1
+++ browser/mdbcomp.m 17 Jan 2005 23:44:51 -0000
@@ -20,7 +20,9 @@
:- pred mdbcomp__version(string::out) is det.
+:- include_module prim_data.
:- include_module program_representation.
+:- include_module trace_counts.
:- implementation.
Index: browser/prim_data.m
===================================================================
RCS file: browser/prim_data.m
diff -N browser/prim_data.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ browser/prim_data.m 17 Jan 2005 23:45:18 -0000
@@ -0,0 +1,149 @@
+%-----------------------------------------------------------------------------%
+% Copyright (C) 2005 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: prim_data.m.
+% Main authors: fjh, zs.
+%
+% This module contains some types and predicates that are, or are planned to
+% be, shared between the compiler and the debugger.
+
+%-----------------------------------------------------------------------------%
+
+:- module mdbcomp__prim_data.
+
+:- interface.
+
+% was in browser/util.m and compiler/prog_data.m
+
+ % This enumeration must be EXACTLY the same as the MR_PredFunc enum
+ % in runtime/mercury_stack_layout.h, and in the same order, since the
+ % code (in browser) assumes the representation is the same.
+
+:- type pred_or_func
+ ---> predicate
+ ; function.
+
+% was in browser/util.m and compiler/trace_params.m
+
+ % The kinds of events with which MR_trace may be called, either
+ % by compiler-generated code, or by code in the standard library
+ % referring to compiler-generated data structures.
+ %
+ % This enumeration must be EXACTLY the same as the MR_trace_port enum
+ % in runtime/mercury_trace_base.h, and in the same order, since the
+ % code (in browser) assumes the representation is the same.
+
+:- type trace_port
+ ---> call
+ ; exit
+ ; redo
+ ; fail
+ ; exception
+ ; ite_cond
+ ; ite_then
+ ; ite_else
+ ; neg_enter
+ ; neg_success
+ ; neg_failure
+ ; disj
+ ; switch
+ ; nondet_pragma_first
+ ; nondet_pragma_later
+ .
+
+% was in compiler/prog_data.m
+
+:- type sym_name
+ ---> qualified(sym_name, string)
+ ; unqualified(string).
+
+:- type module_name == sym_name.
+
+% was in compiler/proc_label.m
+
+ % A proc_label is a data structure a backend can use to as the basis
+ % of the label used as the entry point of a procedure.
+ %
+ % The defining module is the module that provides the code for the
+ % predicate, the declaring module contains the `:- pred' declaration.
+ % When these are different, as for specialised versions of predicates
+ % from `.opt' files, the defining module's name may need to be added
+ % as a qualifier to the label.
+
+:- type proc_label
+ ---> proc(
+ module_name, % defining module
+ pred_or_func,
+ module_name, % declaring module
+ string, % name
+ int, % arity
+ int % mode number
+ )
+ ; special_proc(
+ module_name, % defining module
+ special_pred_id,% indirectly defines pred name
+ module_name, % type module
+ string, % type name
+ int, % type arity
+ int % mode number
+ ).
+
+% was in compiler/special_pred.m
+
+:- type special_pred_id
+ ---> unify
+ ; index
+ ; compare
+ ; initialise.
+
+% was in compiler/prog_util.m
+
+ % string_to_sym_name(String, Separator, SymName):
+ % Convert a string, possibly prefixed with
+ % module qualifiers (separated by Separator),
+ % into a symbol name.
+ %
+:- pred string_to_sym_name(string::in, string::in, sym_name::out) is det.
+
+ % insert_module_qualifier(ModuleName, SymName0, SymName):
+ % prepend the specified ModuleName onto the module
+ % qualifiers in SymName0, giving SymName.
+:- pred insert_module_qualifier(string::in, sym_name::in, sym_name::out)
+ is det.
+
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int, string.
+
+% This would be simpler if we had a string__rev_sub_string_search/3 pred.
+% With that, we could search for underscores right-to-left,
+% and construct the resulting symbol directly.
+% Instead, we search for them left-to-right, and then call
+% insert_module_qualifier to fix things up.
+
+string_to_sym_name(String, ModuleSeparator, Result) :-
+ (
+ string__sub_string_search(String, ModuleSeparator, LeftLength),
+ LeftLength > 0
+ ->
+ string__left(String, LeftLength, ModuleName),
+ string__length(String, StringLength),
+ string__length(ModuleSeparator, SeparatorLength),
+ RightLength = StringLength - LeftLength - SeparatorLength,
+ string__right(String, RightLength, Name),
+ string_to_sym_name(Name, ModuleSeparator, NameSym),
+ insert_module_qualifier(ModuleName, NameSym, Result)
+ ;
+ Result = unqualified(String)
+ ).
+
+insert_module_qualifier(ModuleName, unqualified(PlainName),
+ qualified(unqualified(ModuleName), PlainName)).
+insert_module_qualifier(ModuleName, qualified(ModuleQual0, PlainName),
+ qualified(ModuleQual, PlainName)) :-
+ insert_module_qualifier(ModuleName, ModuleQual0, ModuleQual).
Index: browser/util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/util.m,v
retrieving revision 1.25
diff -u -r1.25 util.m
--- browser/util.m 14 Dec 2004 03:45:53 -0000 1.25
+++ browser/util.m 17 Jan 2005 23:31:07 -0000
@@ -8,42 +8,15 @@
:- interface.
-:- import_module list, string, io, bool.
-
-% The stuff defined below is similar to types goal_path and trace_port
-% defined in modules compiler/hlds_goal.m and compiler/trace.m.
-% This enumeration must be EXACTLY the same as the MR_trace_port enum in
-% runtime/mercury_trace_base.h, and in the same order, since the code
-% assumes the representation is the same.
-
-:- type trace_port_type
- ---> call
- ; exit
- ; redo
- ; fail
- ; exception
- ; ite_cond
- ; ite_then
- ; ite_else
- ; neg_enter
- ; neg_success
- ; neg_failure
- ; disj
- ; switch
- ; nondet_pragma_first
- ; nondet_pragma_later
- .
+:- import_module mdbcomp__prim_data.
-% This enumeration must be EXACTLY the same as the MR_PredFunc enum in
-% runtime/mercury_stack_layout.h, and in the same order, since the code
-% assumes the representation is the same.
-
-:- type pred_or_func
- ---> predicate
- ; function.
+:- import_module list, string, io, bool.
:- func util__is_predicate(pred_or_func) = bool.
:- func util__is_function(pred_or_func) = bool.
+
+% This is similar to the type goal_path defined in the module
+% compiler/hlds_goal.m.
:- type goal_path_string == string.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list