[m-rev.] for review: bugfix for foreign_proc IL

Tyson Dowd trd at cs.mu.OZ.AU
Thu Jul 11 16:55:26 AEST 2002


Hi,

Pete can you look at this?

I wanted to use this but discovered it had been (probably quite
recently) broken.  We were generating Headvar__1 locals instead of
locals with the correct names.

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


Estimated hours taken: 2
Branches: main

Fix a bug that meant we generated invalid code for foreign_proc IL.
Recent changes to variable naming unifications uncovered this bug.

compiler/ml_code_gen.m:
	Use the user's names for variables when generating locals for
	use in foreign_proc for IL, so that they match the names given
	in the foreign code.


Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.120
diff -u -r1.120 ml_code_gen.m
--- compiler/ml_code_gen.m	30 Jun 2002 17:06:26 -0000	1.120
+++ compiler/ml_code_gen.m	11 Jul 2002 06:11:56 -0000
@@ -2467,7 +2467,7 @@
 	out, out, in, out) is det.
 
 ml_gen_ordinary_pragma_il_proc(_CodeModel, Attributes,
-	PredId, ProcId, ArgVars, _ArgDatas, OrigArgTypes,
+	PredId, ProcId, ArgVars, ArgDatas, OrigArgTypes,
 	ForeignCode, Context, MLDS_Decls, MLDS_Statements) -->
 
 	{ MLDSContext = mlds__make_context(Context) },
@@ -2487,6 +2487,7 @@
 	{ module_info_name(ModuleInfo, ModuleName) },
 	{ MLDSModuleName = mercury_module_name_to_mlds(ModuleName) },
 
+	{ ArgVarDataMap = map__from_corresponding_lists(ArgVars, ArgDatas) },
 
 	% XXX in the code to marshall parameters, fjh says:
 	% we need to handle the case where the types in the procedure interface
@@ -2501,7 +2502,6 @@
 		(pred(Var::in, Statement::out) is semidet :- 
 			map__lookup(HeadVarTypes, Var, Type),
 			not type_util__is_dummy_argument_type(Type),
-			VarName = mlds__var_name(VarNameString, _MangleInt),
 			MLDSType = mercury_type_to_mlds_type(ModuleInfo, Type),
 
 			VarName = ml_gen_var_name(VarSet, Var),
@@ -2509,7 +2509,10 @@
 			OutputVarLval = mem_ref(lval(
 				var(QualVarName, MLDSType)), MLDSType),
 
-			NonMangledVarName = mlds__var_name(VarNameString, no),
+			map__lookup(ArgVarDataMap, Var, MaybeVarName),
+			MaybeVarName = yes(UserVarNameString - _),
+			NonMangledVarName = 
+				mlds__var_name(UserVarNameString, no),
 			QualLocalVarName= qual(MLDSModuleName,
 				NonMangledVarName),
 			LocalVarLval = var(QualLocalVarName, MLDSType),
@@ -2523,7 +2526,6 @@
 		(pred(Var::in, Statement::out) is semidet :- 
 			map__lookup(HeadVarTypes, Var, Type),
 			not type_util__is_dummy_argument_type(Type),
-			VarName = mlds__var_name(VarNameString, _MangleInt),
 			MLDSType = mercury_type_to_mlds_type(ModuleInfo, Type),
 
 			VarName = ml_gen_var_name(VarSet, Var),
@@ -2531,7 +2533,10 @@
 				% this line differs from above
 			OutputVarLval = var(QualVarName, MLDSType),
 
-			NonMangledVarName = mlds__var_name(VarNameString, no),
+			map__lookup(ArgVarDataMap, Var, MaybeVarName),
+			MaybeVarName = yes(UserVarNameString - _),
+			NonMangledVarName =
+				mlds__var_name(UserVarNameString, no),
 			QualLocalVarName= qual(MLDSModuleName,
 				NonMangledVarName),
 			LocalVarLval = var(QualLocalVarName, MLDSType),
@@ -2547,8 +2552,15 @@
 		(pred(Var::in, MLDS_Defn::out, Box0::in, Box::out) is det :- 
 			map__lookup(HeadVarTypes, Var, Type),
 			VarName = ml_gen_var_name(VarSet, Var),
-			VarName = mlds__var_name(VarNameString, _MangleInt),
-			NonMangledVarName = mlds__var_name(VarNameString, no),
+
+			map__lookup(ArgVarDataMap, Var, MaybeVarName),
+			( MaybeVarName = yes(UserVarNameString - _) ->
+				NonMangledVarName = 
+					mlds__var_name(UserVarNameString, no)
+			;
+				error("ml_gen_ordinary_pragma_il_proc: no variable name for var")
+			),
+
 				% Dummy arguments are just mapped to integers,
 				% since they shouldn't be used in any
 				% way that requires them to have a real value.


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