[m-rev.] for review: initialise mercury runtime on .NET fixes
Peter Ross
pro at missioncriticalit.com
Wed Oct 15 23:15:46 AEST 2003
Hi,
===================================================================
Estimated hours taken: 8
Branches: main
Ensure that the mercury runtime is always initialised on the .NET
backend, regardless of whether Mercury is used as a library or an
executable.
runtime/mercury_il.il:
Change the mercury.runtime.Init class so that it can be called
multiple times, but that the runtime will only be initialised
once.
compiler/mlds_to_il.m:
Change the .cctor of mercury_code so that it calls the new
mercury.runtime.Init methods in the correct order.
library/private_builtin.m:
Remove the now unused init_runtime routine.
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.131
diff -u -r1.131 mlds_to_il.m
--- compiler/mlds_to_il.m 17 Jul 2003 14:40:22 -0000 1.131
+++ compiler/mlds_to_il.m 15 Oct 2003 13:07:37 -0000
@@ -1074,7 +1074,7 @@
{ MaybeSeqNum = no }
->
{ EntryPoint = [entrypoint] },
- il_info_add_init_instructions(runtime_initialization_instrs),
^ has_main := yes,
il_info_get_next_block_id(InnerTryBlockId),
@@ -2857,6 +2857,8 @@
{ Method = method(methodhead([public, static], cctor,
signature(call_conv(no, default), void, []), []),
MethodDecls) },
+ { MaybeInitRuntimeInstrs = maybe_init_runtime_instrs },
+ { RuntimeInitInstrs = runtime_initialization_instrs },
test_rtti_initialization_field(DoneFieldRef, TestInstrs),
set_rtti_initialization_field(DoneFieldRef, SetInstrs),
{ CCtorCalls = list__filter_map(
@@ -2866,8 +2868,9 @@
C = call_class_constructor(
class_name(ImportName, wrapper_class_name))
), Imports) },
- { AllInstrs = list__condense([TestInstrs, AllocInstrs, SetInstrs,
- CCtorCalls, InitInstrs, [ret]]) },
+ { AllInstrs = list__condense([MaybeInitRuntimeInstrs,
+ TestInstrs, AllocInstrs, SetInstrs,
+ CCtorCalls, InitInstrs, RuntimeInitInstrs, [ret]]) },
{ MethodDecls = [instrs(AllInstrs)] }.
:- pred test_rtti_initialization_field(fieldref, list(instr),
@@ -2876,7 +2879,7 @@
test_rtti_initialization_field(FieldRef, Instrs) -->
il_info_make_next_label(DoneLabel),
{ Instrs = [ldsfld(FieldRef), brfalse(label_target(DoneLabel)),
- ret, label(DoneLabel)] }.
+ pop, ret, label(DoneLabel)] }.
:- pred set_rtti_initialization_field(fieldref, list(instr),
il_info, il_info).
@@ -3832,6 +3835,11 @@
error("no value class for native uint").
%-----------------------------------------------------------------------------%
+
+:- func il_bool_type = ilds__type.
+il_bool_type = simple_type_to_valuetype(bool).
+
+%-----------------------------------------------------------------------------%
%
% The mapping of the string type.
%
@@ -4191,21 +4199,28 @@
make_fieldref(ILType, ClassName, Id) =
fieldref(ILType, class_member_name(ClassName, id(Id))).
-
+:- func maybe_init_runtime_instrs = list(instr).
+maybe_init_runtime_instrs = [
+ call(get_static_methodref(runtime_init_module_name,
+ maybe_init_runtime_method_name, simple_type(bool), []))
+ ].
:- func runtime_initialization_instrs = list(instr).
runtime_initialization_instrs = [
call(get_static_methodref(runtime_init_module_name,
- runtime_init_method_name, void, []))
+ runtime_init_method_name, void, [il_bool_type]))
].
:- func runtime_init_module_name = ilds__class_name.
runtime_init_module_name =
structured_name(assembly("mercury"),
- ["mercury", "private_builtin__cpp_code", wrapper_class_name], []).
+ ["mercury", "runtime", "Init"], []).
:- func runtime_init_method_name = ilds__member_name.
runtime_init_method_name = id("init_runtime").
+
+:- func maybe_init_runtime_method_name = ilds__member_name.
+maybe_init_runtime_method_name = id("responsible_for_initialising_runtime").
%-----------------------------------------------------------------------------%
%
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.123
diff -u -r1.123 private_builtin.m
--- library/private_builtin.m 25 Jul 2003 06:05:52 -0000 1.123
+++ library/private_builtin.m 15 Oct 2003 13:07:38 -0000
@@ -590,11 +590,6 @@
dynamic_cast<MR_Word>(y));
}
-static void init_runtime(void)
-{
- mercury::runtime::Init::init_runtime();
-}
-
").
:- pragma foreign_proc("C",
Index: runtime/mercury_il.il
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_il.il,v
retrieving revision 1.21
diff -u -r1.21 mercury_il.il
--- runtime/mercury_il.il 5 Mar 2003 15:55:22 -0000 1.21
+++ runtime/mercury_il.il 15 Oct 2003 13:07:40 -0000
@@ -605,17 +605,49 @@
}
-// Call init_state/2 in the IO module.
-// This gets called before main runs.
-// It has to be written in IL because we call something that might not
-// yet be available in a .DLL.
+// The init class is responsible for ensuring that the mercury runtime
+// is initialised before the first piece of Mercury code is executed.
+// This is done by calling responsible_for_initialising_runtime as the first
+// thing and init_runtime as the last thing in each .cctor for every
+// mercury_code class.
+// XXX These routines needs to be made thread safe!
.class public 'Init' {
- .method public static default void init_runtime() {
- tail.
+
+ .method public static default void .cctor()
+ {
+ ldc.i4.1
+ stsfld bool [mercury]mercury.runtime.Init::will_initialise_runtime
+ ret
+ }
+
+ .method public static default bool responsible_for_initialising_runtime() {
+ ldsfld bool [mercury]mercury.runtime.Init::will_initialise_runtime
+ brfalse false_branch
+
+ true_branch:
+ ldc.i4.0
+ stsfld bool [mercury]mercury.runtime.Init::will_initialise_runtime
+ ldc.i4.1
+ ret
+
+ false_branch:
+ ldc.i4.0
+ ret
+ }
+
+ .method public static default void init_runtime(bool initialise) {
+ ldarg initialise
+ brtrue true_branch
+ ret
+
+ true_branch:
call void ['mercury']mercury.io.mercury_code::init_state_2()
ret
}
+
+
+ .field private static bool will_initialise_runtime
}
--
Peter Ross
Software Engineer (Work) +32 2 757 10 15
Mission Critical (Mobile) +32 485 482 559
--------------------------------------------------------------------------
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