[m-rev.] for review: restore old behaviour of .cs target

Peter Wang novalazy at gmail.com
Tue Sep 21 11:47:59 AEST 2010


Branches: main

`.cs' targets were formerly used to tell `mmake' and `mmc --make' to generate
all the C files for a given target.  However, `.cs' is also the file name
extension for C# source files.  The recent addition of the C# backend
inadvertently changed the behaviour for `mmc --make'.

This patch restores `mmc --make's old interpretation of the `.cs' extension,
but adds new targets `.all_<ext>s' for both `mmake' and `mmc --make'.
The plan is to migrate to the latter syntax.

compiler/make.m:
compiler/make.util.m:
        Restore old behaviour for `.cs'.

        Accept `.all_<ext>s' syntax.

        Accept `.csharp' and `.all_csharps' as targets to generate C# files.
        This is only temporary.

compiler/file_names.m:
        The new `.all_<ext>s' mmake targets need to go in the current directory
        (not that the files actually exist).

compiler/write_deps_file.m:
        Write out `.all_<ext>s' rules in `.dep' files.

doc/user_guide.texi:
        Replace an instance of `.ints' in the documentation with `.all_ints'.

        Delete documentation of `.javas', `.classes', `.ils', `.erls', and
        `.beams' targets in the documentation.  `.cs', `.opts' and other
        targets are not documented either.  As far as I can tell, they are
        really designed to be used by bootcheck.

diff --git a/compiler/file_names.m b/compiler/file_names.m
index 3bab458..f5f6ed4 100644
--- a/compiler/file_names.m
+++ b/compiler/file_names.m
@@ -341,6 +341,12 @@ choose_file_name(Globals, _ModuleName, BaseParentDirs, BaseName, Ext,
             ; Ext = ".beams"
             ; Ext = ".opts"
             ; Ext = ".trans_opts"
+            ; Ext = ".all_ints"
+            ; Ext = ".all_int3s"
+            ; Ext = ".all_ss"
+            ; Ext = ".all_pic_ss"
+            ; Ext = ".all_opts"
+            ; Ext = ".all_trans_opts"
             )
         ;
             % Output files intended for use by the user.
diff --git a/compiler/make.m b/compiler/make.m
index 19703fe..a60db4c 100644
--- a/compiler/make.m
+++ b/compiler/make.m
@@ -450,7 +450,16 @@ classify_target(Globals, FileName, ModuleName - TargetType) :-
 
 classify_target_2(Globals, ModuleNameStr0, Suffix, ModuleName - TargetType) :-
     (
-        yes(Suffix) = target_extension(Globals, ModuleTargetType)
+        yes(Suffix) = target_extension(Globals, ModuleTargetType),
+        % The .cs extension was used to build all C target files, but .cs is
+        % also the file name extension for a C# file. The former use is being
+        % migrated over to the .all_cs target but we still accept it for now.
+        Suffix \= ".cs"
+    ->
+        ModuleNameStr = ModuleNameStr0,
+        TargetType = module_target(ModuleTargetType)
+    ;
+        target_extension_synonym(Suffix, ModuleTargetType)
     ->
         ModuleNameStr = ModuleNameStr0,
         TargetType = module_target(ModuleTargetType)
@@ -480,8 +489,19 @@ classify_target_2(Globals, ModuleNameStr0, Suffix, ModuleName - TargetType) :-
         ModuleNameStr = ModuleNameStr1,
         TargetType = linked_target(erlang_archive)
     ;
-        string.append(Suffix1, "s", Suffix),
-        yes(Suffix1) = target_extension(Globals, ModuleTargetType),
+        (
+            string.append(".all_", Rest, Suffix),
+            string.append(DotlessSuffix1, "s", Rest),
+            Suffix1 = "." ++ DotlessSuffix1
+        ;
+            % Deprecated.
+            string.append(Suffix1, "s", Suffix)
+        ),
+        (
+            yes(Suffix1) = target_extension(Globals, ModuleTargetType)
+        ;
+            target_extension_synonym(Suffix1, ModuleTargetType)
+        ),
         % Not yet implemented. `build_all' targets are only used by
         % tools/bootcheck, so it doesn't really matter.
         ModuleTargetType \= module_target_c_header(_)
