[m-rev.] for review: support grade specific .init files with mmc --make

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Nov 30 14:33:02 AEDT 2006


The following diff adds support for grade specific .init files with
mmc --make.  I'm adding this now because it's necessary for the
debugging stuff in G12 to work properly.  Grade specific .init file
support in mmake will be a separate change.

Estimated hours taken: 4
Branches: main

When building with mmc --make use the grade specific versions of the
.init files.

Support grade specific .init files with --use-grade-subdirs.

compiler/compile_target_code.m:
 	Use the grade specific versions of the .init files for the Mercury
 	standard libraries.

 	If --use-grade-subdirs is enabled them symlink/copy .init files
 	into the user's directory.

compiler/options.m:
 	Delay handling the init file directories until after the grade
 	has been computed.

compiler/handle_options.m:
 	Append the grade to each init file directory, so that we get
 	the grade specific version of the .init files.

 	Unrelated changes: replace an if-then-else with a switch.
 			   minor formatting fixes.

compiler/modules.m:
 	.init files are now grade dependent.

scripts/c2init.in:
 	Use the grade specific version of the .init files for the
 	standard Mercury libraries.

compiler/make.program_target.m:
 	Remove some unnecessary module qualification.

Julien.

Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.99
diff -u -r1.99 compile_target_code.m
--- compiler/compile_target_code.m	24 Nov 2006 03:48:00 -0000	1.99
+++ compiler/compile_target_code.m	30 Nov 2006 02:58:37 -0000
@@ -924,7 +924,36 @@
          module_name_to_file_name(MainModuleName, ".init", yes, InitFileName,
              !IO),
          update_interface_return_succeeded(InitFileName, Succeeded1, !IO),
-        Succeeded = Succeeded0 `and` Succeeded1
+        Succeeded2 = Succeeded0 `and` Succeeded1,
+        (
+            Succeeded2 = yes,
+            % Symlink or copy the .init files to the user's directory
+            % if --use-grade-subdirs is enabled.
+            globals.io_lookup_bool_option(use_grade_subdirs,
+                UseGradeSubDirs, !IO),
+            (
+                UseGradeSubDirs = yes,
+                io.set_output_stream(ErrorStream, OutputStream, !IO),
+                globals.io_set_option(use_subdirs, bool(no), !IO),
+                globals.io_set_option(use_grade_subdirs, bool(no), !IO),
+                module_name_to_file_name(MainModuleName, ".init", no,
+                    UserDirFileName, !IO),
+                globals.io_set_option(use_subdirs, bool(yes), !IO),
+                globals.io_set_option(use_grade_subdirs, bool(yes), !IO),
+                % Remove the target of the symlink/copy in case it already
+                % exists.
+                io.remove_file(UserDirFileName, _, !IO),
+                make_symlink_or_copy_file(InitFileName, UserDirFileName,
+                    Succeeded, !IO),
+                io.set_output_stream(OutputStream, _, !IO)
+            ;
+                UseGradeSubDirs = no,
+                Succeeded = yes
+            )
+        ;
+            Succeeded2 = no,
+            Succeeded  = no
+        )
      ;
          InitFileRes = error(Error),
          io.progname_base("mercury_compile", ProgName, !IO),
