[m-rev.] for review: autoconfigure which version of .NET std lib to use

Peter Ross peter.ross at miscrit.be
Fri Mar 1 21:35:04 AEDT 2002


Hi,


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


Estimated hours taken: 2
Branches: main

Configure the version of the .NET std library that we are using instead
of hard-coding it in the compiler.

aclocal.m4:
    Find the version number of the mscorlib assembly and record it in
    MS_DOTNET_LIBRARY_VERSION.

compiler/options.m:
compiler/mlds_to_il.m:
doc/user_guide.texi:
    Add the option --dotnet-library-version, and use it to determine
    which version of the .NET standard libraries to refer too.
    
scripts/mmc.in:
    Use the autoconfigured MS_DOTNET_LIBRARY_VERSION to set the
    --dotnet-library-version.  This is commented out for the moment
    until this change bootstraps.


Index: aclocal.m4
===================================================================
RCS file: /home/mercury1/repository/mercury/aclocal.m4,v
retrieving revision 1.7
diff -u -r1.7 aclocal.m4
--- aclocal.m4	11 Feb 2002 12:11:31 -0000	1.7
+++ aclocal.m4	1 Mar 2002 10:30:13 -0000
@@ -98,10 +98,44 @@
 AC_MSG_RESULT($mercury_cv_microsoft_visual_cpp)
 MS_CL=`basename "$MS_CL"`
 
+# We default to the Beta 2 version of the library
+mercury_cv_microsoft_dotnet_library_version=1.0.2411.0
+if test $mercury_cv_microsoft_dotnet = "yes"; then
+	AC_MSG_CHECKING(determining version of .NET libraries)
+	cat > conftest.cs << EOF
+	using System;
+	using System.Reflection;
+	public class version {
+	    public static void Main()
+	    {
+		Assembly asm = Assembly.Load("mscorlib");
+		AssemblyName name = asm.GetName();
+		Version version = name.Version;
+		Console.Write(version);
+		Console.Write("\n");
+	    }
+	}
+EOF
+	if
+		echo csc conftest.cs >&AC_FD_CC 2>&1 && \
+			csc conftest.cs  >&AC_FD_CC 2>&1
+	then
+		mercury_cv_microsoft_dotnet_library_version=`./conftest`
+		AC_MSG_RESULT($mercury_cv_microsoft_dotnet_library_version)
+		rm -f conftest*
+	else
+		rm -f conftest*
+		AC_MSG_ERROR(unable to determine version)
+		exit 1
+	fi
+fi
+MS_DOTNET_LIBRARY_VERSION=$mercury_cv_microsoft_dotnet_library_version
+
 AC_SUBST(ILASM)
 AC_SUBST(GACUTIL)
 AC_SUBST(MS_CL)
 AC_SUBST(MS_DOTNET_SDK_DIR)
