[m-dev.] IL name mangling

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 9 16:51:11 AEDT 2000


I'm not planning to commit this yet, because of the XXX below,
but Tyson wanted the diff...

----------

Estimated hours taken: 1

compiler/mlds_to_il.m:
	Change the name mangling algorithm.
	XXX need to put the arity back, at least for predicates/functions
	with dummy argument types such as io__state

Workspace: /home/pgrad/fjh/fs/roy/traveller/mercury
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.4
diff -u -d -r1.4 mlds_to_il.m
--- compiler/mlds_to_il.m	2000/11/07 12:54:29	1.4
+++ compiler/mlds_to_il.m	2000/11/08 07:07:31
@@ -131,7 +131,7 @@
 :- import_module mlds_to_c. /* to output C code for .cpp files */
 :- use_module llds. /* for user_c_code */
 
-:- import_module bool, int, map, string, list, assoc_list, term.
+:- import_module bool, char, int, map, string, list, assoc_list, term.
 :- import_module library, require, counter.
 
 	% We build up lists of instructions using a tree to make
@@ -1804,12 +1804,33 @@
 	% sure it is all necessary.
 	% We may need to do different name mangling for CLS compliance
 	% than we would otherwise need.
-predlabel_to_id(pred(PredOrFunc, MaybeModuleName, Name, Arity), ProcId, 
+predlabel_to_id(pred(PredOrFunc, MaybeModuleName, Name, _Arity), ProcId, 
 			MaybeSeqNum, Id) :-
-		( PredOrFunc = predicate, PredOrFuncStr = "p" 
-		; PredOrFunc = function, PredOrFuncStr = "f" 
+		(
+			PredOrFunc = function,
+			PredOrFuncStr = "_f" 
+		;
+			PredOrFunc = predicate,
+			(
+				( Name = _V `app` "_f"
+				; Name = _ `app` "_p"
+				; Name = _ `app` "_m" `app` DigitString,
+				  Digits = string__to_char_list(DigitString),
+				  all [Digit] (list__member(Digit, Digits) =>
+				  	char__is_digit(Digit))
+				)
+			->
+				PredOrFuncStr = "_p" 
+			;
+				PredOrFuncStr = "" 
+			)
 		),
 		proc_id_to_int(ProcId, ProcIdInt),
+		( ProcIdInt = 0 ->
+			ProcIdStr = ""
+		;
+			string__format("_m%d", [i(ProcIdInt)], ProcIdStr)
+		),
 		( MaybeModuleName = yes(ModuleName) ->
 			mlds_to_il__sym_name_to_string(ModuleName, MStr),
 			string__format("%s_", [s(MStr)], MaybeModuleStr)
@@ -1821,10 +1842,14 @@
 		;
 			MaybeSeqNumStr = ""
 		),
-		string__format("%s%s_%d_%s_%d%s", [s(MaybeModuleStr), s(Name),
-			 i(Arity), s(PredOrFuncStr), i(ProcIdInt),
-			 s(MaybeSeqNumStr)], UnMangledId),
+		string__format("%s%s%s%s%s", [s(MaybeModuleStr), s(Name),
+			s(PredOrFuncStr), s(ProcIdStr),
+			s(MaybeSeqNumStr)], UnMangledId),
 		llds_out__name_mangle(UnMangledId, Id).
+
+:- func app(string, string) = string.
+:- mode app(out, out) = in is multi.
+app(X, Y) = Z :- string__append(X, Y, Z).
 
 predlabel_to_id(special_pred(PredName, MaybeModuleName, TypeName, Arity),
 			ProcId, MaybeSeqNum, Id) :-

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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