[m-rev.] trivial diff: switch on target_lang type

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Oct 5 14:15:42 AEST 2006


Estimated hours taken: 0.1
Branches: main

compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile.m:
compiler/ml_code_gen.m:
compiler/modules.m:
compiler/simplify.m:
 	Switch on the linked_target_type and target_lang types wherever
 	we can.

compiler/mlds_to_c.m:
 	As above and add a sanity check: we shouldn't output IL or Java
 	to C header files.

Julien.

Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.95
diff -u -r1.95 compile_target_code.m
--- compiler/compile_target_code.m	2 Oct 2006 09:06:48 -0000	1.95
+++ compiler/compile_target_code.m	5 Oct 2006 03:53:34 -0000
@@ -952,7 +952,8 @@

      globals.io_get_target(Target, !IO),
      io.output_stream(OutputStream, !IO),
-    ( Target = target_asm ->
+    ( 
+        Target = target_asm,
          % For --target asm, we generate everything into a single object file.
          (
              Modules = [FirstModule | _],
@@ -962,9 +963,14 @@
              unexpected(this_file, "link_module_list: no modules")
          )
      ;
+        ( Target = target_c
+        ; Target = target_java
+        ; Target = target_il
+        ),
          join_module_list(Modules, Obj, ObjectsList, !IO)
      ),
-    ( TargetType = executable ->
+    ( 
+        TargetType = executable,
          list.map(
              (pred(ModuleStr::in, ModuleName::out) is det :-
                  file_name_to_module_name(dir.basename_det(ModuleStr),
@@ -974,6 +980,7 @@
          make_init_obj_file(OutputStream, MustCompile, MainModuleName,
              ModuleNames, InitObjResult, !IO)
      ;
+        TargetType = shared_library,
          InitObjResult = yes("")
      ),
      (
@@ -1610,9 +1617,14 @@
          % Link/copy the executable into the user's directory.
          globals.io_set_option(use_subdirs, bool(no), !IO),
          globals.io_set_option(use_grade_subdirs, bool(no), !IO),
-        ( LinkTargetType = executable ->
+        ( 
+            LinkTargetType = executable,
              module_name_to_file_name(ModuleName, Ext, no, UserDirFileName, !IO)
          ;
+            ( LinkTargetType = static_library
+            ; LinkTargetType = shared_library
+            ; LinkTargetType = java_archive
+            ),
              module_name_to_lib_file_name("lib", ModuleName, Ext, no,
                  UserDirFileName, !IO)
          ),
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.275
diff -u -r1.275 handle_options.m
--- compiler/handle_options.m	2 Oct 2006 09:06:49 -0000	1.275
+++ compiler/handle_options.m	5 Oct 2006 03:50:08 -0000
@@ -476,7 +476,8 @@
          %         intermodule optimization pulls in a lot of code which isn't
          %         needed, so ensure that this dead code is removed.

-        ( Target = target_il ->
+        ( 
+            Target = target_il,
              globals.set_gc_method(gc_automatic, !Globals),
              globals.set_option(gc, string("automatic"), !Globals),
              globals.set_option(reclaim_heap_on_nondet_failure, bool(no),
@@ -512,7 +513,10 @@
                  true
              )
          ;
-            true
+            ( Target = target_c
+            ; Target = target_java
+            ; Target = target_asm
+            )
          ),

          % Set --put-nondet-env-on-heap if --verifiable-code is specified,
@@ -570,7 +574,8 @@
          %         intermodule optimization pulls in a lot of code which isn't
          %         needed, so ensure that this dead code is removed.

-        ( Target = target_java ->
+        ( 
+            Target = target_java,
              globals.set_gc_method(gc_automatic, !Globals),
              globals.set_option(gc, string("automatic"), !Globals),
              globals.set_option(reclaim_heap_on_nondet_failure, bool(no),
@@ -596,14 +601,21 @@
                  AutoIntermodOptimization = no
              )
          ;
-            true
+            ( Target = target_c
+            ; Target = target_il
+            ; Target = target_asm
+            )
          ),
          % Generating assembler via the gcc back-end requires
          % using high-level code.
-        ( Target = target_asm ->
+        ( 
+            Target = target_asm,
              globals.set_option(highlevel_code, bool(yes), !Globals)
          ;
-            true
+            ( Target = target_c
+            ; Target = target_il
+            ; Target = target_java
+            )
          ),

          % Generating high-level C or asm code requires putting each commit
@@ -1069,10 +1081,14 @@
                  % For the IL backend we turn off optimize_peep
                  % so that we don't optimize away references to the
                  % local variables of a procedure.
-                ( Target = target_il ->
+                ( 
+                    Target = target_il,
                      globals.set_option(optimize_peep, bool(no), !Globals)
                  ;
-                    true
+                    ( Target = target_c
+                    ; Target = target_java
+                    ; Target = target_asm
+                    )
                  )
              ;
                  TraceOptimized = yes
Index: compiler/make_hlds_passes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make_hlds_passes.m,v
retrieving revision 1.56
diff -u -r1.56 make_hlds_passes.m
--- compiler/make_hlds_passes.m	4 Oct 2006 06:36:56 -0000	1.56
+++ compiler/make_hlds_passes.m	5 Oct 2006 02:27:00 -0000
@@ -979,9 +979,13 @@
          % So we ignore these pragmas for the Java back-end.
          module_info_get_globals(!.ModuleInfo, Globals),
          globals.get_target(Globals, Target),
-        ( Target = target_java ->
-            true
+        ( 
+            Target = target_java
          ;
+            ( Target = target_c
+            ; Target = target_il
+            ; Target = target_asm
+            ),
              add_pragma_type_spec(Pragma, Context, !ModuleInfo, !QualInfo,
                  !Specs)
          )
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.407
diff -u -r1.407 mercury_compile.m
--- compiler/mercury_compile.m	2 Oct 2006 05:21:13 -0000	1.407
+++ compiler/mercury_compile.m	5 Oct 2006 02:26:19 -0000
@@ -428,13 +428,17 @@
                  file_name_to_module_name(FirstModule,
                      MainModuleName),
                  globals.get_target(Globals, Target),
-                ( Target = target_java ->
-                    % For Java, at the "link" step we just
-                    % generate a shell script; the actual
-                    % linking will be done at runtime by
+                ( 
+                    Target = target_java,
+                    % For Java, at the "link" step we just generate a shell
+                    % script; the actual linking will be done at runtime by
                      % the Java interpreter.
                      create_java_shell_script(MainModuleName, Succeeded, !IO)
                  ;
+                    ( Target = target_c
+                    ; Target = target_il
+                    ; Target = target_asm
+                    ),
                      compile_with_module_options(MainModuleName,
                          OptionVariables, OptionArgs,
                          link_module_list(ModulesToLink, FactTableObjFiles),
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.189
diff -u -r1.189 ml_code_gen.m
--- compiler/ml_code_gen.m	4 Oct 2006 07:14:47 -0000	1.189
+++ compiler/ml_code_gen.m	5 Oct 2006 03:42:51 -0000
@@ -2429,11 +2429,16 @@
          % for calling managed function pointers in managed C++. Instead we have
          % to call back into IL and make the continuation call in IL. This is
          % called an "indirect" success continuation call.
-
-        ( Target = target_il ->
+        %
+        ( 
+            Target = target_il,
              ml_gen_call_current_success_cont_indirectly(Context, CallCont,
                  !Info)
          ;
+            ( Target = target_c
+            ; Target = target_java
+            ; Target = target_asm
+            ),
              ml_gen_call_current_success_cont(Context, CallCont, !Info)
          )
      ;
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.201
diff -u -r1.201 mlds_to_c.m
--- compiler/mlds_to_c.m	4 Oct 2006 07:14:48 -0000	1.201
+++ compiler/mlds_to_c.m	5 Oct 2006 03:49:29 -0000
@@ -202,17 +202,23 @@

  mlds_output_src_imports(Indent, Imports, !IO) :-
      globals.io_get_target(Target, !IO),
-    ( Target = target_asm ->
+    ( 
+        Target = target_asm
          % For --target asm, we don't create the header files for modules that
          % don't contain C code, so we'd better not include them, since they
          % might not exist.

          % XXX This is a hack; it may lead to warnings or errors when compiling
          % the generated code, since the functions that we call (e.g. for
-        % `pragma export') may not have been declared.
-        true
+        % `pragma foreign_export') may not have been declared.
      ;
+        Target = target_c,
          list.foldl(mlds_output_src_import(Indent), Imports, !IO)
+    ;
+        ( Target = target_java
+        ; Target = target_il
+        ),
+        unexpected(this_file, "expected target asm or target c")
      ).

  :- pred mlds_output_src_import(indent::in, mlds_import::in,
@@ -361,7 +367,8 @@
      % can be #included by C++ programs.

      globals.io_get_target(Target, !IO),
-    ( Target = target_c ->
+    ( 
+        Target = target_c,
          mlds_indent(Indent, !IO),
          io.write_string("#ifdef __cplusplus\n", !IO),
          mlds_indent(Indent, !IO),
@@ -370,7 +377,10 @@
          io.write_string("#endif\n", !IO),
          io.nl(!IO)
      ;
-        true
+        ( Target = target_il
+        ; Target = target_java
+        ; Target = target_asm
+        )
      ),
      mlds_indent(Indent, !IO),
      io.write_string("#include ""mercury.h""\n", !IO).
@@ -465,7 +475,8 @@

  mlds_output_hdr_end(Indent, ModuleName, !IO) :-
      globals.io_get_target(Target, !IO),
-    ( Target = target_c ->
+    ( 
+        Target = target_c,
          % Terminate the `extern "C"' wrapper.
          mlds_indent(Indent, !IO),
          io.write_string("#ifdef __cplusplus\n", !IO),
@@ -475,7 +486,10 @@
          io.write_string("#endif\n", !IO),
          io.nl(!IO)
      ;
-        true
+        ( Target = target_il
+        ; Target = target_java
+        ; Target = target_asm
+        )
      ),
      mlds_indent(Indent, !IO),
      io.write_string("#endif /* MR_HEADER_GUARD_", !IO),
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.405
diff -u -r1.405 modules.m
--- compiler/modules.m	2 Oct 2006 05:21:19 -0000	1.405
+++ compiler/modules.m	5 Oct 2006 03:43:45 -0000
@@ -4537,9 +4537,14 @@
      io.write_string(DepStream, "\n", !IO),

      globals.io_get_target(Target, !IO),
-    ( Target = target_il ->
+    ( 
+        Target = target_il,
          ForeignModulesAndExts = foreign_modules(Modules, DepsMap)
      ;
+        ( Target = target_c
+        ; Target = target_java
+        ; Target = target_asm
+        ),
          ForeignModulesAndExts = []
      ),
      ForeignModules = assoc_list.keys(ForeignModulesAndExts),
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.191
diff -u -r1.191 simplify.m
--- compiler/simplify.m	2 Oct 2006 05:21:23 -0000	1.191
+++ compiler/simplify.m	5 Oct 2006 02:28:49 -0000
@@ -1404,9 +1404,14 @@
                      PrivateBuiltin = mercury_private_builtin_module,
                      EvalPredName = "trace_evaluate_runtime_condition",
                      some [!EvalAttributes] (
-                        ( Target = target_c ->
+                        ( 
+                            Target = target_c,
                              !:EvalAttributes = default_attributes(lang_c)
                          ;
+                            ( Target = target_il
+                            ; Target = target_java
+                            ; Target = target_asm
+                            ),
                              sorry(this_file, "NYI: runtime trace conditions "
                                  ++ "in languages other than C")
                          ),

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