[m-rev.] for review: ROTOR fixes

Peter Ross pro at missioncriticalit.com
Thu Mar 6 02:26:32 AEDT 2003


Estimated hours taken: 4
Branches: main

Get the mercury compiler working with ROTOR, the MS shared source CLI
implementation.

compiler/mlds_to_il.m:
	ROTOR doesn't allow calli calls to be made tail calls, so
	don't make them tail calls.
	
compiler/options.m:
	Add the option --support-rotor-clr which avoids generating
	code which can cause problems for the ROTOR CLR.

library/array.m:
	Fix some function signatures which were incorrectly declared
	as returning int rather than MR_bool, which the MS CLR accepts
	but ROTOR doesn't.
	
runtime/Mmakefile:
	Add a commented out rule for compiling mercury_il.il for
	ROTOR.

runtime/mercury_il.il:
	Add a `// REMOVE FOR ROTOR comment' to all the tail. prefixes
	associatied with calli instructions.


diff -u compiler/mlds_to_il.m compiler/mlds_to_il.m
--- compiler/mlds_to_il.m
+++ compiler/mlds_to_il.m
@@ -167,6 +167,7 @@
 	verifiable_code	:: bool,		% --verifiable-code
 	il_byref_tailcalls :: bool,		% --il-byref-tailcalls
 	support_ms_clr	:: bool,		% --support-ms-clr
+	support_rotor_clr :: bool,		% --support-rotor-clr
 		% class-wide attributes (all accumulate)
 	alloc_instrs	:: instr_tree,		% .cctor allocation instructions
 	init_instrs	:: instr_tree,		% .cctor init instructions
@@ -236,7 +237,7 @@
 		io__state, io__state).
 :- mode generate_il(in, in, out, out, di, uo) is det.
 
-generate_il(MLDS, Version, ILAsm, ForeignLangs, IO0, IO) :-
+generate_il(MLDS, Version, ILAsm, ForeignLangs, !IO) :-
 
 	mlds(MercuryModuleName, ForeignCode, Imports, Defns) =
 		transform_mlds(MLDS),
@@ -244,22 +245,20 @@
 	ModuleName = mercury_module_name_to_mlds(MercuryModuleName),
 	prog_out__sym_name_to_string(mlds_module_name_to_sym_name(ModuleName),
 			".", AssemblyName),
-	get_il_data_rep(ILDataRep, IO0, IO1),
-	globals__io_lookup_bool_option(debug_il_asm, DebugIlAsm, IO1, IO2),
+	get_il_data_rep(ILDataRep, !IO),
+	globals__io_lookup_bool_option(debug_il_asm, DebugIlAsm, !IO),
 	globals__io_lookup_bool_option(verifiable_code,
-			VerifiableCode, IO2, IO3),
-	globals__io_lookup_bool_option(il_byref_tailcalls, ByRefTailCalls,
-			IO3, IO4),
-	globals__io_lookup_bool_option(sign_assembly, SignAssembly,
-			IO4, IO5),
+			VerifiableCode, !IO),
+	globals__io_lookup_bool_option(il_byref_tailcalls, ByRefTailCalls, !IO),
+	globals__io_lookup_bool_option(sign_assembly, SignAssembly, !IO),
 	globals__io_lookup_bool_option(separate_assemblies, SeparateAssemblies,
-			IO5, IO6),
-	globals__io_lookup_bool_option(support_ms_clr, MsCLR,
-			IO6, IO),
+			!IO),
+	globals__io_lookup_bool_option(support_ms_clr, MsCLR, !IO),
+	globals__io_lookup_bool_option(support_rotor_clr, RotorCLR, !IO),
 
 	IlInfo0 = il_info_init(ModuleName, AssemblyName, Imports,
 			ILDataRep, DebugIlAsm, VerifiableCode, ByRefTailCalls,
-			MsCLR),
+			MsCLR, RotorCLR),
 
 		% Generate code for all the methods.
 	list__map_foldl(mlds_defn_to_ilasm_decl, Defns, ILDecls,
@@ -1584,6 +1583,7 @@
 	VerifiableCode =^ verifiable_code,
 	ByRefTailCalls =^ il_byref_tailcalls,
 	MsCLR =^ support_ms_clr,
+	RotorCLR =^ support_rotor_clr,
 	DataRep =^ il_data_rep,
 	{ TypeParams = mlds_signature_to_ilds_type_params(DataRep, Sig) },
 	{ ReturnParam = mlds_signature_to_il_return_param(DataRep, Sig) },
@@ -1620,9 +1620,13 @@
 			{ MsCLR = yes },
 			{ ReturnParam \= CallerReturnParam }
 		),
-		% The ROTOR implementation only allows const calls to be tail
-		% calls.
-		{ Function = const(_) }
+		% The ROTOR implementation only allows "tail."
+		% annotations on direct calls (tail.call),
+		% not indirect calls (calli).
+		\+ (
+			{ RotorCLR = yes },
+			{ Function \= const(_) }
+		)
 	->
 		{ TailCallInstrs = [tailcall] },
 		% For calls marked with "tail.", we need a `ret'
