[m-rev.] for review: pragma foreign_import_module on the IL backend
Peter Ross
pro at missioncriticalit.com
Sat Dec 21 00:51:29 AEDT 2002
I am just writing the changes to the documentation now.
diff log file:
--- zzlog.foreign_import_module 2002-12-20 14:31:52.000000000 +0100
+++ zzlog.foreign_import_module3 2002-12-20 14:45:11.000000000 +0100
@@ -1,5 +1,5 @@
-Estimated hours taken: 8
+Estimated hours taken: 12
Branches: main
Get pragma foreign_import_module working on the IL backend.
@@ -17,6 +17,10 @@
For managed C++ output a #using for every module implied by the
pragma foreign_import_module.
+compiler/compile_target_code.m:
+ Add the assemblies implied by the pragma foreign_import_module
+ to the C# compiler's command line.
+
compiler/modules.m:
Factor the code for outputting the dependencies implied by the
pragma foreign_import_modules so that they work for both the
@@ -24,6 +28,16 @@
For C# add a reference to every module implied by the pragma
foreign_import_module.
+compiler/make.dependencies.m:
+ Add the dependency that before we can build a MC++ or C#
+ assembly all the assemblies implied by the
+ foreign_import_modules must be built.
+
+compiler/make.module_target.m:
+ Detect when circular dependencies caused by cyclic
+ pragma foreign_import_module on the IL backend occur and print
+ an informative error message.
+
compiler/modules.m:
compiler/prog_io_pragma.m:
Remove constraints the pragma foreign_import_modules can only
interdiff:
diff -u compiler/foreign.m compiler/foreign.m
--- compiler/foreign.m
+++ compiler/foreign.m
@@ -90,7 +90,7 @@
:- func foreign__to_type_string(foreign_language, module_info, (type)) = string.
%
- % foreign__module_name(ForeignImport)
+ % foreign__foreign_import_module_name(ForeignImport)
%
% returns the module name which represents the ForeignImport.
%
@@ -99,14 +99,14 @@
% would return the module_name
% unqualified("module__cpp_code")
%
-:- func foreign__module_name(foreign_import_module) = module_name.
+:- func foreign__foreign_import_module_name(foreign_import_module) = module_name.
- % foreign__module_name(ForeignImport, CurrentModule)
+ % foreign__foreign_import_module_name(ForeignImport, CurrentModule)
%
% returns the module name needed to refer to ForeignImport from the
% CurrentModule.
%
-:- func foreign__module_name(foreign_import_module, module_name) =
+:- func foreign__foreign_import_module_name(foreign_import_module, module_name) =
module_name.
% Filter the decls for the given foreign language.
@@ -709,7 +709,8 @@
%-----------------------------------------------------------------------------%
-foreign__module_name(foreign_import_module(Lang, ForeignImportModule, _)) =
+foreign__foreign_import_module_name(
+ foreign_import_module(Lang, ForeignImportModule, _)) =
ModuleName :-
( Lang = c,
ModuleName = ForeignImportModule
@@ -723,18 +724,22 @@
Lang)
).
-foreign__module_name(ForeignImportModule, CurrentModule) =
- ModuleName :-
- ForeignImportModule = foreign_import_module(Lang, _, _),
- ModuleName1 = ForeignImportModule ^ foreign__module_name,
+foreign__foreign_import_module_name(ModuleForeignImported, CurrentModule) =
+ ImportedForeignCodeModuleName :-
+ ModuleForeignImported = foreign_import_module(Lang, _, _),
+ ImportedForeignCodeModuleName1 = ModuleForeignImported ^
+ foreign__foreign_import_module_name,
( Lang = c,
- ModuleName = ModuleName1
+ ImportedForeignCodeModuleName = ImportedForeignCodeModuleName1
; Lang = il,
- ModuleName = handle_std_library(CurrentModule, ModuleName1)
+ ImportedForeignCodeModuleName = handle_std_library(
+ CurrentModule, ImportedForeignCodeModuleName1)
; Lang = managed_cplusplus,
- ModuleName = handle_std_library(CurrentModule, ModuleName1)
+ ImportedForeignCodeModuleName = handle_std_library(
+ CurrentModule, ImportedForeignCodeModuleName1)
; Lang = csharp,
- ModuleName = handle_std_library(CurrentModule, ModuleName1)
+ ImportedForeignCodeModuleName = handle_std_library(
+ CurrentModule, ImportedForeignCodeModuleName1)
).
%
diff -u compiler/make.dependencies.m compiler/make.dependencies.m
--- compiler/make.dependencies.m
+++ compiler/make.dependencies.m
@@ -196,7 +195,15 @@
target_dependencies(_, foreign_il_asm(_)) =
combine_deps_list([
il_asm `of` self,
- il_asm `of` filter(maybe_keep_std_lib_module, direct_imports)
+ il_asm `of` filter(maybe_keep_std_lib_module, direct_imports),
+ il_asm `of` filter(maybe_keep_std_lib_module,
+ foreign_imports(il)),
+ foreign_il_asm(managed_cplusplus) `of`
+ filter(maybe_keep_std_lib_module,
+ foreign_imports(managed_cplusplus)),
+ foreign_il_asm(csharp) `of`
+ filter(maybe_keep_std_lib_module,
+ foreign_imports(csharp))
]).
target_dependencies(Globals, foreign_object(PIC, _)) =
get_foreign_deps(Globals, PIC).
@@ -584,3 +591,29 @@
%-----------------------------------------------------------------------------%
+ %
+ % foreign_imports(Lang, ModuleName, Success, Modules, !Info, !IO)
+ %
+ % From the module, ModuleName, extract the set of modules, Modules,
+ % which are mentioned in foreign_import_module declarations with the
+ % specified language, Lang.
+ %
+:- pred foreign_imports(foreign_language::in,
+ module_name::in, bool::out, set(module_name)::out,
+ make_info::in, make_info::out, io__state::di, io__state::uo) is det.
+
+foreign_imports(Lang, ModuleName, Success, Modules, !Info) -->
+ get_module_dependencies(ModuleName, MaybeImports, !Info),
+ { MaybeImports = yes(Imports),
+ list__filter_map((pred(FI::in, M::out) is semidet :-
+ FI = foreign_import_module(Lang, M, _)
+ ), Imports ^ foreign_import_module_info, ModulesList),
+ set__list_to_set(ModulesList, Modules),
+ Success = yes
+ ; MaybeImports = no,
+ Modules = set__init,
+ Success = no
+ }.
+
+%-----------------------------------------------------------------------------%
+
diff -u compiler/mlds_to_managed.m compiler/mlds_to_managed.m
--- compiler/mlds_to_managed.m
+++ compiler/mlds_to_managed.m
@@ -253,8 +253,8 @@
list__foldl(
(pred(ForeignImport::in, di, uo) is det -->
module_name_to_search_file_name(
- foreign__module_name(ForeignImport,
- ModuleName),
+ foreign_import_module_name(
+ ForeignImport, ModuleName),
".dll", FileName),
io__write_strings(["#using """,
FileName, """\n"])
diff -u compiler/modules.m compiler/modules.m
--- compiler/modules.m
+++ compiler/modules.m
@@ -2613,11 +2613,11 @@
%
{ list__filter_map(
(pred(ForeignImportMod::in, Import::out) is semidet :-
- Import = foreign__module_name(
+ Import = foreign_import_module_name(
ForeignImportMod,
SourceFileModuleName),
- % We can't include mercury.dll as mmake
+ % XXX We can't include mercury.dll as mmake
% can't find it, but we know that it exists.
Import \= unqualified("mercury")
), ForeignImports, ForeignImportedModules) },
@@ -2906,7 +2906,8 @@
},
{ ForeignDeps = list__map(
(func(M) =
- foreign__module_name(M, ModuleName)
+ foreign_import_module_name(
+ M, ModuleName)
), ForeignImports) },
{ Deps = AllDeps ++ ForeignDeps },
write_dll_dependencies_list(
only in patch2:
--- compiler/make.module_target.m 20 Dec 2002 09:46:18 -0000 1.19
+++ compiler/make.module_target.m 20 Dec 2002 13:32:19 -0000
@@ -170,8 +170,20 @@
{ Info = Info1 }
;
{ Status = being_built },
- { error(
- "make_module_target: target being built, circular dependencies?") },
+ ( { TargetFile = _FileName - foreign_il_asm(_Lang) } ->
+ io__write_string(
+ "error: circular dependency detected while building\n"),
+ io__write_string(" `"),
+ write_dependency_file(Dep),
+ io__write_string("'.\n"),
+ io__write_string(
+ " This is due to a forbidden foreign_import_module cycle.\n"),
+ io__set_exit_status(1)
+ ;
+ { error(
+ "make_module_target: target being built, circular dependencies?"
+ ) }
+ ),
{ Succeeded = no },
{ Info = Info1 }
;
only in patch2:
--- compiler/compile_target_code.m 20 Dec 2002 09:46:18 -0000 1.32
+++ compiler/compile_target_code.m 20 Dec 2002 13:32:19 -0000
@@ -160,6 +160,7 @@
:- import_module libs__options, libs__handle_options.
:- import_module hlds__passes_aux, libs__trace_params.
:- import_module parse_tree__prog_out.
+:- import_module backend_libs__foreign.
:- import_module ll_backend__llds_out. % for llds_out__make_init_name and
% llds_out__make_rl_data_name
@@ -295,8 +296,13 @@
;
Prefix = "/r:"
},
+ { ForeignDeps = list__map(
+ (func(M) =
+ foreign_import_module_name(M, Imports ^ module_name)
+ ), Imports ^ foreign_import_module_info ) },
{ ReferencedDlls = referenced_dlls(Imports ^ module_name,
- Imports ^ int_deps ++ Imports ^ impl_deps) },
+ Imports ^ int_deps ++ Imports ^ impl_deps ++
+ ForeignDeps) },
list__map_foldl((pred(Mod::in, Result::out, di, uo) is det -->
module_name_to_file_name(Mod, ".dll", no, FileName),
{ Result = [Prefix, FileName, " "] }
--------------------------------------------------------------------------
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