+AC_SUBST(MS_DOTNET_LIBRARY_VERSION)
 AC_SUBST(MS_VISUALCPP_DIR)
 ])
 
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.105
diff -u -r1.105 mlds_to_il.m
--- compiler/mlds_to_il.m	27 Feb 2002 16:21:30 -0000	1.105
+++ compiler/mlds_to_il.m	1 Mar 2002 10:30:15 -0000
@@ -192,7 +192,48 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-generate_il(MLDS, ILAsm, ForeignLangs, IO0, IO) :-
+generate_il(MLDS, ILAsm, ForeignLangs) -->
+	maybe_get_dotnet_library_version(MaybeVersion),
+	( { MaybeVersion = yes(Version) },
+		generate_il(MLDS, Version, ILAsm, ForeignLangs)
+	; { MaybeVersion = no },
+		{ ILAsm = [] },
+		{ ForeignLangs = set__init }
+	).
+
+:- pred maybe_get_dotnet_library_version(maybe(assembly_decl)::out,
+		io::di, io::uo) is det.
+
+maybe_get_dotnet_library_version(MaybeVersion) -->
+	io_lookup_string_option(dotnet_library_version, VersionStr),
+	{ IsSep = (pred(('.')::in) is semidet) },
+	( 
+		{ string__words(IsSep, VersionStr) = [Mj, Mn, Bu, Rv] },
+		{ string__to_int(Mj, Major) },
+		{ string__to_int(Mn, Minor) },
+		{ string__to_int(Bu, Build) },
+		{ string__to_int(Rv, Revision) }
+	->
+		{ Version = version(Major, Minor, Build, Revision) },
+		{ MaybeVersion = yes(Version) }
+	;
+		{ MaybeVersion = no },
+		io__stderr_stream(StdErr),
+		io__write_string(StdErr, "error: Invalid version string `"),
+		io__write_string(StdErr, VersionStr),
+		io__write_string(StdErr, "' passed " ),
+		io__write_string(StdErr, "to --dotnet-library-version.\n"),
+		io__set_exit_status(1)
+	).
+
+%-----------------------------------------------------------------------------%
+
+:- pred generate_il(mlds, assembly_decl,
+		list(ilasm:decl), set(foreign_language),
+		io__state, io__state).
+:- mode generate_il(in, in, out, out, di, uo) is det.
+
+generate_il(MLDS, Version, ILAsm, ForeignLangs, IO0, IO) :-
 
 	mlds(MercuryModuleName, _ForeignCode, Imports, Defns) =
 		transform_mlds(MLDS),
@@ -261,8 +302,8 @@
 			ForeignCodeAssemblerRefs),
 		AssemblerRefs = list__append(ForeignCodeAssemblerRefs, Imports)
 	),
-	generate_extern_assembly(AssemblyName, SignAssembly, SeparateAssemblies,
-			AssemblerRefs, ExternAssemblies),
+	generate_extern_assembly(AssemblyName, Version, SignAssembly,
+			SeparateAssemblies, AssemblerRefs, ExternAssemblies),
 	Namespace = [namespace(NamespaceName, ILDecls)],
 	ILAsm = list__condense([ThisAssembly, ExternAssemblies, Namespace]).
 
@@ -3914,10 +3955,10 @@
 %-----------------------------------------------------------------------------
 
 	% Generate extern decls for any assembly we reference.
-:- pred mlds_to_il__generate_extern_assembly(string::in, bool::in, bool::in,
-		mlds__imports::in, list(decl)::out) is det.
+:- pred mlds_to_il__generate_extern_assembly(string::in, assembly_decl::in,
+		bool::in, bool::in, mlds__imports::in, list(decl)::out) is det.
 
-mlds_to_il__generate_extern_assembly(CurrentAssembly, SignAssembly,
+mlds_to_il__generate_extern_assembly(CurrentAssembly, Version, SignAssembly,
 		SeparateAssemblies, Imports, AllDecls) :-
 	Gen = (pred(Import::in, Decl::out) is semidet :-
 		( Import = mercury_import(ImportName),
@@ -3933,7 +3974,7 @@
 			prog_out__sym_name_to_string(PackageName,
 					ForeignPackageStr),
 			( string__prefix(ForeignPackageStr, "System") ->
-				AsmDecls = dotnet_system_assembly_decls
+				AsmDecls = dotnet_system_assembly_decls(Version)
 			;
 				AsmDecls = []
 			)
@@ -3970,7 +4011,7 @@
 			])
 		]),
 		extern_assembly("mscorlib",
-			dotnet_system_assembly_decls ++ 
+			dotnet_system_assembly_decls(Version) ++ 
 			[hash([
 				int8(0xb0), int8(0x73), int8(0xf2), int8(0x4c),
 				int8(0x14), int8(0x39), int8(0x0a), int8(0x35),
@@ -3980,11 +4021,11 @@
 			])
 		]) | Decls].
 
-:- func dotnet_system_assembly_decls = list(assembly_decl).
+:- func dotnet_system_assembly_decls(assembly_decl) = list(assembly_decl).
 
