[m-rev.] for review: format C# file names according to which C# compiler we are using
Peter Ross
pro at missioncriticalit.com
Tue Jan 10 14:14:08 AEDT 2012
Hi,
===================================================================
Estimated hours taken: 4
Branches: main, 11.07
The Microsoft C# compiler only accepts paths in the Windows format, so
add code to format file names depending on which host environment we are
compiling and which C# compiler we are using.
compiler/compile_target_code.m:
Convert to file names to use windows paths when required.
compiler/globals.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/options.m:
m4/mercury.m4:
scripts/Mercury.config.in:
Add code to determine the C# compiler type and pass it to the compiler.
doc/user_guide.texi:
Document the --output-csharp-compiler-type option.
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.181
diff -u -r1.181 compile_target_code.m
--- compiler/compile_target_code.m 16 Dec 2011 03:38:20 -0000 1.181
+++ compiler/compile_target_code.m 10 Jan 2012 02:43:25 -0000
@@ -2735,7 +2735,14 @@
bool::out, io::di, io::uo) is det.
create_csharp_exe_or_lib(Globals, ErrorStream, LinkTargetType, MainModuleName,
- OutputFileName, SourceList, Succeeded, !IO) :-
+ OutputFileName0, SourceList0, Succeeded, !IO) :-
+
+ get_host_env_type(Globals, EnvType),
+ get_csharp_compiler_type(Globals, CSharpCompilerType),
+
+ OutputFileName = csharp_file_name(EnvType, CSharpCompilerType, OutputFileName0),
+ SourceList = list.map(csharp_file_name(EnvType, CSharpCompilerType), SourceList0),
+
globals.lookup_string_option(Globals, csharp_compiler, CSharpCompiler),
globals.lookup_bool_option(Globals, highlevel_data, HighLevelData),
(
@@ -2820,6 +2827,32 @@
Succeeded = Succeeded0
).
+ % Converts the given filename into a format acceptable to the C# compiler.
+ % Note we expect the given file name to be using "/" for the directory separator.
+ %
+:- func csharp_file_name(env_type, csharp_compiler_type, file_name) = file_name.
+
+csharp_file_name(env_type_posix, csharp_microsoft, Filename) = convert_to_windows_path_format(Filename).
+csharp_file_name(env_type_posix, csharp_mono, Filename) = Filename.
+csharp_file_name(env_type_posix, csharp_unknown, Filename) = Filename.
+
+csharp_file_name(env_type_cygwin, csharp_microsoft, Filename) = convert_to_windows_path_format(Filename).
+csharp_file_name(env_type_cygwin, csharp_mono, Filename) = Filename.
+csharp_file_name(env_type_cygwin, csharp_unknown, Filename) = Filename.
+
+ % MSYS converts the path for us to the windows format.
+csharp_file_name(env_type_msys, csharp_microsoft, Filename) = Filename.
+csharp_file_name(env_type_msys, csharp_mono, Filename) = Filename.
+csharp_file_name(env_type_msys, csharp_unknown, Filename) = Filename.
+
+csharp_file_name(env_type_win_cmd, csharp_microsoft, Filename) = convert_to_windows_path_format(Filename).
+csharp_file_name(env_type_win_cmd, csharp_mono, Filename) = Filename.
+csharp_file_name(env_type_win_cmd, csharp_unknown, Filename) = convert_to_windows_path_format(Filename).
+
+:- func convert_to_windows_path_format(file_name) = file_name.
+
+convert_to_windows_path_format(FileName) = string.replace_all(FileName, "/", "\\\\").
+
:- pred write_cli_shell_script(globals::in, string::in, io.output_stream::in,
io::di, io::uo) is det.
Index: compiler/globals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.104
diff -u -r1.104 globals.m
--- compiler/globals.m 21 Sep 2011 06:11:30 -0000 1.104
+++ compiler/globals.m 10 Jan 2012 02:43:25 -0000
@@ -146,6 +146,14 @@
; cc_cl(maybe(int))
; cc_unknown.
+ % For the csharp backend, which csharp compiler are we using?
+ %
+:- type csharp_compiler_type
+ ---> csharp_microsoft
+ ; csharp_mono
+ ; csharp_unknown
+ .
+
:- type clang_version
---> clang_version(int, int, int).
@@ -194,6 +202,8 @@
is semidet.
:- pred convert_c_compiler_type(string::in, c_compiler_type::out)
is semidet.
+:- pred convert_csharp_compiler_type(string::in, csharp_compiler_type::out)
+ is semidet.
:- pred convert_reuse_strategy(string::in, int::in, reuse_strategy::out)
is semidet.
:- pred convert_env_type(string::in, env_type::out) is semidet.
@@ -214,7 +224,8 @@
:- pred globals_init(option_table::in, compilation_target::in, gc_method::in,
tags_method::in, termination_norm::in, termination_norm::in,
trace_level::in, trace_suppress_items::in,
- may_be_thread_safe::in, c_compiler_type::in, reuse_strategy::in,
+ may_be_thread_safe::in, c_compiler_type::in, csharp_compiler_type::in,
+ reuse_strategy::in,
maybe(il_version_number)::in, maybe(feedback_info)::in, env_type::in,
env_type::in, globals::out) is det.
@@ -230,6 +241,7 @@
:- pred get_trace_suppress(globals::in, trace_suppress_items::out) is det.
:- pred get_maybe_thread_safe(globals::in, may_be_thread_safe::out) is det.
:- pred get_c_compiler_type(globals::in, c_compiler_type::out) is det.
+:- pred get_csharp_compiler_type(globals::in, csharp_compiler_type::out) is det.
:- pred get_reuse_strategy(globals::in, reuse_strategy::out) is det.
:- pred get_maybe_il_version_number(globals::in, maybe(il_version_number)::out)
is det.
@@ -504,6 +516,10 @@
Version > 0,
C_CompilerType = cc_cl(yes(Version)).
+convert_csharp_compiler_type("microsoft", csharp_microsoft).
+convert_csharp_compiler_type("mono", csharp_mono).
+convert_csharp_compiler_type("unknown", csharp_unknown).
+
convert_env_type("posix", env_type_posix).
convert_env_type("cygwin", env_type_cygwin).
convert_env_type("msys", env_type_msys).
@@ -555,6 +571,7 @@
g_trace_suppress_items :: trace_suppress_items,
g_may_be_thread_safe :: bool,
g_c_compiler_type :: c_compiler_type,
+ g_csharp_compiler_type :: csharp_compiler_type,
g_reuse_strategy :: reuse_strategy,
g_maybe_il_version_number :: maybe(il_version_number),
g_maybe_feedback :: maybe(feedback_info),
@@ -564,11 +581,13 @@
globals_init(Options, Target, GC_Method, TagsMethod,
TerminationNorm, Termination2Norm, TraceLevel, TraceSuppress,
- MaybeThreadSafe, C_CompilerType, ReuseStrategy, MaybeILVersion,
+ MaybeThreadSafe, C_CompilerType, CSharp_CompilerType,
+ ReuseStrategy, MaybeILVersion,
MaybeFeedback, HostEnvType, TargetEnvType, Globals) :-
Globals = globals(Options, Target, GC_Method, TagsMethod,
TerminationNorm, Termination2Norm, TraceLevel, TraceSuppress,
- MaybeThreadSafe, C_CompilerType, ReuseStrategy, MaybeILVersion,
+ MaybeThreadSafe, C_CompilerType, CSharp_CompilerType,
+ ReuseStrategy, MaybeILVersion,
MaybeFeedback, HostEnvType, TargetEnvType).
get_options(Globals, Globals ^ g_options).
@@ -581,6 +600,7 @@
get_trace_suppress(Globals, Globals ^ g_trace_suppress_items).
get_maybe_thread_safe(Globals, Globals ^ g_may_be_thread_safe).
get_c_compiler_type(Globals, Globals ^ g_c_compiler_type).
+get_csharp_compiler_type(Globals, Globals ^ g_csharp_compiler_type).
get_reuse_strategy(Globals, Globals ^ g_reuse_strategy).
get_maybe_il_version_number(Globals, Globals ^ g_maybe_il_version_number).
get_maybe_feedback_info(Globals, Globals ^ g_maybe_feedback).
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.374
diff -u -r1.374 handle_options.m
--- compiler/handle_options.m 2 Jan 2012 15:40:55 -0000 1.374
+++ compiler/handle_options.m 10 Jan 2012 02:43:25 -0000
@@ -213,13 +213,15 @@
Globals, !IO) :-
check_option_values(OptionTable0, OptionTable, Target, GC_Method,
TagsMethod, TermNorm, Term2Norm, TraceLevel, TraceSuppress,
- MaybeThreadSafe, C_CompilerType, ReuseStrategy, MaybeILVersion,
+ MaybeThreadSafe, C_CompilerType, CSharp_CompilerType,
+ ReuseStrategy, MaybeILVersion,
MaybeFeedbackInfo, HostEnvType, TargetEnvType, [], CheckErrors, !IO),
(
CheckErrors = [],
convert_options_to_globals(OptionTable, Target, GC_Method,
TagsMethod, TermNorm, Term2Norm, TraceLevel,
- TraceSuppress, MaybeThreadSafe, C_CompilerType, ReuseStrategy,
+ TraceSuppress, MaybeThreadSafe, C_CompilerType,
+ CSharp_CompilerType, ReuseStrategy,
MaybeILVersion, MaybeFeedbackInfo, HostEnvType, TargetEnvType,
[], Errors, Globals, !IO)
;
@@ -232,13 +234,15 @@
compilation_target::out, gc_method::out, tags_method::out,
termination_norm::out, termination_norm::out, trace_level::out,
trace_suppress_items::out, may_be_thread_safe::out,
- c_compiler_type::out, reuse_strategy::out, maybe(il_version_number)::out,
+ c_compiler_type::out, csharp_compiler_type::out,
+ reuse_strategy::out, maybe(il_version_number)::out,
maybe(feedback_info)::out, env_type::out, env_type::out,
list(string)::in, list(string)::out, io::di, io::uo) is det.
check_option_values(!OptionTable, Target, GC_Method, TagsMethod,
TermNorm, Term2Norm, TraceLevel, TraceSuppress, MaybeThreadSafe,
- C_CompilerType, ReuseStrategy, MaybeILVersion, MaybeFeedbackInfo,
+ C_CompilerType, CSharp_CompilerType,
+ ReuseStrategy, MaybeILVersion, MaybeFeedbackInfo,
HostEnvType, TargetEnvType, !Errors, !IO) :-
map.lookup(!.OptionTable, target, Target0),
(
@@ -399,6 +403,20 @@
!Errors)
),
+ map.lookup(!.OptionTable, csharp_compiler_type, CSharp_CompilerType0),
+ (
+ CSharp_CompilerType0 = string(CSharp_CompilerTypeStr),
+ convert_csharp_compiler_type(CSharp_CompilerTypeStr, CSharp_CompilerTypePrime)
+ ->
+ CSharp_CompilerType = CSharp_CompilerTypePrime
+ ;
+ CSharp_CompilerType = csharp_unknown, % dummy
+ add_error("Invalid argument to option `--csharp-compiler-type'\n" ++
+ "\t(must be `microsoft', `mono', or `unknown').",
+ !Errors),
+ true
+ ),
+
map.lookup(!.OptionTable, structure_reuse_constraint, ReuseConstraint0),
map.lookup(!.OptionTable, structure_reuse_constraint_arg,
ReuseConstraintArg0),
@@ -499,17 +517,20 @@
compilation_target::in, gc_method::in, tags_method::in,
termination_norm::in, termination_norm::in, trace_level::in,
trace_suppress_items::in, may_be_thread_safe::in, c_compiler_type::in,
+ csharp_compiler_type::in,
reuse_strategy::in, maybe(il_version_number)::in, maybe(feedback_info)::in,
env_type::in, env_type::in, list(string)::in, list(string)::out,
globals::out, io::di, io::uo) is det.
convert_options_to_globals(OptionTable0, Target, GC_Method, TagsMethod0,
TermNorm, Term2Norm, TraceLevel, TraceSuppress, MaybeThreadSafe,
- C_CompilerType, ReuseStrategy, MaybeILVersion, MaybeFeedbackInfo,
+ C_CompilerType, CSharp_CompilerType,
+ ReuseStrategy, MaybeILVersion, MaybeFeedbackInfo,
HostEnvType, TargetEnvType, !Errors, !:Globals, !IO) :-
globals_init(OptionTable0, Target, GC_Method, TagsMethod0,
TermNorm, Term2Norm, TraceLevel, TraceSuppress, MaybeThreadSafe,
- C_CompilerType, ReuseStrategy, MaybeILVersion, MaybeFeedbackInfo,
+ C_CompilerType, CSharp_CompilerType,
+ ReuseStrategy, MaybeILVersion, MaybeFeedbackInfo,
HostEnvType, TargetEnvType, !:Globals),
globals.lookup_string_option(!.Globals, event_set_file_name,
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.517
diff -u -r1.517 mercury_compile.m
--- compiler/mercury_compile.m 1 Dec 2011 04:59:28 -0000 1.517
+++ compiler/mercury_compile.m 10 Jan 2012 02:43:25 -0000
@@ -340,6 +340,7 @@
globals.lookup_bool_option(Globals, output_cc, OutputCC),
globals.lookup_bool_option(Globals, output_c_compiler_type, OutputCCType),
globals.lookup_bool_option(Globals, output_cflags, OutputCFlags),
+ globals.lookup_bool_option(Globals, output_csharp_compiler_type, OutputCSCType),
globals.lookup_bool_option(Globals, output_library_link_flags,
OutputLibraryLinkFlags),
globals.lookup_bool_option(Globals, make, Make),
@@ -393,6 +394,10 @@
; OutputCFlags = yes ->
io.stdout_stream(StdOut, !IO),
output_c_compiler_flags(Globals, StdOut, !IO)
+ ; OutputCSCType = yes ->
+ globals.lookup_string_option(Globals, csharp_compiler_type, CSC_Type),
+ io.stdout_stream(StdOut, !IO),
+ io.write_string(StdOut, CSC_Type ++ "\n", !IO)
; OutputLibraryLinkFlags = yes ->
io.stdout_stream(StdOut, !IO),
output_library_link_flags(Globals, StdOut, !IO)
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.710
diff -u -r1.710 options.m
--- compiler/options.m 14 Dec 2011 03:26:00 -0000 1.710
+++ compiler/options.m 10 Jan 2012 02:43:26 -0000
@@ -207,6 +207,7 @@
; output_libgrades
; output_cc
; output_c_compiler_type
+ ; output_csharp_compiler_type
; output_cflags
; output_library_link_flags
@@ -834,6 +835,7 @@
; pic_object_file_extension
; link_with_pic_object_file_extension
; c_compiler_type
+ ; csharp_compiler_type
% Java
; java_compiler
@@ -1191,6 +1193,7 @@
output_libgrades - bool(no),
output_cc - bool(no),
output_c_compiler_type - bool(no),
+ output_csharp_compiler_type - bool(no),
output_cflags - bool(no),
output_library_link_flags - bool(no)
]).
@@ -1708,9 +1711,11 @@
pic_object_file_extension - string(".o"),
link_with_pic_object_file_extension - string(".o"),
c_compiler_type - string("gcc"),
+ csharp_compiler_type - string("microsoft"),
% The `mmc' script will override the
% default with a value determined at
- % configuration time.
+ % configuration time for the above
+ % two options
% Java
java_compiler - string("javac"),
java_interpreter - string("java"),
@@ -2074,6 +2079,7 @@
long_option("output-cc", output_cc).
long_option("output-cc-type", output_c_compiler_type).
long_option("output-c-compiler-type", output_c_compiler_type).
+long_option("output-csharp-compiler-type", output_csharp_compiler_type).
long_option("output-cflags", output_cflags).
long_option("output-library-link-flags", output_library_link_flags).
@@ -2664,6 +2670,7 @@
long_option("link-with-pic-object-file-extension",
link_with_pic_object_file_extension).
long_option("c-compiler-type", c_compiler_type).
+long_option("csharp-compiler-type", csharp_compiler_type).
long_option("java-compiler", java_compiler).
@@ -3794,6 +3801,8 @@
"--output-cflags",
"\tPrint the flags with which the C compiler will be invoked",
"\tto the standard output.",
+ "--output-csharp-compiler-type",
+ "\tPrint the C# compiler type to the standard output.",
"--output-library-link-flags",
"\tPrint the flags that are passed to linker in order to link",
"\tagainst the current set of libraries. This includes the",
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.645
diff -u -r1.645 user_guide.texi
--- doc/user_guide.texi 2 Jan 2012 15:40:55 -0000 1.645
+++ doc/user_guide.texi 10 Jan 2012 02:43:27 -0000
@@ -6991,6 +6991,11 @@
to the standard output.
@sp 1
+ at itemx --output-csharp-compiler-type
+ at findex --output-csharp-compiler-type
+Print the C# compiler type to the standard output.
+
+ at sp 1
@item --output-library-link-flags
@findex --output-library-link-flags
Print the flags that are passed to the linker in order to link
Index: m4/mercury.m4
===================================================================
RCS file: /home/mercury1/repository/mercury/m4/mercury.m4,v
retrieving revision 1.4
diff -u -r1.4 mercury.m4
--- m4/mercury.m4 9 Jan 2012 00:35:41 -0000 1.4
+++ m4/mercury.m4 10 Jan 2012 02:43:27 -0000
@@ -253,6 +253,21 @@
AC_PATH_PROGS(CSC, csc gmcs cscc)
CSC=`basename "$CSC"`
+case "$CSC" in
+ csc*)
+ CSHARP_COMPILER_TYPE=microsoft
+ ;;
+
+ gmcs*)
+ CSHARP_COMPILER_TYPE=mono
+ ;;
+
+ *)
+ CSHARP_COMPILER_TYPE=unknown
+ ;;
+esac
+
+
# 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" &&
@@ -305,6 +320,7 @@
AC_SUBST(ILASM)
AC_SUBST(GACUTIL)
AC_SUBST(CSC)
+AC_SUBST(CSHARP_COMPILER_TYPE)
AC_SUBST(MS_AL)
AC_SUBST(MS_DOTNET_SDK_DIR)
AC_SUBST(MS_DOTNET_LIBRARY_VERSION)
Index: scripts/Mercury.config.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/Mercury.config.in,v
retrieving revision 1.28
diff -u -r1.28 Mercury.config.in
--- scripts/Mercury.config.in 8 Nov 2011 03:11:42 -0000 1.28
+++ scripts/Mercury.config.in 10 Jan 2012 02:43:27 -0000
@@ -31,6 +31,7 @@
MERCURY_JAVA_COMPILER=@JAVAC@
MERCURY_JAVA_INTERPRETER=@JAVA_INTERPRETER@
MERCURY_CSHARP_COMPILER=@CSC@
+MERCURY_CSHARP_COMPILER_TYPE=@CSHARP_COMPILER_TYPE@
MERCURY_CLI_INTERPRETER=@CLI_INTERPRETER@
MERCURY_ERLANG_COMPILER=@ERLC@
MERCURY_ERLANG_INTERPRETER=@ERL@
@@ -57,6 +58,7 @@
--java-compiler "$(MERCURY_JAVA_COMPILER)" \
--java-interpreter "$(MERCURY_JAVA_INTERPRETER)" \
--csharp-compiler "$(MERCURY_CSHARP_COMPILER)" \
+ --csharp-compiler-type "$(MERCURY_CSHARP_COMPILER_TYPE)" \
--cli-interpreter "$(MERCURY_CLI_INTERPRETER)" \
--erlang-compiler "$(MERCURY_ERLANG_COMPILER)" \
--erlang-interpreter "$(MERCURY_ERLANG_INTERPRETER)" \
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list