[m-rev.] for post-commit review: new options for querying the compiler

Julien Fischer jfischer at opturion.com
Thu Nov 13 11:12:42 AEDT 2014


Branches: master

Add two new options for querying the compiler.

Add two new options for querying the compiler.  The first new option,
--output-target-arch, prints the target architecture.  This is useful in
situations where you are working directly with the contents of the Mercury
subdirectory and --use-grade-subdirs is enabled.  (The directory names
generated by --use-grade-subdirs include the target architecture.) The second
new option, --output-class-dir, deals with a more specific instance of the
above.  It prints out the name of the directory in which the Mercury compiler
places generated Java class files.

Replace the use of 'fullarch' by 'target_arch' throughout the compiler.
(We still currently support '--fullarch' as a synonym for '--target-arch'
but that too will eventually be dropped.)

compiler/options.m:
 	Add the new options.

compiler/mercury_compile.m:
 	Implement the new options.

 	s/fullarch/target_arch/

 	Add an XXX comment about an inaccurate error message.

compiler/handle_options.m:
compiler/compile_target_code.m:
compiler/file_names.m:
compiler/make.program_target.m:
 	Conform to the above changes.

doc/user_guide.texi:
 	Document the new options.

Julien.

diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index 6b4b0b3..cd6f956 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -574,11 +574,11 @@ gather_c_compiler_flags(Globals, PIC, AllCFlags) :-
      % See the hard_coded/ppc_bug test case for an example
      % program which fails with this optimization.

