mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 20:34:19 +00:00
Fix a compiler abort with `--use-subdirs'.
Estimated hours taken: 1 Branches: main compiler/mlds_to_ilasm.m: Fix a compiler abort with `--use-subdirs'. tests/valid/Mmakefile: tests/valid/csharp_hello.m: Test case.
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
:- import_module hlds__hlds_pred. % for `pred_proc_id'.
|
||||
:- import_module parse_tree__prog_data, parse_tree__prog_out.
|
||||
:- import_module backend_libs__rtti, check_hlds__type_util, hlds__error_util.
|
||||
:- import_module backend_libs__foreign.
|
||||
|
||||
:- import_module ml_backend__ilds, ml_backend__ilasm, ml_backend__il_peephole.
|
||||
:- import_module ml_backend__ml_util, ml_backend__ml_code_util.
|
||||
@@ -70,20 +71,30 @@ output_mlds(MLDS) -->
|
||||
|
||||
output_foreign_file(MLDS, ForeignLang) -->
|
||||
{ ModuleName = mlds__get_module_name(MLDS) },
|
||||
{ handle_foreign_lang(ForeignLang, Extension, CodeGenerator) },
|
||||
module_name_to_file_name(ModuleName, Extension, yes, File),
|
||||
output_to_file(File, (pred(di, uo) is det --> CodeGenerator(MLDS))).
|
||||
(
|
||||
{ ForeignModuleName = foreign_language_module_name(ModuleName,
|
||||
ForeignLang) },
|
||||
{ Extension = foreign_language_file_extension(ForeignLang) }
|
||||
->
|
||||
{ handle_foreign_lang(ForeignLang, CodeGenerator) },
|
||||
module_name_to_file_name(ForeignModuleName, Extension,
|
||||
yes, File),
|
||||
output_to_file(File,
|
||||
(pred(di, uo) is det --> CodeGenerator(MLDS)))
|
||||
;
|
||||
{ error(
|
||||
"mlds_to_ilasm__output_foreign_file: unexpected language") }
|
||||
).
|
||||
|
||||
:- pred handle_foreign_lang(foreign_language::in, string::out,
|
||||
:- pred handle_foreign_lang(foreign_language::in,
|
||||
pred(mlds, io__state, io__state)::out(pred(in, di, uo) is det))
|
||||
is det.
|
||||
|
||||
handle_foreign_lang(managed_cplusplus, "__cpp_code.cpp",
|
||||
output_managed_code(managed_cplusplus)).
|
||||
handle_foreign_lang(csharp, "__csharp_code.cs", output_managed_code(csharp)).
|
||||
handle_foreign_lang(c, _, _) :-
|
||||
handle_foreign_lang(managed_cplusplus, output_managed_code(managed_cplusplus)).
|
||||
handle_foreign_lang(csharp, output_managed_code(csharp)).
|
||||
handle_foreign_lang(c, _) :-
|
||||
sorry(this_file, "language C foreign code not supported").
|
||||
handle_foreign_lang(il, _, _) :-
|
||||
handle_foreign_lang(il, _) :-
|
||||
sorry(this_file, "language IL foreign code not supported").
|
||||
|
||||
%
|
||||
|
||||
@@ -46,6 +46,7 @@ RLO_PROGS= \
|
||||
|
||||
# Tests for which we should only produce a `.il' file.
|
||||
IL_PROGS = \
|
||||
csharp_hello \
|
||||
foreign_type_spec
|
||||
|
||||
OTHER_PROGS= \
|
||||
|
||||
12
tests/valid/csharp_hello.m
Normal file
12
tests/valid/csharp_hello.m
Normal file
@@ -0,0 +1,12 @@
|
||||
:- module csharp_hello.
|
||||
:- interface.
|
||||
:- import_module io.
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
|
||||
:- pragma foreign_proc("C#", main(_IO0::di,_IO::uo),
|
||||
[will_not_call_mercury, promise_pure],
|
||||
"
|
||||
System.Console.WriteLine(""Hello Mercury/C# world"");
|
||||
").
|
||||
Reference in New Issue
Block a user