diff --git a/compiler/make.util.m b/compiler/make.util.m
index 15d4a81..59c6cd9 100644
--- a/compiler/make.util.m
+++ b/compiler/make.util.m
@@ -222,6 +222,9 @@
 :- mode target_extension(in, in) = out is det.
 :- mode target_extension(in, out) = in(bound(yes(ground))) is nondet.
 
+:- pred target_extension_synonym(string::in, module_target_type::out)
+    is semidet.
+
 :- pred linked_target_file_name(globals::in, module_name::in,
     linked_target_type::in, file_name::out, io::di, io::uo) is det.
 
@@ -1403,6 +1406,10 @@ target_extension(_, module_target_foreign_object(_, _)) = no.
 target_extension(_, module_target_foreign_il_asm(_)) = no.
 target_extension(_, module_target_fact_table_object(_, _)) = no.
 
+    % Currently the .cs extension is still treated as the build-all target for
+    % C files, so we accept .csharp for C# files.
+target_extension_synonym(".csharp", module_target_csharp_code).
+
 linked_target_file_name(Globals, ModuleName, TargetType, FileName, !IO) :-
     (
         TargetType = executable,
diff --git a/compiler/write_deps_file.m b/compiler/write_deps_file.m
index 71077c7..4bed877 100644
--- a/compiler/write_deps_file.m
+++ b/compiler/write_deps_file.m
@@ -2237,55 +2237,45 @@ generate_dep_file_install_targets(Globals, DepStream, ModuleName, DepsMap,
 
 generate_dep_file_collective_targets(Globals, DepStream, ModuleName,
         MakeVarName, !IO) :-
-    module_name_to_file_name(Globals, ModuleName, ".check",
-        do_not_create_dirs, CheckTargetName, !IO),
-    module_name_to_file_name(Globals, ModuleName, ".ints",
-        do_not_create_dirs, IntsTargetName, !IO),
-    module_name_to_file_name(Globals, ModuleName, ".int3s",
-        do_not_create_dirs, Int3sTargetName, !IO),
-    module_name_to_file_name(Globals, ModuleName, ".opts",
-        do_not_create_dirs, OptsTargetName, !IO),
-    module_name_to_file_name(Globals, ModuleName, ".trans_opts",
-        do_not_create_dirs, TransOptsTargetName, !IO),
-    module_name_to_file_name(Globals, ModuleName, ".ss",
-        do_not_create_dirs, SsTargetName, !IO),
-    module_name_to_file_name(Globals, ModuleName, ".pic_ss",
-        do_not_create_dirs, PicSsTargetName, !IO),
-    module_name_to_file_name(Globals, ModuleName, ".ils",
-        do_not_create_dirs, ILsTargetName, !IO),
-    module_name_to_file_name(Globals, ModuleName, ".javas",
-        do_not_create_dirs, JavasTargetName, !IO),
-    module_name_to_file_name(Globals, ModuleName, ".classes",
-        do_not_create_dirs, ClassesTargetName, !IO),
-
     % We need to explicitly mention $(foo.pic_ss) somewhere in the Mmakefile,
     % otherwise it won't build properly with --target asm: GNU Make's pattern
     % rule algorithm will try to use the .m -> .c_date -> .c -> .pic_o rule
     % chain rather than the .m -> .pic_s_date -> .pic_s -> .pic_o chain.
     % So don't remove the pic_ss target here.
 
+    list.foldl(
+        generate_dep_file_collective_target(Globals, DepStream, ModuleName,
+            MakeVarName),
+        [
+            ".check" - ".errs",
+            ".ints" - ".dates",
+            ".int3s" - ".date3s",
+            ".opts" - ".optdates",
+            ".trans_opts" - ".trans_opt_dates",
+            ".ss" - ".ss",
+            ".pic_ss" - ".pic_ss",
+            ".ils" - ".ils",
+            ".javas" - ".javas",
+            ".classes" - ".classes",
+            ".all_ints" - ".dates",
+            ".all_int3s" - ".date3s",
+            ".all_opts" - ".optdates",
+            ".all_trans_opts" - ".trans_opt_dates",
+            ".all_ss" - ".ss",
+            ".all_pic_ss" - ".pic_ss"
+        ], !IO).
+
+:- pred generate_dep_file_collective_target(globals::in, io.output_stream::in,
+    module_name::in, string::in, pair(string, string)::in,
+    io::di, io::uo) is det.
+
+generate_dep_file_collective_target(Globals, DepStream, ModuleName,
+        MakeVarName, Extension - VarExtension, !IO) :-
+    module_name_to_file_name(Globals, ModuleName, Extension,
+        do_not_create_dirs, TargetName, !IO),
     io.write_strings(DepStream, [
-        ".PHONY : ", CheckTargetName, "\n",
-        CheckTargetName, " : $(", MakeVarName, ".errs)\n\n",
-        ".PHONY : ", IntsTargetName, "\n",
-        IntsTargetName, " : $(", MakeVarName, ".dates)\n\n",
-        ".PHONY : ", Int3sTargetName, "\n",
-        Int3sTargetName, " : $(", MakeVarName, ".date3s)\n\n",
-        ".PHONY : ", OptsTargetName, "\n",
-        OptsTargetName, " : $(", MakeVarName, ".optdates)\n\n",
-        ".PHONY : ", TransOptsTargetName, "\n",
-        TransOptsTargetName, " : $(", MakeVarName,
-            ".trans_opt_dates)\n\n",
-        ".PHONY : ", SsTargetName, "\n",
-        SsTargetName, " : $(", MakeVarName, ".ss)\n\n",
-        ".PHONY : ", PicSsTargetName, "\n",
-        PicSsTargetName, " : $(", MakeVarName, ".pic_ss)\n\n",
-        ".PHONY : ", ILsTargetName, "\n",
-        ILsTargetName, " : $(", MakeVarName, ".ils)\n\n",
-        ".PHONY : ", JavasTargetName, "\n",
-        JavasTargetName, " : $(", MakeVarName, ".javas)\n\n",
-        ".PHONY : ", ClassesTargetName, "\n",
-        ClassesTargetName, " : $(", MakeVarName, ".classes)\n\n"
+        ".PHONY : ", TargetName, "\n",
+        TargetName, " : $(", MakeVarName, VarExtension, ")\n\n"
     ], !IO).
 
 :- pred generate_dep_file_clean_targets(globals::in, io.output_stream::in,
diff --git a/doc/user_guide.texi b/doc/user_guide.texi
index 89ff3c3..56022e5 100644
--- a/doc/user_guide.texi
+++ b/doc/user_guide.texi
@@ -538,7 +538,7 @@ This step must be performed first.
 It is also required whenever you wish to change the level of
 inter-module optimization performed (@pxref{Overall optimization options}).
 
- at item @var{main-module}.ints
+ at item @var{main-module}.all_ints
 Ensure that the interface files for @var{main-module}
 and its imported modules are up-to-date.
 (If the underlying @samp{make} program does not handle transitive dependencies,
@@ -554,24 +554,8 @@ Error messages are placed in @file{.err} files.
 Compiles and links @var{main-module} using the Mercury compiler.
 Error messages are placed in @file{.err} files.
 
- at item @var{main-module}.javas
-Compiles @var{main-module} to Java source files (@file{*.java}).
-
- at item @var{main-module}.classes
-Compiles @var{main-module} to Java bytecode files (@file{*.class}).
-
- at item @var{main-module}.ils
-Compiles @var{main-module} to IL files (@file{*.il})
-for the .NET Common Language Runtime.
-
 @c XXX mention .dlls and .exe targets?
 
- at item @var{main-module}.erls
-Compiles @var{main-module} to Erlang source files (@file{*.erl}).
-
- at item @var{main-module}.beams
-Compiles @var{main-module} to Erlang bytecode (object) files (@file{*.beam}).
-
 @item lib at var{main-module}
 Builds a library whose top-level module is @var{main-module}.
 This will build a static object library, a shared object library

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