[m-rev.] for review; compiler changes needed for il grade

Peter Ross pro at missioncriticalit.com
Fri Jun 28 02:15:28 AEST 2002


Hi,

For Simon, Tyson or Fergus to review.

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


Estimated hours taken: 8
Branches: main

Misc changes to the compiler needed so that the library can be compiled in the
il grade.  Note that the library doesn't yet currently compile in the il grade,
these changes are just the first step to getting it to.

compiler/handle_options.m:
	Intermodule optimization needs to be turned on when using high-level
	data in the il grade, so that equivalence types can be fully expanded.

compiler/mlds_to_managed.m:
	When outputting MC++ code do the following
		- define MR_HIGHLEVEL_DATA so that conditional choices
		  can be made,
		- add a #using for each imported module so that the types can
		  be found,
		- treat imported std lib modules specially.

compiler/mlds.m:
	Add a utility predict that tests whether a mlds_module_name is one
	belonging to the standard library.

compiler/modules.m:
	Add a new predicate mercury_std_library_module_name, which tests if a
	module_name is a standard library module name.



Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.140
diff -u -r1.140 handle_options.m
--- compiler/handle_options.m	30 May 2002 12:54:56 -0000	1.140
+++ compiler/handle_options.m	27 Jun 2002 16:05:09 -0000
@@ -328,6 +328,9 @@
 	%         XXX Previously static ground terms used to not work with
 	%             --high-level-data.  But this has been (mostly?) fixed now.
 	%             So we should investigate re-enabling static ground terms.
