[m-rev.] for review: remove depenency between parse_tree and backend_libs

Julien Fischer juliensf at cs.mu.OZ.AU
Mon Mar 21 13:26:31 AEDT 2005


For review by anyone.

Estimated hours taken: 3.5
Branches: main

Simplify the structure of the compiler by removing the cycle
parse_tree -> backend_libs -> check_hlds -> parse_tree
from the package dependency graph.

I've done this by factoring out the code in backend_libs.foreign
and backend_libs.name_mangle that is needed by the frontend of
the compiler and putting it in a new module, parse_tree.prog_foreign.
This removes the dependency between the parse_tree and backend_libs
packages.

The obvious downside to this is that the name mangler is now
split in two, although such a division was always in implicit
in the predicates of the name_mangle module anyway, ie. between
those bits that operate on the HLDS/MLDS/LLDS level data structures
and those that don't.

compiler/name_mangle.m:
compiler/foreign.m:
compiler/prog_foreign.m:
	Move code for dealing with foreign language procedures that
	is required by the parse_tree package into a new module,
	prog_foreign.

	Update the formatting in some of these modules so that
	they match our current coding standard.

compiler/*.m:
	Update to reflect the above change.

compiler/notes/compiler_design.html:
	Include the new module.

	Fix some spelling errors.

Julien.

Workspace:/home/swordfish/juliensf/ws70
Index: compiler/c_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/c_util.m,v
retrieving revision 1.22
diff -u -r1.22 c_util.m
--- compiler/c_util.m	19 Jan 2005 03:10:29 -0000	1.22
+++ compiler/c_util.m	21 Mar 2005 01:18:23 -0000
@@ -151,6 +151,7 @@
 :- import_module libs__globals.
 :- import_module libs__options.
 :- import_module backend_libs__name_mangle.
+:- import_module parse_tree__prog_foreign.

 :- import_module list, bool.

Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.66
diff -u -r1.66 compile_target_code.m
--- compiler/compile_target_code.m	15 Feb 2005 05:22:16 -0000	1.66
+++ compiler/compile_target_code.m	20 Mar 2005 23:27:36 -0000
@@ -164,6 +164,7 @@
 :- import_module libs__options.
 :- import_module libs__trace_params.
 :- import_module parse_tree__error_util.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.

 :- import_module char, dir, getopt_io, int, require, string.
Index: compiler/export.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/export.m,v
retrieving revision 1.82
diff -u -r1.82 export.m
--- compiler/export.m	19 Jan 2005 03:10:32 -0000	1.82
+++ compiler/export.m	21 Mar 2005 01:18:58 -0000
@@ -81,6 +81,7 @@
 :- import_module libs__options.
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_util.

 :- import_module term, varset.
Index: compiler/fact_table.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/fact_table.m,v
retrieving revision 1.59
diff -u -r1.59 fact_table.m
--- compiler/fact_table.m	27 Jan 2005 03:38:06 -0000	1.59
+++ compiler/fact_table.m	21 Mar 2005 01:22:53 -0000
@@ -86,6 +86,7 @@
 % Parse tree modules
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
Index: compiler/foreign.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/foreign.m,v
retrieving revision 1.44
diff -u -r1.44 foreign.m
--- compiler/foreign.m	21 Jan 2005 03:27:37 -0000	1.44
+++ compiler/foreign.m	21 Mar 2005 01:20:13 -0000
@@ -117,26 +117,6 @@
 :- func to_type_string(foreign_language, exported_type) = string.
 :- func to_type_string(foreign_language, module_info, (type)) = string.

-	%
-	% foreign_import_module_name(ForeignImport)
-	%
-	% returns the module name which represents the ForeignImport.
-	%
-	% For instance for the foreign_import_module representing
-	% 	:- foreign_import_module("MC++", module)
-	% would return the module_name
-	% 	unqualified("module__cpp_code")
-	%
-:- func foreign_import_module_name(foreign_import_module) = module_name.
-
-	% foreign_import_module_name(ForeignImport, CurrentModule)
-	%
-	% returns the module name needed to refer to ForeignImport from the
-	% CurrentModule.
-	%
-:- func foreign_import_module_name(foreign_import_module, module_name) =
-	module_name.
-
 	% Filter the decls for the given foreign language.
 	% The first return value is the list of matches, the second is
 	% the list of mis-matches.
@@ -185,51 +165,12 @@
 	prog_varset::out, list(pragma_var)::out, list(type)::out, arity::out,
 	pred_or_func::out) is det.

-	% It is possible that more than one foreign language could be used to
-	% implement a particular piece of code.
-	% Therefore, foreign languages have an order of preference, from most
-	% preferred to least perferred.
-	% prefer_foreign_language(Globals, Target, Lang1, Lang2) returns the
-	% yes if Lang2 is preferred over Lang1.
-	%
-	% Otherwise it will return no.
-
-:- func prefer_foreign_language(globals, compilation_target,
-	foreign_language, foreign_language) = bool.
-
-	% Sub-type of foreign_language for languages for which
-	% we generate external files for foreign code.
-:- inst lang_gen_ext_file
-	--->	c
-	;	managed_cplusplus
-	;	csharp.
-
-	% The file extension used for this foreign language (including
-	% the dot).
-	% Not all foreign languages generate external files,
-	% so this function only succeeds for those that do.
-:- func foreign_language_file_extension(foreign_language) = string.
-:- mode foreign_language_file_extension(in) = out is semidet.
-:- mode foreign_language_file_extension(in(lang_gen_ext_file)) = out is det.
-
-	% The module name used for this foreign language.
-	% Not all foreign languages generate external modules
-	% so this function only succeeds for those that do.
-:- func foreign_language_module_name(module_name, foreign_language) =
-		module_name.
-:- mode foreign_language_module_name(in, in) = out is semidet.
-:- mode foreign_language_module_name(in, in(lang_gen_ext_file)) = out is det.
-
 	% The name of the #define which can be used to guard declarations with
 	% to prevent entities being declared twice.
 :- func decl_guard(sym_name) = string.

-:- func foreign_type_language(foreign_language_type) = foreign_language.
-
-	% The `multi' mode returns all supported foreign languages.
-:- pred foreign_language(foreign_language).
-:- mode foreign_language(in) is det.
-:- mode foreign_language(out) is multi.
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.

@@ -243,6 +184,7 @@
 :- import_module libs__globals.
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
 :- import_module parse_tree__prog_type.
@@ -250,49 +192,6 @@
 :- import_module list, map, assoc_list, std_util, string, varset, int, term.
 :- import_module require.

-	% Currently we don't use the globals to compare foreign language
-	% interfaces, but if we added appropriate options we might want
-	% to do this later.
-
-	% When compiling to C, C is always preferred over any other language.
-prefer_foreign_language(_Globals, c, Lang1, Lang2) =
-	( Lang2 = c, not Lang1 = c ->
-		yes
-	;
-		no
-	).
-
-	% When compiling to asm, C is always preferred over any other language.
-prefer_foreign_language(_Globals, asm, Lang1, Lang2) =
-	( Lang2 = c, not Lang1 = c ->
-		yes
-	;
-		no
-	).
-
-	% Whe compiling to il, first we prefer il, then csharp, then
-	% managed_cplusplus, after that we don't care.
-prefer_foreign_language(_Globals, il, Lang1, Lang2) = Comp :-
-	PreferredList = [il, csharp, managed_cplusplus],
-
-	FindLangPriority = (func(L) = X :-
-		( list__nth_member_search(PreferredList, L, X0) ->
-			X = X0
-		;
-			X = list__length(PreferredList) + 1
-		)),
-	N1 = FindLangPriority(Lang1),
-	N2 = FindLangPriority(Lang2),
-	( N2 < N1 ->
-		Comp = yes
-	;
-		Comp = no
-	).
-
-	% Nothing useful to do here, but when we add Java as a
-	% foreign language, we should add it here.
-prefer_foreign_language(_Globals, java, _Lang1, _Lang2) = no.
-
 filter_decls(WantedLang, Decls0, LangDecls, NotLangDecls) :-
 	list__filter((pred(foreign_decl_code(Lang, _, _, _)::in) is semidet :-
 			WantedLang = Lang),
@@ -619,23 +518,6 @@

 	create_pragma_import_c_code(PragmaVars, ModuleInfo, C_Code3, C_Code).

-foreign_language_file_extension(c) = ".c".
-foreign_language_file_extension(managed_cplusplus) = ".cpp".
-foreign_language_file_extension(csharp) = ".cs".
-foreign_language_file_extension(java) = ".java".
-foreign_language_file_extension(il) = _ :- fail.
-
-foreign_language_module_name(M, L) = FM :-
-		% Only succeed if this language generates external files.
-	_ = foreign_language_file_extension(L),
-
-	Ending = "__" ++ simple_foreign_language_string(L) ++ "_code",
-	( M = unqualified(Name),
-		FM = unqualified(Name ++ Ending)
-	; M = qualified(Module, Name),
-		FM = qualified(Module, Name ++ Ending)
-	).
-
 %-----------------------------------------------------------------------------%

 have_foreign_type_for_backend(c, ForeignTypeBody,
@@ -793,96 +675,16 @@

 %-----------------------------------------------------------------------------%

-foreign_import_module_name(
-		foreign_import_module(Lang, ForeignImportModule, _)) =
-		ModuleName :-
-	(
-		Lang = c,
-		ModuleName = ForeignImportModule
-	;
-		Lang = il,
-		ModuleName = ForeignImportModule
-	;
-		Lang = java,
-		ModuleName = ForeignImportModule
-	;
-		Lang = managed_cplusplus,
-		ModuleName = foreign_language_module_name(ForeignImportModule,
-				Lang)
-	;
-		Lang = csharp,
-		ModuleName = foreign_language_module_name(ForeignImportModule,
-				Lang)
-	).
-
-foreign_import_module_name(ModuleForeignImported, CurrentModule) =
-		ImportedForeignCodeModuleName :-
-	ModuleForeignImported = foreign_import_module(Lang, _, _),
-	ImportedForeignCodeModuleName1 = ModuleForeignImported ^
-		foreign_import_module_name,
-	(
-		Lang = c,
-		ImportedForeignCodeModuleName = ImportedForeignCodeModuleName1
-	;
-		Lang = il,
-		ImportedForeignCodeModuleName = handle_std_library(
-			CurrentModule, ImportedForeignCodeModuleName1)
-	;
-		Lang = managed_cplusplus,
-		ImportedForeignCodeModuleName = handle_std_library(
-			CurrentModule, ImportedForeignCodeModuleName1)
-	;
-		Lang = csharp,
-		ImportedForeignCodeModuleName = handle_std_library(
-			CurrentModule, ImportedForeignCodeModuleName1)
-	;
-		Lang = java,
-		ImportedForeignCodeModuleName = handle_std_library(
-			CurrentModule, ImportedForeignCodeModuleName1)
-	).
-
-	%
-	% On the il backend, we need to refer to the module "mercury" when
-	% referencing a std library module when we are not actually building
-	% the std library.
-	%
-:- func handle_std_library(module_name, module_name) = module_name.
-
-handle_std_library(CurrentModule, ModuleName0) = ModuleName :-
-	(
-		mercury_std_library_module_name(ModuleName0),
-		\+ mercury_std_library_module_name(CurrentModule)
-	->
-		ModuleName = unqualified("mercury")
-	;
-		ModuleName = ModuleName0
-	).
-
-%-----------------------------------------------------------------------------%
-
 decl_guard(ModuleName) = UppercaseModuleName ++ "_DECL_GUARD" :-
 	MangledModuleName = sym_name_mangle(ModuleName),
 	string__to_upper(MangledModuleName, UppercaseModuleName).

 %-----------------------------------------------------------------------------%

-foreign_type_language(il(_)) = il.
-foreign_type_language(c(_)) = c.
-foreign_type_language(java(_)) = java.
-
-%-----------------------------------------------------------------------------%
-
-foreign_language(c).
-foreign_language(java).
-foreign_language(csharp).
-foreign_language(managed_cplusplus).
-foreign_language(il).
-
-%-----------------------------------------------------------------------------%
-
 :- func this_file = string.

 this_file = "foreign.m".

 %-----------------------------------------------------------------------------%
+:- end_module foreign.
 %-----------------------------------------------------------------------------%
Index: compiler/layout_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/layout_out.m,v
retrieving revision 1.44
diff -u -r1.44 layout_out.m
--- compiler/layout_out.m	6 Mar 2005 05:17:29 -0000	1.44
+++ compiler/layout_out.m	21 Mar 2005 01:41:52 -0000
@@ -95,6 +95,7 @@
 :- import_module libs__trace_params.
 :- import_module ll_backend__code_util.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__mercury_to_mercury.

Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.246
diff -u -r1.246 llds_out.m
--- compiler/llds_out.m	7 Mar 2005 05:00:25 -0000	1.246
+++ compiler/llds_out.m	21 Mar 2005 01:42:42 -0000
@@ -181,6 +181,7 @@
 :- import_module parse_tree__mercury_to_mercury.
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.

Index: compiler/make.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.24
diff -u -r1.24 make.m
--- compiler/make.m	27 Jan 2005 03:38:08 -0000	1.24
+++ compiler/make.m	21 Mar 2005 00:00:20 -0000
@@ -62,7 +62,6 @@
 :- import_module make__util.

 :- import_module backend_libs__compile_target_code.
-:- import_module backend_libs__foreign.
 :- import_module libs__globals.
 :- import_module libs__handle_options.
 :- import_module libs__options.
@@ -72,6 +71,7 @@
 :- import_module parse_tree__mercury_to_mercury.
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_io_util.
 :- import_module parse_tree__prog_out.
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.503
diff -u -r1.503 make_hlds.m
--- compiler/make_hlds.m	20 Mar 2005 02:24:34 -0000	1.503
+++ compiler/make_hlds.m	21 Mar 2005 00:16:07 -0000
@@ -133,6 +133,7 @@
 :- import_module parse_tree__mercury_to_mercury.
 :- import_module parse_tree__module_qual.
 :- import_module parse_tree__modules.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_io_dcg.
 :- import_module parse_tree__prog_io_goal.
@@ -6494,7 +6495,7 @@
         ClauseLang = foreign_language(OldLang),
         ( list__member(ProcId, ProcIds) ->
             (
-                yes = foreign__prefer_foreign_language(Globals, Target,
+                yes = prefer_foreign_language(Globals, Target,
                     OldLang, NewLang)
             ->
                 % This language is preferred to the old
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.328
diff -u -r1.328 mercury_compile.m
--- compiler/mercury_compile.m	20 Mar 2005 02:24:34 -0000	1.328
+++ compiler/mercury_compile.m	21 Mar 2005 00:22:08 -0000
@@ -38,6 +38,7 @@

 	% semantic analysis
 :- import_module libs__handle_options.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__modules.
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.169
diff -u -r1.169 mlds_to_c.m
--- compiler/mlds_to_c.m	1 Feb 2005 07:11:33 -0000	1.169
+++ compiler/mlds_to_c.m	21 Mar 2005 01:45:38 -0000
@@ -84,6 +84,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_type.

Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.102
diff -u -r1.102 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	1 Feb 2005 07:11:33 -0000	1.102
+++ compiler/mlds_to_gcc.m	21 Mar 2005 01:49:51 -0000
@@ -177,6 +177,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.

Index: compiler/mlds_to_ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_ilasm.m,v
retrieving revision 1.24
diff -u -r1.24 mlds_to_ilasm.m
--- compiler/mlds_to_ilasm.m	14 Jun 2004 04:16:20 -0000	1.24
+++ compiler/mlds_to_ilasm.m	21 Mar 2005 00:02:00 -0000
@@ -48,6 +48,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.

 :- import_module bool, int, map, string, set, list, assoc_list, term, std_util.
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.64
diff -u -r1.64 mlds_to_java.m
--- compiler/mlds_to_java.m	1 Feb 2005 07:11:34 -0000	1.64
+++ compiler/mlds_to_java.m	21 Mar 2005 01:46:27 -0000
@@ -110,6 +110,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.       % for mercury_std_library_name.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
 :- import_module parse_tree__prog_io.
Index: compiler/mlds_to_managed.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_managed.m,v
retrieving revision 1.16
diff -u -r1.16 mlds_to_managed.m
--- compiler/mlds_to_managed.m	1 Feb 2005 07:11:34 -0000	1.16
+++ compiler/mlds_to_managed.m	20 Mar 2005 23:40:25 -0000
@@ -59,6 +59,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.

 :- import_module bool, int, map, string, list, assoc_list, term, std_util.
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.319
diff -u -r1.319 modules.m
--- compiler/modules.m	10 Mar 2005 02:35:58 -0000	1.319
+++ compiler/modules.m	21 Mar 2005 01:07:24 -0000
@@ -777,14 +777,13 @@

 :- implementation.

-:- import_module backend_libs__foreign.
-:- import_module backend_libs__name_mangle.
 :- import_module libs__handle_options.
 :- import_module libs__options.
 :- import_module make.              % XXX undesirable dependency
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__mercury_to_mercury.
 :- import_module parse_tree__module_qual.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_io_util.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
Index: compiler/name_mangle.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/name_mangle.m,v
retrieving revision 1.10
diff -u -r1.10 name_mangle.m
--- compiler/name_mangle.m	19 Jan 2005 03:10:49 -0000	1.10
+++ compiler/name_mangle.m	21 Mar 2005 01:56:12 -0000
@@ -11,9 +11,13 @@
 % syntactically acceptable in all our target languages, meaning C, Java
 % and MSIL.

+% NOTE: some parts of the name mangling routines are defined in
+% prog_foreign.m because they are required by the frontend of the compiler,
+% for generating makefile fragment etc.
+
 % Warning: any changes to the name mangling algorithms implemented in this
-% module will also require changes to extras/dynamic_linking/name_mangle.m,
-% profiler/demangle.m and util/mdemangle.c.
+% module may also require changes to extras/dynamic_linking/name_mangle.m,
+% profiler/demangle.m, util/mdemangle.c and compiler/prog_foreign.m.

 %-----------------------------------------------------------------------------%

@@ -25,90 +29,73 @@

 :- import_module io, bool, string.

-	% Output a proc label.
+%-----------------------------------------------------------------------------%

+	% Output a proc label.
+	%
 :- pred output_proc_label(proc_label::in, io::di, io::uo) is det.

 	% Output a proc label. The boolean controls whether
 	% mercury_label_prefix is added to it.
-
+	%
 :- pred output_proc_label(proc_label::in, bool::in, io::di, io::uo) is det.

 	% Get a proc label string (used by procs which are exported to C).
 	% The boolean controls whether label_prefix is added to the string.
-
+	%
 :- func proc_label_to_c_string(proc_label, bool) = string.

-	% Mangle an arbitrary name into a C etc identifier
-
-:- func name_mangle(string) = string.
-
-	% Mangle a possibly module-qualified Mercury symbol name
-	% into a C identifier.
-
-:- func sym_name_mangle(sym_name) = string.
-
 	% Succeed iff the given name or sym_name doesn't need mangling.
-
+	%
 :- pred name_doesnt_need_mangling(string::in) is semidet.
 :- pred sym_name_doesnt_need_mangling(sym_name::in) is semidet.

-	% Produces a string of the form Module__Name.
-
-:- func qualify_name(string, string) = string.
-
 	% Create a name for base_typeclass_info.
-
+	%
 :- func make_base_typeclass_info_name(tc_name, string) = string.

 	% Output the name for base_typeclass_info,
 	% with the appropriate mercury_data_prefix.
-
+	%
 :- pred output_base_typeclass_info_name(tc_name::in, string::in,
 	io::di, io::uo) is det.

 	% Prints the name of the initialization function
 	% for a given module.
-
+	%
 :- pred output_init_name(module_name::in, io::di, io::uo) is det.

-	% Returns the name of the initialization function
-	% for a given module.
-
-:- func make_init_name(module_name) = string.
-
-	% Returns the name of the Aditi-RL code constant
-	% for a given module.
-
-:- func make_rl_data_name(module_name) = string.
-
 	% Print out the name of the tabling variable for the specified
 	% procedure.
-
+	%
 :- pred output_tabling_pointer_var_name(proc_label::in, io::di, io::uo) is det.

 	% To ensure that Mercury labels don't clash with C symbols, we
 	% prefix them with `mercury__'.
-
+	%
 :- func mercury_label_prefix = string.

 	% All the C data structures we generate which are either fully static
 	% or static after initialization should have one of these two prefixes,
 	% to ensure that Mercury global variables don't clash with C symbols.
-
+	%
 :- func mercury_data_prefix = string.
 :- func mercury_common_prefix = string.

 	% All the C types we generate should have this prefix to ensure
 	% that they don't clash with C symbols.
-
+	%
 :- func mercury_common_type_prefix = string.

+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- implementation.

 :- import_module hlds__hlds_pred.
 :- import_module hlds__special_pred.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_util.

 :- import_module char, int, list, std_util.
@@ -138,6 +125,7 @@

 	% For a special proc, output a label of the form:
 	% mercury____<PredName>___<TypeModule>__<TypeName>_<TypeArity>_<Mode>
+	%
 proc_label_to_c_string(special_proc(Module, SpecialPredId, TypeModule,
 		TypeName, TypeArity, ModeInt), AddPrefix) = ProcLabelString :-
 	% figure out the LabelName
@@ -180,9 +168,9 @@
 	arity, bool) = string.

 %
-% Warning: any changes to the name mangling algorithm here will also
-% require changes to extras/dynamic_linking/name_mangle.m, profiler/demangle.m
-% and util/mdemangle.c.
+% Warning: any changes to the name mangling algorithm here may also
+% require changes to extras/dynamic_linking/name_mangle.m, profiler/demangle.m,
+% util/mdemangle.c and compiler/prog_foreign.m.
 %
 make_pred_or_func_name(DefiningModule, PredOrFunc, DeclaringModule,
 		Name0, Arity, AddPrefix) = LabelName :-
@@ -227,34 +215,6 @@
 		string__prefix(Name, "__")
 	).

-%
-% Warning: any changes to the name mangling algorithm here will also
-% require changes to extras/dynamic_linking/name_mangle.m,
-% profiler/demangle.m and util/mdemangle.c.
-%
-
-name_mangle(Name) = MangledName :-
-	( string__is_alnum_or_underscore(Name) ->
-		% any names that start with `f_' are changed so that
-		% they start with `f__', so that we can use names starting
-		% with `f_' (followed by anything except an underscore)
-		% without fear of name collisions
-		( string__append("f_", Suffix, Name) ->
-			string__append("f__", Suffix, MangledName)
-		;
-			MangledName = Name
-		)
-	;
-		MangledName = convert_to_valid_c_identifier(Name)
-	).
-
-sym_name_mangle(unqualified(Name)) =
-	name_mangle(Name).
-sym_name_mangle(qualified(ModuleName, PlainName)) = MangledName :-
-	MangledModuleName = sym_name_mangle(ModuleName),
-	MangledPlainName = name_mangle(PlainName),
-	MangledName = qualify_name(MangledModuleName, MangledPlainName).
-
 	% Convert a Mercury predicate name into something that can form
 	% part of a C identifier.  This predicate is necessary because
 	% quoted names such as 'name with embedded spaces' are valid
@@ -270,19 +230,6 @@
 	sym_name_doesnt_need_mangling(ModuleName),
 	name_doesnt_need_mangling(PlainName).

-:- func convert_to_valid_c_identifier(string) = string.
-
-convert_to_valid_c_identifier(String) = Name :-
-	( name_conversion_table(String, Name0) ->
-		Name = Name0
-	;
-		Name0 = convert_to_valid_c_identifier_2(String),
-		string__append("f", Name0, Name)
-	).
-
-qualify_name(Module0, Name0) = Name :-
-	string__append_list([Module0, "__", Name0], Name).
-
 	% Produces a string of the form Module__Name, unless Module__
 	% is already a prefix of Name.

@@ -296,59 +243,6 @@
 		string__append(UnderscoresModule, Name0, Name)
 	).

-	% A table used to convert Mercury functors into
-	% C identifiers.  Feel free to add any new translations you want.
-	% The C identifiers should start with "f_",
-	% to avoid introducing name clashes.
-	% If the functor name is not found in the table, then
-	% we use a fall-back method which produces ugly names.
-
-:- pred name_conversion_table(string::in, string::out) is semidet.
-
-name_conversion_table("\\=", "f_not_equal").
-name_conversion_table(">=", "f_greater_or_equal").
-name_conversion_table("=<", "f_less_or_equal").
-name_conversion_table("=", "f_equal").
-name_conversion_table("<", "f_less_than").
-name_conversion_table(">", "f_greater_than").
-name_conversion_table("-", "f_minus").
-name_conversion_table("+", "f_plus").
-name_conversion_table("*", "f_times").
-name_conversion_table("/", "f_slash").
-name_conversion_table(",", "f_comma").
-name_conversion_table(";", "f_semicolon").
-name_conversion_table("!", "f_cut").
-name_conversion_table("{}", "f_tuple").
-name_conversion_table("[|]", "f_cons").
-name_conversion_table("[]", "f_nil").
-
-	% This is the fall-back method.
-	% Given a string, produce a C identifier
-	% for that string by concatenating the decimal
-	% expansions of the character codes in the string,
-	% separated by underlines.
-	% The C identifier will start with "f_"; this predicate
-	% constructs everything except the initial "f".
-	%
-	% For example, given the input "\n\t" we return "_10_8".
-
-:- func convert_to_valid_c_identifier_2(string) = string.
-
-convert_to_valid_c_identifier_2(String) = Name :-
-	( string__first_char(String, Char, Rest) ->
-		% XXX This will cause ABI incompatibilities between
-		%     compilers which are built in grades that have
-		%     different character representations.
-		char__to_int(Char, Code),
-		string__int_to_string(Code, CodeString),
-		string__append("_", CodeString, ThisCharString),
-		Name0 = convert_to_valid_c_identifier_2(Rest),
-		string__append(ThisCharString, Name0, Name)
-	;
-		% String is the empty string
-		Name = String
-	).
-
 %-----------------------------------------------------------------------------%

 output_base_typeclass_info_name(TCName, TypeNames, !IO) :-
@@ -372,15 +266,6 @@
 	InitName = make_init_name(ModuleName),
 	io__write_string(InitName, !IO).

-make_init_name(ModuleName) = InitName :-
-	MangledModuleName = sym_name_mangle(ModuleName),
-	string__append_list(["mercury__", MangledModuleName, "__"], InitName).
-
-make_rl_data_name(ModuleName) = RLDataConstName :-
-	MangledModuleName = sym_name_mangle(ModuleName),
-	string__append("mercury__aditi_rl_data__", MangledModuleName,
-		RLDataConstName).
-
 output_tabling_pointer_var_name(ProcLabel, !IO) :-
 	io__write_string("mercury_var__table_root__", !IO),
 	output_proc_label(ProcLabel, !IO).
@@ -395,4 +280,6 @@

 mercury_common_type_prefix = "mercury_type_".

+%-----------------------------------------------------------------------------%
+:- end_module name_mangle.
 %-----------------------------------------------------------------------------%
Index: compiler/opt_debug.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.147
diff -u -r1.147 opt_debug.m
--- compiler/opt_debug.m	1 Feb 2005 07:11:35 -0000	1.147
+++ compiler/opt_debug.m	21 Mar 2005 01:43:07 -0000
@@ -109,6 +109,7 @@
 :- import_module ll_backend__llds_out.
 :- import_module ll_backend__opt_util.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.

 :- import_module int, set, map, string.
Index: compiler/optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/optimize.m,v
retrieving revision 1.44
diff -u -r1.44 optimize.m
--- compiler/optimize.m	19 Jan 2005 03:10:49 -0000	1.44
+++ compiler/optimize.m	21 Mar 2005 01:43:32 -0000
@@ -49,6 +49,7 @@
 :- import_module ll_backend__use_local_vars.
 :- import_module ll_backend__wrap_blocks.
 :- import_module mdbcomp__prim_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.

 :- import_module bool, int, string.
Index: compiler/parse_tree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/parse_tree.m,v
retrieving revision 1.9
diff -u -r1.9 parse_tree.m
--- compiler/parse_tree.m	21 Jan 2005 03:27:44 -0000	1.9
+++ compiler/parse_tree.m	20 Mar 2005 23:05:39 -0000
@@ -14,8 +14,8 @@
 :- module parse_tree.
 :- interface.

+:- import_module backend_libs. % XXX
 :- import_module libs.
-:- import_module backend_libs. % XXX for `foreign'
 :- import_module mdbcomp.
 :- import_module recompilation.

@@ -35,6 +35,7 @@
 :- include_module prog_out.

 % Utility routines.
+:- include_module prog_foreign.
 :- include_module prog_mode.
 :- include_module prog_util.
 :- include_module prog_type.
Index: compiler/pragma_c_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/pragma_c_gen.m,v
retrieving revision 1.75
diff -u -r1.75 pragma_c_gen.m
--- compiler/pragma_c_gen.m	24 Feb 2005 06:07:09 -0000	1.75
+++ compiler/pragma_c_gen.m	21 Mar 2005 01:43:56 -0000
@@ -61,6 +61,7 @@
 :- import_module ll_backend__llds_out.
 :- import_module ll_backend__trace.
 :- import_module parse_tree__error_util.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_type.

 :- import_module bool, string, int, assoc_list, set, map.
Index: compiler/prog_foreign.m
===================================================================
RCS file: compiler/prog_foreign.m
diff -N compiler/prog_foreign.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ compiler/prog_foreign.m	21 Mar 2005 02:00:53 -0000
@@ -0,0 +1,394 @@
+%-----------------------------------------------------------------------------%
+% Copyright (C) 2000-2005 The University of Melbourne.
+% This file may only be copied under the terms of the GNU General
+% Public License - see the file COPYING in the Mercury distribution.
+%-----------------------------------------------------------------------------%
+
+% This module defines predicate for interfacing with foreign languages.
+% that are necessary for the frontend of the compiler to construct
+% the list of items.  The predicates in this module should not depend
+% on the HLDS in any way.  The predicates for interfacing with foreign
+% languages that do depend on the HLDS are defined in foreign.m.
+
+% This module also contains the parts of the name mangler that are used
+% by the frontend of the compiler.
+
+% Warning: any changes to the name mangling algorithms implemented in this
+% module may also require changes to extras/dynamic_linking/name_mangle.m,
+% profiler/demangle.m, util/mdemangle.c and compiler/name_mangle.m.
+
+% Main authors: trd, dgj.
+% These code was originally part of the foreign module and was moved here.
+
+%-----------------------------------------------------------------------------%
+
+:- module parse_tree.prog_foreign.
+
+:- interface.
+
+:- import_module libs.globals.
+:- import_module parse_tree.prog_data.
+:- import_module mdbcomp.prim_data.
+
+:- import_module bool.
+
+%-----------------------------------------------------------------------------%
+
+	% foreign_import_module_name(ForeignImport)
+	%
+	% returns the module name which represents the ForeignImport.
+	%
+	% For instance for the foreign_import_module representing
+	% 	:- foreign_import_module("MC++", module)
+	% would return the module_name
+	% 	unqualified("module__cpp_code")
+	%
+:- func foreign_import_module_name(foreign_import_module) = module_name.
+
+	% foreign_import_module_name(ForeignImport, CurrentModule)
+	%
+	% returns the module name needed to refer to ForeignImport from the
+	% CurrentModule.
+	%
+:- func foreign_import_module_name(foreign_import_module, module_name) =
+	module_name.
+
+	% Sub-type of foreign_language for languages for which
+	% we generate external files for foreign code.
+	%
+:- inst lang_gen_ext_file
+	--->	c
+	;	managed_cplusplus
+	;	csharp.
+
+	% The module name used for this foreign language.
+	% Not all foreign languages generate external modules
+	% so this function only succeeds for those that do.
+	%
+:- func foreign_language_module_name(module_name, foreign_language) =
+		module_name.
+:- mode foreign_language_module_name(in, in) = out is semidet.
+:- mode foreign_language_module_name(in, in(lang_gen_ext_file)) = out is det.
+
+	% The file extension used for this foreign language (including the dot).
+	% Not all foreign languages generate external files,
+	% so this function only succeeds for those that do.
+	%
+:- func foreign_language_file_extension(foreign_language) = string.
+:- mode foreign_language_file_extension(in) = out is semidet.
+:- mode foreign_language_file_extension(in(lang_gen_ext_file)) = out is det.
+
+	% It is possible that more than one foreign language could be used to
+	% implement a particular piece of code.
+	% Therefore, foreign languages have an order of preference, from most
+	% preferred to least perferred.
+	% prefer_foreign_language(Globals, Target, Lang1, Lang2) returns the
+	% yes if Lang2 is preferred over Lang1.
+	%
+	% Otherwise it will return no.
+	%
+:- func prefer_foreign_language(globals, compilation_target,
+	foreign_language, foreign_language) = bool.
+
+	% The `multi' mode returns all supported foreign languages.
+	%
+:- pred foreign_language(foreign_language).
+:- mode foreign_language(in) is det.
+:- mode foreign_language(out) is multi.
+
+:- func foreign_type_language(foreign_language_type) = foreign_language.
+
+%
+% The following are the parts of the name mangler that are needed by
+% the compiler frontend so that it can write out makefile fragments.
+%
+
+	% Returns the name of the initialization function
+	% for a given module.
+	%
+:- func make_init_name(module_name) = string.
+
+	% Returns the name of the Aditi-RL code constant
+	% for a given module.
+	%
+:- func make_rl_data_name(module_name) = string.
+
+	% Mangle a possibly module-qualified Mercury symbol name
+	% into a C identifier.
+	%
+:- func sym_name_mangle(sym_name) = string.
+
+	% Mangle an arbitrary name into a C etc identifier
+	%
+:- func name_mangle(string) = string.
+
+	% Produces a string of the form Module__Name.
+	%
+:- func qualify_name(string, string) = string.
+
+:- func convert_to_valid_c_identifier(string) = string.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module parse_tree.modules.
+
+:- import_module char.
+:- import_module int.
+:- import_module list.
+:- import_module string.
+
+%-----------------------------------------------------------------------------%
+
+foreign_import_module_name(
+		foreign_import_module(Lang, ForeignImportModule, _)) =
+		ModuleName :-
+	(
+		Lang = c,
+		ModuleName = ForeignImportModule
+	;
+		Lang = il,
+		ModuleName = ForeignImportModule
+	;
+		Lang = java,
+		ModuleName = ForeignImportModule
+	;
+		Lang = managed_cplusplus,
+		ModuleName = foreign_language_module_name(ForeignImportModule,
+				Lang)
+	;
+		Lang = csharp,
+		ModuleName = foreign_language_module_name(ForeignImportModule,
+				Lang)
+	).
+
+foreign_import_module_name(ModuleForeignImported, CurrentModule) =
+		ImportedForeignCodeModuleName :-
+	ModuleForeignImported = foreign_import_module(Lang, _, _),
+	ImportedForeignCodeModuleName1 = ModuleForeignImported ^
+		foreign_import_module_name,
+	(
+		Lang = c,
+		ImportedForeignCodeModuleName = ImportedForeignCodeModuleName1
+	;
+		Lang = il,
+		ImportedForeignCodeModuleName = handle_std_library(
+			CurrentModule, ImportedForeignCodeModuleName1)
+	;
+		Lang = managed_cplusplus,
+		ImportedForeignCodeModuleName = handle_std_library(
+			CurrentModule, ImportedForeignCodeModuleName1)
+	;
+		Lang = csharp,
+		ImportedForeignCodeModuleName = handle_std_library(
+			CurrentModule, ImportedForeignCodeModuleName1)
+	;
+		Lang = java,
+		ImportedForeignCodeModuleName = handle_std_library(
+			CurrentModule, ImportedForeignCodeModuleName1)
+	).
+
+	% On the il backend, we need to refer to the module "mercury" when
+	% referencing a std library module when we are not actually building
+	% the std library.
+	%
+:- func handle_std_library(module_name, module_name) = module_name.
+
+handle_std_library(CurrentModule, ModuleName0) = ModuleName :-
+	(
+		mercury_std_library_module_name(ModuleName0),
+		\+ mercury_std_library_module_name(CurrentModule)
+	->
+		ModuleName = unqualified("mercury")
+	;
+		ModuleName = ModuleName0
+	).
+
+%-----------------------------------------------------------------------------%
+
+foreign_language_module_name(M, L) = FM :-
+		% Only succeed if this language generates external files.
+	_ = foreign_language_file_extension(L),
+
+	Ending = "__" ++ simple_foreign_language_string(L) ++ "_code",
+	( M = unqualified(Name),
+		FM = unqualified(Name ++ Ending)
+	; M = qualified(Module, Name),
+		FM = qualified(Module, Name ++ Ending)
+	).
+
+%-----------------------------------------------------------------------------%
+
+foreign_language_file_extension(c) = ".c".
+foreign_language_file_extension(managed_cplusplus) = ".cpp".
+foreign_language_file_extension(csharp) = ".cs".
+foreign_language_file_extension(java) = ".java".
+foreign_language_file_extension(il) = _ :- fail.
+
+%-----------------------------------------------------------------------------%
+
+	% Currently we don't use the globals to compare foreign language
+	% interfaces, but if we added appropriate options we might want
+	% to do this later.
+
+	% When compiling to C, C is always preferred over any other language.
+prefer_foreign_language(_Globals, c, Lang1, Lang2) =
+	( Lang2 = c, not Lang1 = c ->
+		yes
+	;
+		no
+	).
+
+	% When compiling to asm, C is always preferred over any other language.
+prefer_foreign_language(_Globals, asm, Lang1, Lang2) =
+	( Lang2 = c, not Lang1 = c ->
+		yes
+	;
+		no
+	).
+
+	% Whe compiling to il, first we prefer il, then csharp, then
+	% managed_cplusplus, after that we don't care.
+prefer_foreign_language(_Globals, il, Lang1, Lang2) = Comp :-
+	PreferredList = [il, csharp, managed_cplusplus],
+
+	FindLangPriority = (func(L) = X :-
+		( list__nth_member_search(PreferredList, L, X0) ->
+			X = X0
+		;
+			X = list__length(PreferredList) + 1
+		)),
+	N1 = FindLangPriority(Lang1),
+	N2 = FindLangPriority(Lang2),
+	( N2 < N1 ->
+		Comp = yes
+	;
+		Comp = no
+	).
+
+	% Nothing useful to do here, but when we add Java as a
+	% foreign language, we should add it here.
+prefer_foreign_language(_Globals, java, _Lang1, _Lang2) = no.
+
+%-----------------------------------------------------------------------------%
+
+foreign_language(c).
+foreign_language(java).
+foreign_language(csharp).
+foreign_language(managed_cplusplus).
+foreign_language(il).
+
+%-----------------------------------------------------------------------------%
+
+foreign_type_language(il(_)) = il.
+foreign_type_language(c(_)) = c.
+foreign_type_language(java(_)) = java.
+
+%-----------------------------------------------------------------------------%
+
+make_init_name(ModuleName) = InitName :-
+	MangledModuleName = sym_name_mangle(ModuleName),
+	string__append_list(["mercury__", MangledModuleName, "__"], InitName).
+
+make_rl_data_name(ModuleName) = RLDataConstName :-
+	MangledModuleName = sym_name_mangle(ModuleName),
+	string__append("mercury__aditi_rl_data__", MangledModuleName,
+		RLDataConstName).
+
+sym_name_mangle(unqualified(Name)) =
+	name_mangle(Name).
+sym_name_mangle(qualified(ModuleName, PlainName)) = MangledName :-
+	MangledModuleName = sym_name_mangle(ModuleName),
+	MangledPlainName = name_mangle(PlainName),
+	MangledName = qualify_name(MangledModuleName, MangledPlainName).
+
+%
+% Warning: any changes to the name mangling algorithm here may also
+% require changes to extras/dynamic_linking/name_mangle.m,
+% profiler/demangle.m, util/mdemangle.c and compiler/name_mangle.m.
+%
+
+name_mangle(Name) = MangledName :-
+	( string__is_alnum_or_underscore(Name) ->
+		% any names that start with `f_' are changed so that
+		% they start with `f__', so that we can use names starting
+		% with `f_' (followed by anything except an underscore)
+		% without fear of name collisions
+		( string__append("f_", Suffix, Name) ->
+			string__append("f__", Suffix, MangledName)
+		;
+			MangledName = Name
+		)
+	;
+		MangledName = convert_to_valid_c_identifier(Name)
+	).
+
+qualify_name(Module0, Name0) = Name :-
+	string__append_list([Module0, "__", Name0], Name).
+
+convert_to_valid_c_identifier(String) = Name :-
+	( name_conversion_table(String, Name0) ->
+		Name = Name0
+	;
+		Name0 = convert_to_valid_c_identifier_2(String),
+		string__append("f", Name0, Name)
+	).
+
+	% A table used to convert Mercury functors into
+	% C identifiers.  Feel free to add any new translations you want.
+	% The C identifiers should start with "f_",
+	% to avoid introducing name clashes.
+	% If the functor name is not found in the table, then
+	% we use a fall-back method which produces ugly names.
+
+:- pred name_conversion_table(string::in, string::out) is semidet.
+
+name_conversion_table("\\=", "f_not_equal").
+name_conversion_table(">=", "f_greater_or_equal").
+name_conversion_table("=<", "f_less_or_equal").
+name_conversion_table("=", "f_equal").
+name_conversion_table("<", "f_less_than").
+name_conversion_table(">", "f_greater_than").
+name_conversion_table("-", "f_minus").
+name_conversion_table("+", "f_plus").
+name_conversion_table("*", "f_times").
+name_conversion_table("/", "f_slash").
+name_conversion_table(",", "f_comma").
+name_conversion_table(";", "f_semicolon").
+name_conversion_table("!", "f_cut").
+name_conversion_table("{}", "f_tuple").
+name_conversion_table("[|]", "f_cons").
+name_conversion_table("[]", "f_nil").
+
+	% This is the fall-back method.
+	% Given a string, produce a C identifier
+	% for that string by concatenating the decimal
+	% expansions of the character codes in the string,
+	% separated by underlines.
+	% The C identifier will start with "f_"; this predicate
+	% constructs everything except the initial "f".
+	%
+	% For example, given the input "\n\t" we return "_10_8".
+
+:- func convert_to_valid_c_identifier_2(string) = string.
+
+convert_to_valid_c_identifier_2(String) = Name :-
+	( string__first_char(String, Char, Rest) ->
+		% XXX This will cause ABI incompatibilities between
+		%     compilers which are built in grades that have
+		%     different character representations.
+		char__to_int(Char, Code),
+		string__int_to_string(Code, CodeString),
+		string__append("_", CodeString, ThisCharString),
+		Name0 = convert_to_valid_c_identifier_2(Rest),
+		string__append(ThisCharString, Name0, Name)
+	;
+		% String is the empty string
+		Name = String
+	).
+
+%-----------------------------------------------------------------------------%
+:- end_module prog_foreign.
+%-----------------------------------------------------------------------------%
Index: compiler/rl_exprn.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl_exprn.m,v
retrieving revision 1.48
diff -u -r1.48 rl_exprn.m
--- compiler/rl_exprn.m	1 Feb 2005 07:11:37 -0000	1.48
+++ compiler/rl_exprn.m	21 Mar 2005 01:17:55 -0000
@@ -151,6 +151,7 @@
 :- import_module libs__globals.
 :- import_module libs__options.
 :- import_module mdbcomp__prim_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
 :- import_module parse_tree__prog_type.
Index: compiler/rtti.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti.m,v
retrieving revision 1.55
diff -u -r1.55 rtti.m
--- compiler/rtti.m	1 Feb 2005 07:11:38 -0000	1.55
+++ compiler/rtti.m	21 Mar 2005 01:21:36 -0000
@@ -790,6 +790,7 @@
 :- import_module check_hlds__mode_util.
 :- import_module check_hlds__type_util.
 :- import_module hlds__hlds_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_util.	% for mercury_public_builtin_module
 :- import_module parse_tree__prog_out.

Index: compiler/rtti_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti_out.m,v
retrieving revision 1.51
diff -u -r1.51 rtti_out.m
--- compiler/rtti_out.m	1 Feb 2005 07:11:38 -0000	1.51
+++ compiler/rtti_out.m	21 Mar 2005 01:44:27 -0000
@@ -96,6 +96,7 @@
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_foreign.
 :- import_module parse_tree__prog_out.

 :- import_module int, string, assoc_list, map, multi_map.
Index: compiler/notes/compiler_design.html
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/notes/compiler_design.html,v
retrieving revision 1.98
diff -u -r1.98 compiler_design.html
--- compiler/notes/compiler_design.html	22 Feb 2005 12:33:50 -0000	1.98
+++ compiler/notes/compiler_design.html	21 Mar 2005 02:22:50 -0000
@@ -278,7 +278,8 @@
 	for printing the parse tree.  prog_util.m contains some utility
 	predicates for manipulating the parse tree, prog_mode contains utility
 	predicates for manipulating insts and modes, prog_type contains utility
-	predicates for manipulating types, while error_util.m contains
+	predicates for manipulating types, prog_foreign contains utility
+	predicates for manipulating foreign code, while error_util.m contains
 	predicates for printing nicely formatting error messages.

 <li><p> imports and exports are handled at this point (modules.m)
@@ -305,13 +306,13 @@
 	<p>
  	Notes on module qualification:
 	<ul>
-	<li> all types, typeclasses, insts and modes occuring in pred, func,
+	<li> all types, typeclasses, insts and modes occurring in pred, func,
 	  type, typeclass and mode declarations are module qualified by
 	  module_qual.m.
- 	<li> all types, insts and modes occuring in lambda expressions,
+ 	<li> all types, insts and modes occurring in lambda expressions,
  	  explicit type qualifications, and clause mode annotations
 	  are module qualified in make_hlds.m.
- 	<li> constructors occuring in predicate and function mode declarations
+ 	<li> constructors occurring in predicate and function mode declarations
  	  are module qualified during type checking.
  	<li> predicate and function calls and constructors within goals
  	  are module qualified during mode analysis.
@@ -523,7 +524,7 @@
 	  type checking that can't be done in the main type checking pass.
 	  It also removes assertions from further processing.
 	  post_typecheck.m reports errors for unbound type and inst variables,
-	  for unsatisified type class constraints, for indistinguishable
+	  for unsatisfied type class constraints, for indistinguishable
 	  predicate or function modes, and for invalid Aditi calls and updates.
 	</ul>
 	<p>
@@ -840,7 +841,7 @@

 <li> attempt to introduce accumulators (accumulator.m).  This optimizes
   procedures whose tail consists of independent associative computations
-  or independant chains of commutative computations into a tail
+  or independent chains of commutative computations into a tail
   recursive form by the introduction of accumulators.  If lco is turned
   on it can also transform some procedures so that only construction
   unifications are after the recursive call.  This pass must come before
@@ -964,7 +965,7 @@
 			transformations have created new opportunities for
 			simplification.  It needs to be run immediately
 			before code generation, because it enforces some
-			invariants tha the LLDS code generator relies on.
+			invariants that the LLDS code generator relies on.
 		<dt> annotation of goals with liveness information (liveness.m)
 			<dd>
 			This records the birth and death of each variable
@@ -1083,7 +1084,7 @@
 		</dl>

 <dt> code generation for `pragma export' declarations (export.m)
-<dd> This is handled seperately from the other parts of code generation.
+<dd> This is handled separately from the other parts of code generation.
      mercury_compile.m calls the procedures `export__produce_header_file'
      and `export__get_pragma_exported_procs' to produce C code fragments
      which declare/define the C functions which are the interface stubs

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