-dotnet_system_assembly_decls
+dotnet_system_assembly_decls(Version)
 	= [
-		version(1, 0, 2411, 0),
+		Version,
 		public_key_token([
 			int8(0xb7), int8(0x7a), int8(0x5c), int8(0x56),
 			int8(0x19), int8(0x34), int8(0xE0), int8(0x89)
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.357
diff -u -r1.357 options.m
--- compiler/options.m	23 Feb 2002 07:30:46 -0000	1.357
+++ compiler/options.m	1 Mar 2002 10:30:16 -0000
@@ -471,7 +471,9 @@
 		;	java_flags
 		;	java_classpath
 		;	java_object_file_extension
-
+			
+			% IL
+		;	dotnet_library_version
 
 	% Link options
 		;	output_file_name
@@ -909,6 +911,7 @@
 option_defaults_2(target_code_compilation_option, [
 		% Target code compilation options
 	target_debug		-	bool(no),
+
 % C
 					% the `mmc' script will override the
 					% following default with a value
@@ -937,7 +940,12 @@
 	java_compiler		-	string("javac"),
 	java_flags		-	accumulating([]),
 	java_classpath  	-	accumulating([]),
-	java_object_file_extension -	string(".class")
+	java_object_file_extension -	string(".class"),
+
+% IL
+		% We default to the version of the library that came
+		% with Beta2.
+	dotnet_library_version	-	string("1.0.2411.0")
 ]).
 option_defaults_2(link_option, [
 		% Link Options
@@ -1464,6 +1472,8 @@
 long_option("java-classpath",   	java_classpath).
 long_option("java-object-file-extension", java_object_file_extension).
 
+long_option("dotnet-library-version",	dotnet_library_version).
+
 % link options
 long_option("output-file",		output_file_name).
 long_option("link-flags",		link_flags).
@@ -3069,7 +3079,11 @@
 
 		"--java-object-file-extension",
 		"\tSpecify an extension for Java object (bytecode) files",
-		"\tBy default this is `.class'."
+		"\tBy default this is `.class'.",
+
+		"--dotnet-library-version",
+		"\tThe version number for the standard libraries distributed",
+		"\twith the Microsoft .NET SDK."
 	]).
 
 :- pred options_help_link(io__state::di, io__state::uo) is det.
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.297
diff -u -r1.297 user_guide.texi
--- doc/user_guide.texi	27 Feb 2002 17:41:11 -0000	1.297
+++ doc/user_guide.texi	1 Mar 2002 10:30:21 -0000
@@ -5628,6 +5628,12 @@
 Specify an extension for Java object (bytecode) files.  By default this
 is @samp{.class}. 
 
+ at sp 1
+ at item --dotnet-library-version @var{extension}
+ at findex --dotnet-library-version
+The version number for the standard libraries distributed with the
+Microsoft .NET SDK.
+
 @end table
 
 @node Link options
Index: scripts/mmc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mmc.in,v
retrieving revision 1.18
diff -u -r1.18 mmc.in
--- scripts/mmc.in	19 Nov 2001 07:25:08 -0000	1.18
+++ scripts/mmc.in	1 Mar 2002 10:30:21 -0000
@@ -34,11 +34,15 @@
 NUM_REAL_R_TEMPS=@NUM_REAL_R_TEMPS@
 HAVE_DELAY_SLOT=@HAVE_DELAY_SLOT@
 HAVE_BOXED_FLOATS=@HAVE_BOXED_FLOATS@
+DOTNET_LIBRARY_VERSION=@MS_DOTNET_LIBRARY_VERSION@
 DEFAULT_OPT_LEVEL=${MERCURY_DEFAULT_OPT_LEVEL="-O2"}
 
 # The default optimization level should be after
 # all the options that describe the machine configuration.
 
+# XXX when the compiler has bootstrapped we need to add the following to
+# the mmc command line
+# --dotnet-library-version "$DOTNET_LIBRARY_VERSION"
 case $# in
 	0) exec $MC \
 		$MERC_ALL_MC_C_INCL_DIRS \

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