+	%   - intermodule optimization
+	%	  This is only required for high-level data and is needed so
+	%	  that equivalence types can be expanded.
 	( { Target = il } ->
 		globals__io_set_gc_method(none),
 		globals__io_set_option(reclaim_heap_on_nondet_failure,
@@ -340,7 +343,15 @@
 		globals__io_set_option(num_tag_bits, int(0)),
 		globals__io_set_option(unboxed_enums, bool(no)),
 		globals__io_set_option(unboxed_no_tag_types, bool(no)),
-		globals__io_set_option(static_ground_terms, bool(no))
+		globals__io_set_option(static_ground_terms, bool(no)),
+
+		globals__io_lookup_bool_option(highlevel_data, HighLevelData),
+		( { HighLevelData = yes } ->
+			globals__io_set_option(intermodule_optimization,
+					bool(yes))
+		;
+			[]
+		)
 	;
 		[]
 	),
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.93
diff -u -r1.93 mlds.m
--- compiler/mlds.m	21 Jun 2002 13:26:41 -0000	1.93
+++ compiler/mlds.m	27 Jun 2002 16:05:09 -0000
@@ -379,6 +379,9 @@
 % MLDS package.
 :- func mlds_module_name_to_package_name(mlds_module_name) = sym_name.
 
+% Is the current module a member of the std library, is so which module is it?
+:- pred is_std_lib_module(mlds_module_name::in, string::out) is semidet.
+
 % Given an MLDS module name (e.g. `foo.bar'), append another class qualifier
 % (e.g. for a class `baz'), and return the result (e.g. `foo.bar.baz').
 % The `arity' argument specifies the arity of the class.
@@ -1772,6 +1775,13 @@
 	;
 		MLDS_Package = MercuryModule
 	).
+
+is_std_lib_module(Module, UnqualifiedName) :-
+	Name = Module ^ module_name,
+	( Name = unqualified(UnqualifiedName)
+	; Name = qualified(unqualified("mercury"), UnqualifiedName)
+	),
+	mercury_std_library_module(UnqualifiedName).
 
 mlds_module_name_to_sym_name(Module) = Module ^ module_name.
 
Index: compiler/mlds_to_managed.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_managed.m,v
retrieving revision 1.2
diff -u -r1.2 mlds_to_managed.m
--- compiler/mlds_to_managed.m	24 Jun 2002 08:43:59 -0000	1.2
+++ compiler/mlds_to_managed.m	27 Jun 2002 16:05:10 -0000
@@ -90,7 +90,7 @@
 
 generate_code(Lang, MLDS) -->
 
-	{ MLDS = mlds(ModuleName, AllForeignCode, _Imports, Defns) },
+	{ MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns) },
 	{ ClassName = class_name(mercury_module_name_to_mlds(ModuleName), 
 			wrapper_class_name) },
 
@@ -98,7 +98,7 @@
 
 		% Output any generic header code specific to the target
 		% language.
-	output_language_specific_header_code(Lang, ModuleName),
+	output_language_specific_header_code(Lang, ModuleName, Imports),
 
 		% Get the foreign code for the required language.
 	{ ForeignCode = map__lookup(AllForeignCode, Lang) },
@@ -146,9 +146,10 @@
 	io__nl.
 
 :- pred output_language_specific_header_code(foreign_language::in(managed_lang),
-		mercury_module_name::in, io::di, io::uo) is det.
+		mercury_module_name::in, mlds__imports::in,
+		io::di, io::uo) is det.
 
-output_language_specific_header_code(csharp, _ModuleName) -->
+output_language_specific_header_code(csharp, _ModuleName, _Imports) -->
 	io__write_strings([
 		% XXX We may be able to drop the mercury namespace soon,
 		% as there doesn't appear to be any llds generated code
@@ -163,14 +164,56 @@
 	; { SignAssembly = no },
 		[]
 	).
-output_language_specific_header_code(managed_cplusplus, ModuleName) -->
+output_language_specific_header_code(managed_cplusplus, ModuleName, Imports) -->
+	get_il_data_rep(DataRep),
+	( { DataRep = il_data_rep(yes, _) } ->
+		io__write_string("#define MR_HIGHLEVEL_DATA\n")
+	;
+		[]
+	),
+
+	io__write_string("#using <mscorlib.dll>\n"),
+
+	( { mercury_std_library_module_name(ModuleName) } ->
+		io__write_strings([
+			"#using ""mercury_mcpp.dll""\n",
+			"#using ""mercury_il.dll""\n",
+			"#using ""private_builtin.dll""\n",
+			"#using ""builtin.dll""\n"])
+	;
+		[]
+	),
+
+	{ list__map(
+		(pred(Import::in, Result::out) is det :-
+		    ( Import = mercury_import(_, Name) ->
+			( is_std_lib_module(Name, StdLibName) ->
+			    ( mercury_std_library_module_name(ModuleName) ->
+				Str = StdLibName
+			    ;
+				Str = "mercury"
+			    )
+			;
+			    SymName = mlds_module_name_to_sym_name(Name),
+			    prog_out__sym_name_to_string(SymName, ".", Str)
+			),
+			Result = [Str]
+		    ;
+			Result = []
+		    )
+		), Imports, ImportListList) },
+	{ ActualImports = remove_dups(condense(ImportListList)) },
+
+	list__foldl((pred(I::in, di, uo) is det -->
+			io__write_string("#using """),
+			io__write_string(I),
+			io__write_string(".dll""\n")
+		), ActualImports),
+
 	{ prog_out__sym_name_to_string(ModuleName, ModuleNameStr) },
 	io__write_strings([
-		"#using <mscorlib.dll>\n",
-		"#include ""mercury_mcpp.h""\n",
-		"#using ""mercury_mcpp.dll""\n",
-		"#using ""mercury_il.dll""\n",
 		"#using """, ModuleNameStr, ".dll""\n",
+		"#include ""mercury_mcpp.h""\n",
 
 		% XXX We have to use the mercury namespace, as
 		% llds_out still generates some of the code used
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.235
diff -u -r1.235 modules.m
--- compiler/modules.m	22 Jun 2002 19:15:55 -0000	1.235
+++ compiler/modules.m	27 Jun 2002 16:05:12 -0000
@@ -45,6 +45,10 @@
 
 %-----------------------------------------------------------------------------%
 
+	% Succeeds iff the module refered to by the module name is one
+	% of the modules in the standard library.
+:- pred mercury_std_library_module_name(module_name::in) is semidet.
+
 	% Succeeds iff the string is the (unqualified) name of one of the
 	% modules in the Mercury standard library.
 	%
@@ -685,6 +689,11 @@
 :- import_module getopt.
 
 %-----------------------------------------------------------------------------%
+
+mercury_std_library_module_name(unqualified(Name)) :-
+	mercury_std_library_module(Name).
+mercury_std_library_module_name(qualified(unqualified("mercury"), Name)) :-
+	mercury_std_library_module(Name).
 
 mercury_std_library_module("array").
 mercury_std_library_module("assoc_list").

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