@@ -4209,12 +4213,12 @@
 %
 
 :- func il_info_init(mlds_module_name, ilds__id, mlds__imports,
-		il_data_rep, bool, bool, bool, bool) = il_info.
+		il_data_rep, bool, bool, bool, bool, bool) = il_info.
 
 il_info_init(ModuleName, AssemblyName, Imports, ILDataRep,
-		DebugIlAsm, VerifiableCode, ByRefTailCalls, MsCLR) =
+		DebugIlAsm, VerifiableCode, ByRefTailCalls, MsCLR, RotorCLR) =
 	il_info(ModuleName, AssemblyName, Imports, set__init, ILDataRep,
-		DebugIlAsm, VerifiableCode, ByRefTailCalls, MsCLR,
+		DebugIlAsm, VerifiableCode, ByRefTailCalls, MsCLR, RotorCLR,
 		empty, empty, [], no, set__init, set__init,
 		map__init, empty, counter__init(1), counter__init(1), no,
 		Args, MethodName, DefaultSignature) :-
diff -u runtime/mercury_il.il runtime/mercury_il.il
--- runtime/mercury_il.il
+++ runtime/mercury_il.il
@@ -377,8 +377,7 @@
 	ldarg 'procedure'
 	unbox int32
 	ldobj int32
-	// XXX ROTOR doesn't allow tail.calli
-	// tail.
+	tail.		// REMOVE FOR ROTOR
 	calli	bool (class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -394,8 +393,7 @@
 	ldarg 'procedure'
 	unbox int32
 	ldobj int32
-	// XXX ROTOR doesn't allow tail.calli
-	// tail.
+	tail.		// REMOVE FOR ROTOR
 	calli	bool (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -411,8 +409,7 @@
 	ldarg 'procedure'
 	unbox int32
 	ldobj int32
-	// XXX ROTOR doesn't allow tail.calli
-	// tail.
+	tail.		// REMOVE FOR ROTOR
 	calli	bool (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -430,8 +427,7 @@
 	ldarg 'procedure'
 	unbox int32
 	ldobj int32
-	// XXX ROTOR doesn't allow tail.calli
-	// tail.
+	tail.		// REMOVE FOR ROTOR
 	calli	bool (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -450,8 +446,7 @@
 	ldarg 'procedure'
 	unbox int32
 	ldobj int32
-	// XXX ROTOR doesn't allow tail.calli
-	// tail.
+	tail.		// REMOVE FOR ROTOR
 	calli	bool (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -473,8 +468,7 @@
 	ldarg 'procedure'
 	unbox int32
 	ldobj int32
-	// XXX ROTOR doesn't allow tail.calli
-	// tail.
+	tail.		// REMOVE FOR ROTOR
 	calli	bool (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
only in patch2:
--- runtime/Mmakefile	3 Mar 2003 06:11:50 -0000	1.99
+++ runtime/Mmakefile	5 Mar 2003 15:15:50 -0000
@@ -282,6 +282,13 @@
 runtime: $(DOTNET_DLLS)
 
 mercury_mcpp.dll: mercury_il.dll $(MCPP_HDRS)
+
+# Uncomment the following rule if you want to build Mercury in a form
+# that will work with ROTOR.
+# mercury_il.dll: mercury_il.il
+#	sed '/REMOVE FOR ROTOR/s@^@//@' mercury_il.il > mercury_il.rotor.il
+#	$(MS_ILASM) $(ALL_MS_ILASMFLAGS) /dll /quiet /OUT=mercury_il.dll \
+#			mercury_il.rotor.il
  
 else
 
only in patch2:
--- compiler/options.m	1 Mar 2003 06:34:51 -0000	1.407
+++ compiler/options.m	5 Mar 2003 15:15:26 -0000
@@ -548,6 +548,7 @@
 		;	quoted_ilasm_flag
 		;	dotnet_library_version
 		;	support_ms_clr
+		;	support_rotor_clr
 
 			% Managed C++
 		;	mcpp_compiler
@@ -1143,6 +1144,7 @@
 		% with Beta2.
 	dotnet_library_version	-	string("1.0.3300.0"),
 	support_ms_clr		-	bool(yes),
+	support_rotor_clr	-	bool(no),
 
 % Managed C++
 	mcpp_compiler		-	string("cl"),
@@ -1808,6 +1810,7 @@
 long_option("ilasm-flag",		quoted_ilasm_flag).
 long_option("dotnet-library-version",	dotnet_library_version).
 long_option("support-ms-clr",		support_ms_clr).
+long_option("support-rotor-clr",	support_rotor_clr).
 
 long_option("mcpp-compiler",		mcpp_compiler).
 long_option("mcpp-flags",		mcpp_flags).
@@ -2902,6 +2905,9 @@
 
 		"--no-support-ms-clr",
 		"\tDon't use MS CLR specific workarounds in the generated code.",
+		
+		"--support-rotor-clr",
+		"\tUse specific workarounds for the ROTOR CLR in the generated code.",
 		
 		"--java",
 		"\tAn abbreviation for `--target java'.",
--------------------------------------------------------------------------
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