[m-rev.] for review: java backend abort on private_builtin.m

Peter Wang novalazy at gmail.com
Thu Apr 23 12:14:41 AEST 2009


Branches: main

Fix an abort when compiling private_builtin.m with the Java backend.
`--optimize-constructor-last-call' is incompatible with Java but the
declarations for the builtins that it uses are in private_builtin.m, so
predicates get added with bodies which aren't handled by the Java backend.
Since the predicates won't be called anyway, it's safe to replace the bodies
with nothing.

compiler/builtin_ops.m:
        Make `translate_builtin' return a no-op for `store_at_ref' and
        `store_at_ref_impure' if the target language is Java or Erlang.

compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/erl_call_gen.m:
compiler/hlds_pred.m:
compiler/ml_call_gen.m:
        Conform to the change above.

diff --git a/compiler/builtin_ops.m b/compiler/builtin_ops.m
index 4080468..35f9d01 100644
--- a/compiler/builtin_ops.m
+++ b/compiler/builtin_ops.m
@@ -21,6 +21,8 @@

 :- import_module hlds.
 :- import_module hlds.hlds_pred.
+:- import_module libs.
+:- import_module libs.globals.
 :- import_module mdbcomp.
 :- import_module mdbcomp.prim_data.

@@ -115,7 +117,8 @@
     % (bytecode_gen.m depends on these guarantees.)
     %
 :- pred translate_builtin(module_name::in, string::in, proc_id::in,
-    list(T)::in, simple_code(T)::out(simple_code)) is semidet.
+    list(T)::in, compilation_target::in, simple_code(T)::out(simple_code))
+    is semidet.

 :- type simple_code(T)
     --->    assign(T, simple_expr(T))
@@ -164,12 +167,35 @@

 %-----------------------------------------------------------------------------%

-translate_builtin(FullyQualifiedModule, PredName, ProcId, Args, Code) :-
+translate_builtin(FullyQualifiedModule, PredName, ProcId, Args,
+        CompilationTarget, Code) :-
     proc_id_to_int(ProcId, ProcInt),
     % -- not yet:
     % FullyQualifiedModule = qualified(unqualified("std"), ModuleName),
     FullyQualifiedModule = unqualified(ModuleName),
-    builtin_translation(ModuleName, PredName, ProcInt, Args, Code).
+    (
+        target_builtin_translation(ModuleName, PredName, ProcInt, Args,
+            CompilationTarget, TargetSpecificCode)
+    ->
+        Code = TargetSpecificCode
+    ;
+        builtin_translation(ModuleName, PredName, ProcInt, Args, Code)
+    ).
+
+:- pred target_builtin_translation(string::in, string::in, int::in,
+    list(T)::in, compilation_target::in, simple_code(T)::out(simple_code))
+    is semidet.
+
+target_builtin_translation("private_builtin", PredName, 0, [_X, _Y], Target,
+        Code) :-
+    ( Target = target_java
+    ; Target = target_erlang
+    ),
+    ( PredName = "store_at_ref"
+    ; PredName = "store_at_ref_impure"
+    ),
+    % Can't do it.
+    Code = noop([]).

 :- pred builtin_translation(string::in, string::in, int::in, list(T)::in,
     simple_code(T)::out(simple_code)) is semidet.
diff --git a/compiler/bytecode_gen.m b/compiler/bytecode_gen.m
index f5d6714..db35237 100644
--- a/compiler/bytecode_gen.m
+++ b/compiler/bytecode_gen.m
@@ -59,6 +59,7 @@
 :- import_module hlds.passes_aux.
 :- import_module libs.
 :- import_module libs.compiler_util.
+:- import_module libs.globals.
 :- import_module ll_backend.  	% bytecode_gen uses ll_backend__call_gen.m
 :- import_module ll_backend.call_gen.  % XXX for arg passing convention
 :- import_module mdbcomp.
@@ -414,9 +415,11 @@ gen_builtin(PredId, ProcId, Args, ByteInfo, Code) :-
     get_module_info(ByteInfo, ModuleInfo),
     ModuleName = predicate_module(ModuleInfo, PredId),
     PredName = predicate_name(ModuleInfo, PredId),
+    module_info_get_globals(ModuleInfo, Globals),
+    globals.get_target(Globals, CompilationTarget),
     (
-        builtin_ops.translate_builtin(ModuleName, PredName, ProcId,
-            Args, SimpleCode)
+        builtin_ops.translate_builtin(ModuleName, PredName, ProcId, Args,
+            CompilationTarget, SimpleCode)
     ->
         (
             SimpleCode = test(Test),
diff --git a/compiler/call_gen.m b/compiler/call_gen.m
index 9974715..1268d3c 100644
--- a/compiler/call_gen.m
+++ b/compiler/call_gen.m
@@ -69,6 +69,7 @@
 :- import_module hlds.hlds_module.
 :- import_module hlds.instmap.
 :- import_module libs.compiler_util.
+:- import_module libs.globals.
 :- import_module libs.options.
 :- import_module ll_backend.code_util.
 :- import_module ll_backend.continuation_info.
@@ -599,9 +600,11 @@ generate_builtin(CodeModel, PredId, ProcId, Args,
Code, !CI) :-
     get_module_info(!.CI, ModuleInfo),
     ModuleName = predicate_module(ModuleInfo, PredId),
     PredName = predicate_name(ModuleInfo, PredId),
+    module_info_get_globals(ModuleInfo, Globals),
+    globals.get_target(Globals, CompilationTarget),
     (
-        builtin_ops.translate_builtin(ModuleName, PredName,
-            ProcId, Args, SimpleCode0)
+        builtin_ops.translate_builtin(ModuleName, PredName, ProcId, Args,
+            CompilationTarget, SimpleCode0)
     ->
         SimpleCode = SimpleCode0
     ;
diff --git a/compiler/erl_call_gen.m b/compiler/erl_call_gen.m
index 03ff0aa..bdefc71 100644
--- a/compiler/erl_call_gen.m
+++ b/compiler/erl_call_gen.m
@@ -107,6 +107,7 @@
 :- import_module check_hlds.type_util.
 :- import_module hlds.hlds_module.
 :- import_module libs.compiler_util.
+:- import_module libs.globals.

 :- import_module int.
 :- import_module map.
@@ -406,8 +407,8 @@ erl_gen_builtin(PredId, ProcId, ArgVars,
CodeModel, _Context,
     ModuleName = predicate_module(ModuleInfo, PredId),
     PredName = predicate_name(ModuleInfo, PredId),
     (
-        builtin_ops.translate_builtin(ModuleName, PredName,
-            ProcId, ArgVars, SimpleCode0)
+        builtin_ops.translate_builtin(ModuleName, PredName, ProcId, ArgVars,
+            target_erlang, SimpleCode0)
     ->
         SimpleCode = SimpleCode0
     ;
diff --git a/compiler/hlds_pred.m b/compiler/hlds_pred.m
index 0cd1164..bed481a 100644
--- a/compiler/hlds_pred.m
+++ b/compiler/hlds_pred.m
@@ -3108,7 +3108,10 @@ is_inline_builtin(ModuleName, PredName, ProcId, Arity) :-
     Arity =< 3,
     prog_varset_init(VarSet),
     varset.new_vars(VarSet, Arity, Args, _),
-    builtin_ops.translate_builtin(ModuleName, PredName, ProcId, Args, _).
+    % Any target will do.
+    AnyTarget = target_c,
+    builtin_ops.translate_builtin(ModuleName, PredName, ProcId, Args,
+        AnyTarget, _).

 :- pred prog_varset_init(prog_varset::out) is det.

diff --git a/compiler/ml_call_gen.m b/compiler/ml_call_gen.m
index f7d8025..3ebfd9d 100644
--- a/compiler/ml_call_gen.m
+++ b/compiler/ml_call_gen.m
@@ -907,9 +907,11 @@ ml_gen_builtin(PredId, ProcId, ArgVars,
CodeModel, Context, Decls, Statements,
     ml_gen_info_get_module_info(!.Info, ModuleInfo),
     ModuleName = predicate_module(ModuleInfo, PredId),
     PredName = predicate_name(ModuleInfo, PredId),
+    ml_gen_info_get_globals(!.Info, Globals),
+    globals.get_target(Globals, CompilationTarget),
     (
-        builtin_ops.translate_builtin(ModuleName, PredName,
-            ProcId, ArgLvals, SimpleCode0)
+        builtin_ops.translate_builtin(ModuleName, PredName, ProcId, ArgLvals,
+            CompilationTarget, SimpleCode0)
     ->
         SimpleCode = SimpleCode0
     ;
--------------------------------------------------------------------------
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