-    globals.lookup_string_option(Globals, fullarch, FullArch),
+    globals.lookup_string_option(Globals, target_arch, TargetArch),
      (
          globals.lookup_bool_option(Globals, highlevel_code, no),
          globals.lookup_bool_option(Globals, gcc_global_registers, yes),
-        string.prefix(FullArch, "powerpc-apple-darwin")
+        string.prefix(TargetArch, "powerpc-apple-darwin")
      ->
          AppleGCCRegWorkaroundOpt = "-fno-loop-optimize "
      ;
@@ -590,7 +590,7 @@ gather_c_compiler_flags(Globals, PIC, AllCFlags) :-
      % (Changes here need to be reflected in scripts/mgnuc.in.)
      (
          globals.lookup_bool_option(Globals, exec_trace, yes),
-        arch_is_apple_darwin(FullArch)
+        arch_is_apple_darwin(TargetArch)
      ->
          OverrideOpts = "-O0"
      ;
@@ -1088,14 +1088,14 @@ compile_java_files(ErrorStream, JavaFiles, Globals, Succeeded, !IO) :-

      globals.lookup_bool_option(Globals, use_subdirs, UseSubdirs),
      globals.lookup_bool_option(Globals, use_grade_subdirs, UseGradeSubdirs),
-    globals.lookup_string_option(Globals, fullarch, FullArch),
+    globals.lookup_string_option(Globals, target_arch, TargetArch),
      (
          UseSubdirs = yes,
          (
              UseGradeSubdirs = yes,
              grade_directory_component(Globals, Grade),
-            SourceDirName = "Mercury"/Grade/FullArch/"Mercury"/"javas",
-            DestDirName = "Mercury"/Grade/FullArch/"Mercury"/"classs"
+            SourceDirName = "Mercury"/Grade/TargetArch/"Mercury"/"javas",
+            DestDirName = "Mercury"/Grade/TargetArch/"Mercury"/"classs"
          ;
              UseGradeSubdirs = no,
              SourceDirName = "Mercury"/"javas",
@@ -1180,13 +1180,13 @@ compile_erlang_file(ErrorStream, ErlangFile, Globals, Succeeded, !IO) :-

      globals.lookup_bool_option(Globals, use_subdirs, UseSubdirs),
      globals.lookup_bool_option(Globals, use_grade_subdirs, UseGradeSubdirs),
-    globals.lookup_string_option(Globals, fullarch, FullArch),
+    globals.lookup_string_option(Globals, target_arch, TargetArch),
      (
          UseSubdirs = yes,
          (
              UseGradeSubdirs = yes,
              grade_directory_component(Globals, Grade),
-            DirName = "Mercury"/Grade/FullArch/"Mercury"/"beams"
+            DirName = "Mercury"/Grade/TargetArch/"Mercury"/"beams"
          ;
              UseGradeSubdirs = no,
              DirName = "Mercury"/"beams"
diff --git a/compiler/file_names.m b/compiler/file_names.m
index 8d5a188..c24563e 100644
--- a/compiler/file_names.m
+++ b/compiler/file_names.m
@@ -475,14 +475,14 @@ make_file_name(Globals, SubDirNames, Search, MkDir, BaseName, Ext, FileName,
          )
      ->
          grade_directory_component(Globals, Grade),
-        globals.lookup_string_option(Globals, fullarch, FullArch),
+        globals.lookup_string_option(Globals, target_arch, TargetArch),

          % The extra "Mercury" is needed so we can use `--intermod-directory
-        % Mercury/<grade>/<fullarch>' and `--c-include
-        % Mercury/<grade>/<fullarch>' to find the local `.opt' and `.mih'
+        % Mercury/<grade>/<target_arch>' and `--c-include
+        % Mercury/<grade>/<target_arch>' to find the local `.opt' and `.mih'
          % files without messing up the search for the files for installed
          % libraries.
-        DirComponents = ["Mercury", Grade, FullArch, "Mercury" | SubDirNames]
+        DirComponents = ["Mercury", Grade, TargetArch, "Mercury" | SubDirNames]
      ;
          UseSubdirs = yes
      ->
@@ -599,8 +599,8 @@ get_class_dir_name(Globals, ClassDirName) :-
          UseGradeSubdirs = yes
      ->
          grade_directory_component(Globals, Grade),
-        globals.lookup_string_option(Globals, fullarch, FullArch),
-        ClassDirName = "Mercury" / Grade / FullArch / "Mercury" / "classs"
+        globals.lookup_string_option(Globals, target_arch, TargetArch),
+        ClassDirName = "Mercury" / Grade / TargetArch / "Mercury" / "classs"
      ;
          UseSubdirs = yes
      ->
diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index 74d776a..3dd2c81 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -2017,7 +2017,7 @@ convert_options_to_globals(OptionTable0, Target, GC_Method, TagsMethod0,
      option_implies(generate_source_file_mapping, warn_wrong_module_name,
          bool(no), !Globals),

-    globals.lookup_string_option(!.Globals, fullarch, FullArch),
+    globals.lookup_string_option(!.Globals, target_arch, TargetArch),

      % Add the standard library directory.
      globals.lookup_maybe_string_option(!.Globals,
@@ -2154,18 +2154,18 @@ convert_options_to_globals(OptionTable0, Target, GC_Method, TagsMethod0,
          search_library_files_directories, SearchLibFilesDirs),
      globals.lookup_accumulating_option(!.Globals,
          intermod_directories, IntermodDirs2),
-    ToGradeSubdir = (func(Dir) = Dir/"Mercury"/GradeString/FullArch),
+    ToGradeSubdir = (func(Dir) = Dir/"Mercury"/GradeString/TargetArch),
      (
          UseGradeSubdirs = yes,
          % With `--use-grade-subdirs', `.opt', `.trans_opt' and
          % `.mih' files are placed in a directory named
-        % `Mercury/<grade>/<fullarch>/Mercury/<ext>s'.
+        % `Mercury/<grade>/<target_arch>/Mercury/<ext>s'.
          % When searching for a `.opt' file, module_name_to_file_name
          % produces `Mercury/<ext>/<module>.ext' so that searches
          % for installed files work, so we need to add
-        % `--intermod-directory Mercury/<grade>/<fullarch>'
+        % `--intermod-directory Mercury/<grade>/<target_arch>'
          % to find the `.opt' files in the current directory.
-        GradeSubdir = "Mercury"/GradeString/FullArch,
+        GradeSubdir = "Mercury"/GradeString/TargetArch,

          % Directories listed with --search-library-files-directories need
          % to be treated in the same way as the current directory.
@@ -2187,8 +2187,8 @@ convert_options_to_globals(OptionTable0, Target, GC_Method, TagsMethod0,
      (
          UseGradeSubdirs = yes,
          % With --use-grade-subdirs we need to search in
-        % `Mercury/<grade>/<fullarch>/Mercury/lib' for libraries and
-        % `Mercury/<grade>/<fullarch>/Mercury/inits' for init files,
+        % `Mercury/<grade>/<target_arch>/Mercury/lib' for libraries and
+        % `Mercury/<grade>/<target_arch>/Mercury/inits' for init files,
          % for each directory listed with --search-library-files-directory.
          ToGradeLibDir = (func(Dir) = ToGradeSubdir(Dir)/"Mercury"/"lib"),
          SearchGradeLibDirs = list.map(ToGradeLibDir, SearchLibFilesDirs),
diff --git a/compiler/make.program_target.m b/compiler/make.program_target.m
index d0522f7..a751b69 100644
--- a/compiler/make.program_target.m
+++ b/compiler/make.program_target.m
@@ -1015,11 +1015,11 @@ create_analysis_cache_dir(Globals, Succeeded, CacheDir, !IO) :-

  choose_cache_dir_name(Globals, DirName, !IO) :-
      globals.lookup_bool_option(Globals, use_grade_subdirs, UseGradeSubdirs),
-    globals.lookup_string_option(Globals, fullarch, FullArch),
+    globals.lookup_string_option(Globals, target_arch, TargetArch),
      (
          UseGradeSubdirs = yes,
          grade_directory_component(Globals, Grade),
-        DirComponents = ["Mercury", Grade, FullArch, "Mercury",
+        DirComponents = ["Mercury", Grade, TargetArch, "Mercury",
              "analysis_cache"]
      ;
          UseGradeSubdirs = no,
diff --git a/compiler/mercury_compile.m b/compiler/mercury_compile.m
index aa4a134..285fdb1 100644
--- a/compiler/mercury_compile.m
+++ b/compiler/mercury_compile.m
@@ -380,6 +380,10 @@ main_after_setup(DetectedGradeFlags, OptionVariables, OptionArgs, Args,
          OutputGradeDefines),
      globals.lookup_bool_option(Globals, output_c_include_directory_flags,
          OutputCInclDirFlags),
+    globals.lookup_bool_option(Globals, output_target_arch,
+        OutputTargetArch),
+    globals.lookup_bool_option(Globals, output_class_dir,
+        OutputClassDir),
      globals.lookup_bool_option(Globals, make, Make),
      globals.lookup_maybe_string_option(Globals,
          generate_standalone_interface, GenerateStandaloneInt),
@@ -451,6 +455,14 @@ main_after_setup(DetectedGradeFlags, OptionVariables, OptionArgs, Args,
      ; OutputCInclDirFlags = yes ->
          io.stdout_stream(StdOut, !IO),
          output_c_include_directory_flags(Globals, StdOut, !IO)
+    ; OutputTargetArch = yes ->
+        io.stdout_stream(StdOut, !IO),
+        globals.lookup_string_option(Globals, target_arch, TargetArch),
+        io.write_string(StdOut, TargetArch ++ "\n", !IO)
+    ; OutputClassDir = yes ->
+        io.stdout_stream(StdOut, !IO),
+        get_class_dir_name(Globals, ClassName),
+        io.write_string(StdOut, ClassName ++ "\n", !IO)
      ; GenerateMapping = yes ->
          source_file_map.write_source_file_map(Globals, Args, !IO)
      ; GenerateStandaloneInt = yes(StandaloneIntBasename) ->
@@ -461,6 +473,9 @@ main_after_setup(DetectedGradeFlags, OptionVariables, OptionArgs, Args,
              ; Target = target_java
              ; Target = target_erlang
              ),
+            % XXX this message is nonsense.  These targets do
+            % not require standalone interfaces since they natively
+            % provide an equivalent mechanism.
              NYIMsg = [
                  words("Sorry,"),
                  quote("--generate-standalone-interface"),
diff --git a/compiler/options.m b/compiler/options.m
index 0e53b6e..cf49191 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -212,6 +212,8 @@
      ;       output_library_link_flags
      ;       output_grade_defines
      ;       output_c_include_directory_flags
+    ;       output_target_arch
+    ;       output_class_dir

      % Auxiliary output options
      ;       smart_recompilation
@@ -1010,7 +1012,7 @@
      ;       typecheck_ambiguity_error_limit
      ;       help
      ;       version
-    ;       fullarch
+    ;       target_arch
      ;       cross_compiling
      ;       local_module_id
      ;       analysis_file_cache_dir
@@ -1213,7 +1215,9 @@ option_defaults_2(output_option, [
      output_cflags                       -   bool(no),
      output_library_link_flags           -   bool(no),
      output_grade_defines                -   bool(no),
-    output_c_include_directory_flags    -   bool(no)
+    output_c_include_directory_flags    -   bool(no),
+    output_target_arch                  -   bool(no),
+    output_class_dir                    -   bool(no)
  ]).
  option_defaults_2(aux_output_option, [
      % Auxiliary Output Options
@@ -1922,7 +1926,7 @@ option_defaults_2(miscellaneous_option, [
      typecheck_ambiguity_error_limit     -   int(3000),
      help                                -   bool(no),
      version                             -   bool(no),
-    fullarch                            -   string(""),
+    target_arch                            -   string(""),
      cross_compiling                     -   bool(no),
      local_module_id                     -   accumulating([]),
      analysis_file_cache_dir             -   string(""),
@@ -2121,6 +2125,9 @@ long_option("output-c-include-directory-flags",
      output_c_include_directory_flags).
  long_option("output-c-include-dir-flags",
      output_c_include_directory_flags).
+long_option("output-target-arch",       output_target_arch).
+long_option("output-class-directory",   output_class_dir).
+long_option("output-class-dir",         output_class_dir).

  % aux output options
  long_option("smart-recompilation",      smart_recompilation).
@@ -2901,8 +2908,8 @@ long_option("typecheck-ambiguity-error-limit",
  long_option("help",                 help).
  long_option("version",              version).
  long_option("filenames-from-stdin", filenames_from_stdin).
-long_option("fullarch",             fullarch).
-long_option("target-arch",          fullarch).
+long_option("fullarch",             target_arch).
+long_option("target-arch",          target_arch).
  long_option("cross-compiling",      cross_compiling).
  long_option("local-module-id",      local_module_id).
  long_option("analysis-file-cache-dir",  analysis_file_cache_dir).
@@ -3868,7 +3875,12 @@ options_help_output -->
          "\tPrint the flags that are passed to the C compiler to specify",
          "\twhich directories to search for C header files.",
          "\tThis includes the C header files from the standard library.",
-        "\tThe flags are printed to the standard output."
+        "\tThe flags are printed to the standard output.",
+        "--output-target-arch",
+        "\tPrint the target architecture to the standard output.",
+        "--output-class-dir, --output-class-directory",
+        "\tPrint the name of the directory in which generated Java",
+        "\tclass files will be placed to the standard output."
      ]).

  :- pred options_help_aux_output(io::di, io::uo) is det.
@@ -5919,8 +5931,9 @@ options_help_misc -->
          "--version",
          "\tDisplay the compiler version.",

-        % The `--fullarch' option is reserved for
-        % use by the `Mercury.config' file.
+        % The `--target-arch' options is reserved for use by the
+        % `Mercury.config' file.  The `--fullarch' option is a deprecated
+        % synonym for this.

          "--cross-compiling",
          "\tDo not assume that the code being generated is for the",
diff --git a/doc/user_guide.texi b/doc/user_guide.texi
index 584b846..377dc5b 100644
--- a/doc/user_guide.texi
+++ b/doc/user_guide.texi
@@ -7099,6 +7099,19 @@ to search for C header files.
  This includes the C header files from the standard library.
  The flags are printed to the standard output.

+ at sp 1
+ at item --output-target-arch
+ at findex --output-target-arch
+Print the target architecture to the standard output.
+
+ at sp 1
+ at item --output-class-dir
+ at item --output-class-directory
+ at findex --output-class-dir
+ at findex --output-class-directory
+Print the name of the direcoty in which generated Java class files
+will be placed to the standard output.
+
  @end table

  @node Auxiliary output options



More information about the reviews mailing list