@@ -1060,13 +1089,16 @@
          mercury_standard_library_directory, MaybeStdLibDir, !IO),
      (
          MaybeStdLibDir = yes(StdLibDir),
-        InitFileNamesList1 = [StdLibDir/"modules"/"mer_rt.init",
-            StdLibDir/"modules"/"mer_std.init" |
-            InitFileNamesList0],
-        TraceInitFileNamesList =
-            [StdLibDir/"modules"/"mer_browser.init",
-            StdLibDir/"modules"/"mer_mdbcomp.init" |
-            TraceInitFileNamesList0]
+        InitFileNamesList1 = [
+            StdLibDir / "modules" / Grade / "mer_rt.init",
+            StdLibDir / "modules" / Grade / "mer_std.init" |
+            InitFileNamesList0
+        ],
+        TraceInitFileNamesList = [
+            StdLibDir/"modules"/ Grade / "mer_browser.init",
+            StdLibDir/"modules"/ Grade / "mer_mdbcomp.init" |
+            TraceInitFileNamesList0
+        ]
      ;
          MaybeStdLibDir = no,
          InitFileNamesList1 = InitFileNamesList0,
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.283
diff -u -r1.283 handle_options.m
--- compiler/handle_options.m	28 Nov 2006 11:02:31 -0000	1.283
+++ compiler/handle_options.m	30 Nov 2006 03:22:32 -0000
@@ -15,7 +15,6 @@
  % It also contains code for handling the --grade option.
  %
  %-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%

  :- module libs.handle_options.
  :- interface.
@@ -1306,7 +1305,8 @@
          % (e.g. `enum(var(T))'' in library/sparse_bitset.m),
          % which the current RTTI system can't handle.
          %
-        ( GC_Method = gc_accurate ->
+        (
+            GC_Method = gc_accurate,
              globals.set_option(agc_stack_layout, bool(yes), !Globals),
              globals.set_option(body_typeinfo_liveness, bool(yes), !Globals),
              globals.set_option(allow_hijacks, bool(no), !Globals),
@@ -1325,7 +1325,12 @@
              globals.set_option(user_guided_type_specialization,
                  bool(no), !Globals)
          ;
-            true
+            ( GC_Method = gc_automatic
+            ; GC_Method = gc_none
+            ; GC_Method = gc_boehm
+            ; GC_Method = gc_boehm_debug
+            ; GC_Method = gc_mps
+            )
          ),

          % ml_gen_params_base and ml_declare_env_ptr_arg, in ml_code_util.m,
@@ -1481,8 +1486,8 @@
              bool(no), !Globals),

          % The results of trail usage analysis assume that trail usage
-        % optimization is being done, i.e that redundant trailing operations
-        % are really being eliminated.
+        % optimization is being done, i.e. that redundant trailing
+        % operations are really being eliminated.
          option_implies(analyse_trail_usage, optimize_trail_usage,
              bool(yes), !Globals),

@@ -1563,9 +1568,9 @@
          ),

          %
-        % Handle the `.opt', C header and library search directories
-        % for installed libraries.  These couldn't be handled by options.m
-        % because they are grade dependent.
+        % Handle the `.opt', C header, init file and library search
+        % directories for installed libraries.  These couldn't be handled by
+        % options.m because they are grade dependent.
          %
          globals.lookup_accumulating_option(!.Globals,
              mercury_library_directories, MercuryLibDirs),
@@ -1604,7 +1609,17 @@
              globals.lookup_accumulating_option(!.Globals,
                  intermod_directories, IntermodDirs0),
              globals.set_option(intermod_directories,
-                accumulating(ExtraIntermodDirs ++ IntermodDirs0), !Globals)
+                accumulating(ExtraIntermodDirs ++ IntermodDirs0), !Globals),
+ 
+            ExtraInitDirs = list.map(
+                (func(MercuryLibDir) =
+                    MercuryLibDir / "modules" / GradeString
+                ), MercuryLibDirs),
+ 
+            globals.lookup_accumulating_option(!.Globals,
+                init_file_directories, InitDirs1),
+            globals.set_option(init_file_directories,
+                accumulating(InitDirs1 ++ ExtraInitDirs), !Globals)
          ;
              MercuryLibDirs = []
          ),
@@ -2403,12 +2418,12 @@

  split_grade_string_2([], []).
  split_grade_string_2(Chars, Components) :-
-    Chars = [_|_],
+    Chars = [_ | _],
      list.takewhile(char_is_not('.'), Chars, ThisChars, RestChars0),
      string.from_char_list(ThisChars, ThisComponent),
-    Components = [ThisComponent|RestComponents],
+    Components = [ThisComponent | RestComponents],
      (
-        RestChars0 = [_|RestChars], % discard the `.'
+        RestChars0 = [_ | RestChars], % Discard the `.'.
          split_grade_string_2(RestChars, RestComponents)
      ;
          RestChars0 = [],
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.60
diff -u -r1.60 make.program_target.m
--- compiler/make.program_target.m	23 Nov 2006 06:10:48 -0000	1.60
+++ compiler/make.program_target.m	30 Nov 2006 02:22:23 -0000
@@ -327,8 +327,8 @@
          ; CompilationTarget = target_asm
          )
      ->
-        compile_target_code.make_init_obj_file(ErrorStream,
-            MainModuleName, AllModulesList, InitObjectResult, !IO),
+        make_init_obj_file(ErrorStream, MainModuleName, AllModulesList,
+            InitObjectResult, !IO),
          (
              InitObjectResult = yes(InitObject),
              % We may need to update the timestamp of the `_init.o' file.
@@ -380,8 +380,8 @@
              UseGradeSubdirs = yes,
              maybe_symlink_or_copy_linked_target_message(
                  MainModuleName - linked_target(FileType), !IO),
-            compile_target_code.post_link_make_symlink_or_copy(ErrorStream,
-                FileType, MainModuleName, Succeeded, !IO)
+            post_link_make_symlink_or_copy(ErrorStream, FileType,
+                MainModuleName, Succeeded, !IO)
          ;
              UseGradeSubdirs = no,
              maybe_warn_up_to_date_target(
@@ -430,16 +430,14 @@
              % Run the link in a separate process so it can be killed
              % if an interrupt is received.
              call_in_forked_process(
-                compile_target_code.link(ErrorStream,
-                    FileType, MainModuleName, AllObjects),
+                link(ErrorStream, FileType, MainModuleName, AllObjects),
                  Succeeded, !IO)
          ;
              CompilationTarget = target_asm,
              % Run the link in a separate process so it can
              % be killed if an interrupt is received.
              call_in_forked_process(
-                compile_target_code.link(ErrorStream,
-                    FileType, MainModuleName, AllObjects),
+                link(ErrorStream, FileType, MainModuleName, AllObjects),
                  Succeeded, !IO)
          ;
              CompilationTarget = target_il,
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.413
diff -u -r1.413 modules.m
--- compiler/modules.m	28 Nov 2006 11:02:31 -0000	1.413
+++ compiler/modules.m	30 Nov 2006 01:09:40 -0000
@@ -1210,6 +1210,7 @@
  file_is_arch_or_grade_dependent_2(".analysis").
  file_is_arch_or_grade_dependent_2(".analysis_date").
  file_is_arch_or_grade_dependent_2(".imdg").
+file_is_arch_or_grade_dependent_2(".init").
  file_is_arch_or_grade_dependent_2(".request").
  file_is_arch_or_grade_dependent_2(".mih").
  file_is_arch_or_grade_dependent_2(".c").
Index: compiler/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.538
diff -u -r1.538 options.m
--- compiler/options.m	28 Nov 2006 11:02:32 -0000	1.538
+++ compiler/options.m	30 Nov 2006 00:51:44 -0000
@@ -2501,25 +2501,21 @@
  %-----------------------------------------------------------------------------%

  option_table_add_mercury_library_directory(OptionTable0, Dir) =
-    % The link_library_directories for Mercury libraries are grade
-    % dependent, so they need to be handled in handle_options.m
-    % when we know the grade.
+    % The init_file_directories and link_library_directories for Mercury
+    % libraries are grade dependent, so they need to be handled in
+    % handle_options.m after we know the grade.
      list.foldl(append_to_accumulating_option, [
          search_directories          - dir.make_path_name(Dir, "ints"),
          c_include_directory         - dir.make_path_name(Dir, "inc"),
-        % XXX Trace goal fix.
-        init_file_directories       - dir.make_path_name(Dir, "modules"),
          mercury_library_directories - Dir
      ], OptionTable0).

  option_table_add_search_library_files_directory(OptionTable0, Dir) =
      % Grade dependent directories need to be handled in handle_options.m
-    % when we know the grade.
+    % after we know the grade.
      list.foldl(append_to_accumulating_option, [
          search_directories          - Dir,
          c_include_directory         - Dir,
-        % XXX Trace goal fix.
-        init_file_directories       - Dir,
          search_library_files_directories - Dir
      ], OptionTable0).
Index: scripts/c2init.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/c2init.in,v
retrieving revision 1.48
diff -u -r1.48 c2init.in
--- scripts/c2init.in	24 Nov 2006 03:48:20 -0000	1.48
+++ scripts/c2init.in	29 Nov 2006 03:17:30 -0000
@@ -79,11 +79,12 @@

  if test "$mercury_stdlib_dir" != ""
  then
-	MERCURY_MOD_LIB_MODS="$mercury_stdlib_dir/modules/$RT_LIB_NAME.init \
-		$mercury_stdlib_dir/modules/$STD_LIB_NAME.init"
+	MERCURY_MOD_LIB_MODS="\
+		$mercury_stdlib_dir/modules/$GRADE/$RT_LIB_NAME.init \
+		$mercury_stdlib_dir/modules/$GRADE/$STD_LIB_NAME.init"
  	MERCURY_TRACE_LIB_MODS="\
-		$mercury_stdlib_dir/modules/$BROWSER_LIB_NAME.init \
-		$mercury_stdlib_dir/modules/$MDBCOMP_LIB_NAME.init"
+		$mercury_stdlib_dir/modules/$GRADE/$BROWSER_LIB_NAME.init \
+		$mercury_stdlib_dir/modules/$GRADE/$MDBCOMP_LIB_NAME.init"
  fi
  MERCURY_TRACE_LIB_MODS="$MERCURY_TRACE_LIB_MODS $trace_init_files"


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