[m-dev.] diff: Fix a couple of bugs in Morphine-collect.
Erwan Jahier
Erwan.Jahier at irisa.fr
Wed Aug 16 19:11:19 AEST 2000
Estimated hours taken: 2
Fix a couple of bugs in Morphine-collect.
extras/morphine/source/collect.in:
Import the `int' module as it is needed by the integer
event attributes.
extras/morphine/source/collect.op:
Fix a bug: when the dynamic linking betwenn collect.so and
the current execution fails, it does not recompile the collect
module. To force its recompilation, we ``touch'' the collect source
file to make it younger than its corresponding .so file.
Add a #1 directive so that the error message eventually produced
during the compilation of collect.m indicates a line number
that makes sense.
Index: collect.in
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/morphine/source/collect.in,v
retrieving revision 1.2
diff -u -r1.2 collect.in
--- collect.in 1999/12/20 14:44:11 1.2
+++ collect.in 2000/08/16 09:01:55
@@ -37,7 +37,7 @@
:- pragma export(collected_variable_type(out),
"ML_COLLECT_collecting_variable_type").
-:- import_module int, io, std_util.
+:- import_module list, int, io, std_util.
:- type event_number == int.
:- type call_number == int.
Index: collect.op
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/morphine/source/collect.op,v
retrieving revision 1.4
diff -u -r1.4 collect.op
--- collect.op 1999/12/20 14:44:11 1.4
+++ collect.op 2000/08/16 09:01:56
@@ -14,7 +14,7 @@
% initialize/1 and filter/4,
% 2) generate `collect.m' from this file (generate_collect/1),
% 3) compile collect.m (compile_collect/0),
-% 4) dynamically link it with the current execution (dyn_link_collect/0).
+% 4) dynamically link it with the current execution (dyn_link_collect/2).
% 5) run the command (run_command/1).
opium_scenario(
@@ -106,7 +106,7 @@
mode_number).\n\
:- type arguments == list(univ).\n\
\n\
-Here are functions that eases the access of the event attributes:\n\
+Here are functions that eases the access to event attributes:\n\
\n\
:- func chrono(event::in) = (event_number::out) is det.\n\
:- func call(event::in) = (call_number::out) is det.\n\
@@ -185,13 +185,13 @@
check_a_program_is_running("collect/2"),
(
% File might be an atom or a string.
- string(File),
- append_strings(File, ".so", File_so),
- !
+ string(File)
+ ->
+ File = FileStr
;
- atom_string(File, FileStr),
- append_strings(FileStr, ".so", File_so)
+ atom_string(File, FileStr)
),
+ append_strings(FileStr, ".so", File_so),
(
% We don't generate again collect.so if the collect input
% file has already been collected and if it has not been
@@ -208,7 +208,7 @@
concat_string(["cp collect.so ", File_so], Cmd2),
sh(Cmd2)
),
- dyn_link_collect,
+ dyn_link_collect(FileStr, File_so),
run_collect(Result).
%------------------------------------------------------------------------------%
@@ -316,11 +316,15 @@
write(collect, ":- mode acc_in :: in.\n"),
write(collect, ":- mode acc_out :: out.\n\n")
),
+ % #1 is a directive to mmc so that mmc believes that the first line
+ % begins here. This is to have more sensible line numbers if the
+ % compilation of collect.m fails for some reasons.
+ write(collect, "#1\n"),
write(collect, Body),
close(collect),
close(collect_in).
+
-
% Check if there is a mode definition of `acc_in' and `acc_out' in the
% file `File'. Those are to let users specify di and uo as modes for filter.
is_there_any_mode_declaration(File) :-
@@ -357,16 +361,16 @@
%------------------------------------------------------------------------------%
opium_primitive(
name : dyn_link_collect,
- arg_list : [],
- arg_type_list : [],
+ arg_list : [File, FileSo],
+ arg_type_list : [is_string, is_string],
abbrev : _,
implementation : dyn_link_collect_Op,
message :
"Dynamically links the collect module with the currently run program."
).
-dyn_link_collect_Op :-
- check_a_program_is_running("dyn_link_collect/0"),
+dyn_link_collect_Op(File, FileSo) :-
+ check_a_program_is_running("dyn_link_collect/2"),
(
exists("collect.so"),
!
@@ -388,17 +392,29 @@
% if the Mercury program has been compiled in another grade, the
% linking will fail here. So if it fails, we recompile the collect
% module and try again.
+ touch(File), % to make sure it really recompiles it
+ print("Because the dynamic linking failed for some reasons, "),
+ print("we recompile the collect module and retry.\n"),
+ generate_collect(File),
compile_collect,
+ concat_string(["cp collect.so ", FileSo], Cmd3),
+ sh(Cmd3),
send_message_to_socket(link_collect("\"./collect.so\"")),
read_message_from_socket(Result2),
( Result2 = link_collect_succeeded ->
- morphine_write_debug("collect.so has been linked successfully.\n")
+ morphine_write_debug("collect.so has been linked "),
+ morphine_write_debug("successfully this time.\n")
;
print("**** collect.so has not been linked.\n"),
abort
)
).
+touch(File) :-
+ append_strings("touch ", File, Cmd),
+ morphine_write_debug(Cmd),
+ sh(Cmd).
+
%------------------------------------------------------------------------------%
opium_primitive(
@@ -456,7 +472,7 @@
CollectLinked == collect_not_linked,
print("You can't call run_collect/1; "),
print("The collect module has not been linked with "),
- print("the current execution (cf dyn_link_collect/0).\n"),
+ print("the current execution (cf dyn_link_collect/2).\n"),
!,
fail
;
--
R1.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list