[m-rev.] diff: fix exception.il dummyvar bug.

Tyson Dowd trd at cs.mu.OZ.AU
Wed Apr 11 01:25:35 AEST 2001


Hi,

This is another fix from the March DevLab.

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


Estimated hours taken: 2
Branches: main dotnet-foreign

compiler/mlds_to_il.m:
	Handle lvals more intelligently -- now that type information is
	available, we no longer need to guess about types of non-local
	vars that are sometimes used in lvals.  Also we need to
	handle non-local vars when storing to lvals.

	A side effect of this fix is that references to
	private_builtin::dummy_var now have the correct type, and are
	handled correctly, which fixes a bug where exception.il refused
	to assemble because it was referencing a local variable called
	"dummy_var".

library/private_builtin.m:
	Add a definition of dummy_var.


Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.16
diff -u -r1.16 mlds_to_il.m
--- compiler/mlds_to_il.m	2001/04/10 13:51:07	1.16
+++ compiler/mlds_to_il.m	2001/04/10 14:12:15
@@ -1170,24 +1170,15 @@
 :- mode load(in, out, in, out) is det.
 
 load(lval(Lval), Instrs, Info0, Info) :- 
-	( Lval = var(Var, _),
+	( Lval = var(Var, VarType),
 		mangle_mlds_var(Var, MangledVarStr),
 		( is_local(MangledVarStr, Info0) ->
 			Instrs = instr_node(ldloc(name(MangledVarStr)))
 		; is_argument(Var, Info0) ->
 			Instrs = instr_node(ldarg(name(MangledVarStr)))
 		;
-			% XXX RTTI generates vars which are references
-			% to other modules!
-			Var = qual(ModuleName, _),
-			mangle_dataname_module(no, ModuleName,
-				NewModuleName),
-			ClassName = mlds_module_name_to_class_name(
-				NewModuleName),
-			GlobalType = mlds_type_to_ilds_type(
-				mlds_type_for_rtti_global),
-			FieldRef = make_fieldref(GlobalType, ClassName, 
-				MangledVarStr),
+			FieldRef = make_fieldref_for_handdefined_var(Var,
+				VarType),
 			Instrs = instr_node(ldsfld(FieldRef))
 		),
 		Info0 = Info
@@ -1263,13 +1254,17 @@
 	{ Instrs = tree__list([R1LoadInstrs, R2LoadInstrs, BinaryOpInstrs]) }.
 
 load(mem_addr(Lval), Instrs, Info0, Info) :- 
-	( Lval = var(Var, _VarType),
+	( Lval = var(Var, VarType),
 		mangle_mlds_var(Var, MangledVarStr),
 		Info0 = Info,
 		( is_local(MangledVarStr, Info) ->
 			Instrs = instr_node(ldloca(name(MangledVarStr)))
-		;
+		; is_argument(Var, Info) ->
 			Instrs = instr_node(ldarga(name(MangledVarStr)))
+		;
+			FieldRef = make_fieldref_for_handdefined_var(Var,
+				VarType),
+			Instrs = instr_node(ldsfld(FieldRef))
 		)
 	; Lval = field(_MaybeTag, Rval, FieldNum, FieldType, ClassType),
 		get_fieldref(FieldNum, FieldType, ClassType, FieldRef),
@@ -1299,12 +1294,15 @@
 		% instruction.  Annoying, eh?
 	unexpected(this_file, "store into mem_ref").
 
-store(var(Var, _VarType), Instrs, Info, Info) :- 
+store(var(Var, VarType), Instrs, Info, Info) :- 
 	mangle_mlds_var(Var, MangledVarStr),
 	( is_local(MangledVarStr, Info) ->
 		Instrs = instr_node(stloc(name(MangledVarStr)))
-	;
+	; is_argument(Var, Info) ->
 		Instrs = instr_node(starg(name(MangledVarStr)))
+	;
+		FieldRef = make_fieldref_for_handdefined_var(Var, VarType),
+		Instrs = instr_node(stsfld(FieldRef))
 	).
 
 %-----------------------------------------------------------------------------%
@@ -1892,6 +1890,23 @@
 			[s(MaybeModuleStr), s(PredName), s(TypeName), i(Arity),
 				i(ProcIdInt), s(MaybeSeqNumStr)], UnMangledId),
 		llds_out__name_mangle(UnMangledId, Id).
+
+
+	% If an mlds__var is not an argument or a local, what is it?
+	% We assume the given variable is a handwritten RTTI reference or a
+	% reference to some hand-written code in the
+	% modulename__c_code class.  This is OK so long as the
+	% code generator uses real 'field' lvals to reference
+	% fields in the modulename class.
+
+:- func make_fieldref_for_handdefined_var(mlds__var, mlds__type) = fieldref.
+make_fieldref_for_handdefined_var(Var, VarType) = FieldRef :-
+	Var = qual(ModuleName, _),
+	mangle_mlds_var(Var, MangledVarStr),
+	mangle_dataname_module(no, ModuleName, NewModuleName),
+	ClassName = mlds_module_name_to_class_name(NewModuleName),
+	FieldRef = make_fieldref(
+		mlds_type_to_ilds_type(VarType), ClassName, MangledVarStr).
 
 	% When generating references to RTTI, we need to mangle the
 	% module name if the RTTI is defined in C code by hand.
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.71
diff -u -r1.71 private_builtin.m
--- library/private_builtin.m	2001/03/18 23:10:09	1.71
+++ library/private_builtin.m	2001/04/10 15:16:16
@@ -115,6 +115,17 @@
 :- implementation.
 :- import_module require, string, std_util, int, float, char, string, list.
 
+:- pragma foreign_code("MC++", "
+
+// The dummy_var is used to represent io__states and other Mercury
+// parameters that are not really passed around.  Occasionally a dummy variable
+// will be used by the code generator as an lval, so we use
+// private_builtin:dummy_var as that lval.
+
+MR_Word dummy_var;
+
+").
+
 :- pragma inline(builtin_compare_int/3).
 :- pragma inline(builtin_compare_character/3).
 :- pragma inline(builtin_compare_string/3).


-- 
       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-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