[m-dev.] for review: initialize global IO data structures in IL backend

Tyson Dowd trd at cs.mu.OZ.AU
Mon Nov 6 20:58:28 AEDT 2000


Hi,

Some samples that use lots of file streams in the IL backend means I
had to deal with initializing the global IO data structures.
Therefore: 

===================================================================

Estimated hours taken: 1.5

compiler/mlds_to_il.m:
	If the module contains main/2, generate a call to the initialization
	function for the io library in the class constructor for this module.
	This isn't a perfect solution (it isn't quite a flexible as the
	init.c approach if you have more than one main module that contains a 
	main/2 predicate) but it works well enough at the moment.

	Also, switch to using DCG versions of the field selection and update
	syntax, as this is nicer than using =(Info) and dcg_set.

Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.3
diff -u -r1.3 mlds_to_il.m
--- compiler/mlds_to_il.m	2000/10/22 07:27:20	1.3
+++ compiler/mlds_to_il.m	2000/11/06 09:48:49
@@ -291,14 +291,16 @@
 			{ InstrsTree0 = empty }
 		),
 
-			% If this is main, add the entrypoint and set a
-			% flag.
+			% If this is main, add the entrypoint, set a
+			% flag, and call the initialization instructions
+			% in the cctor of this module.
 		( { PredLabel = pred(predicate, no, "main", 2) },
 		  { MaybeSeqNum = no }
 		->
 			{ EntryPoint = [entrypoint] },
-			=(Info10),
-			dcg_set(Info10 ^ has_main := yes)
+			il_info_add_init_instructions(
+				io_initialization_instrs),
+			^ has_main := yes
 		;
 			{ EntryPoint = [] }
 		),
@@ -902,19 +904,18 @@
 
 atomic_statement_to_il(target_code(_Lang, _Code), node(Instrs)) --> 
 	il_info_get_module_name(ModuleName),
-	=(Info),
-	( { Info ^ method_c_code = no } ->
-		dcg_set(Info ^ method_c_code := yes),
+	( no =^ method_c_code  ->
+		^ method_c_code := yes,
 		{ mangle_dataname_module(no, ModuleName, NewModuleName) },
 		{ ClassName = mlds_module_name_to_class_name(NewModuleName) },
-		{ Info ^ signature = signature(_, RetType, Params) }, 
+		signature(_, RetType, Params) =^ signature, 
 			% If there is a return value, put it in succeeded.
 		{ RetType = void ->
 			StoreReturnInstr = []
 		;
 			StoreReturnInstr = [stloc(name("succeeded"))]
 		},
-		{ Info ^ method_name = MethodName },
+		MethodName =^ method_name,
 		{ assoc_list__keys(Params, TypeParams) },
 		{ list__map_foldl((pred(_::in, Instr::out,
 			Num::in, Num + 1::out) is det :-
@@ -2466,6 +2467,20 @@
 :- func make_fieldref(ilds__type, ilds__class_name, ilds__id) = fieldref.
 make_fieldref(ILType, ClassName, Id) = 
 	fieldref(ILType, class_member_name(ClassName, id(Id))).
+
+
+
+:- func io_initialization_instrs = list(instr).
+io_initialization_instrs = [
+	call(get_static_methodref(io_init_module_name, 
+			io_init_method_name, void, []))
+	].
+
+:- func io_init_module_name = ilds__class_name.
+io_init_module_name = ["mercury", "io"].
+
+:- func io_init_method_name = ilds__member_name.
+io_init_method_name = id("init_state_2_p_0").
 
 %-----------------------------------------------------------------------------%
 %


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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