aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2010-01-24 16:51:54 +0100
committerBjörn Gustavsson <[email protected]>2010-01-30 16:34:53 +0100
commitfe14832ebff7b4ef1ec9ded348c77e8779098c36 (patch)
tree245f1836386461b443b17f7bafac817eb4b570cd /lib/compiler/src
parentd91db9e12b15a821592aa95de39c47e5ad2923ab (diff)
downloadotp-fe14832ebff7b4ef1ec9ded348c77e8779098c36.tar.gz
otp-fe14832ebff7b4ef1ec9ded348c77e8779098c36.tar.bz2
otp-fe14832ebff7b4ef1ec9ded348c77e8779098c36.zip
Teach the compiler the no_native option
Implement the 'no_native' option to disable native-code compilation. If given in a module like this: -compile(no_native). it will override a 'native' option given on the command line.
Diffstat (limited to 'lib/compiler/src')
-rw-r--r--lib/compiler/src/compile.erl20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl
index 58e147d508..f0f962f3ef 100644
--- a/lib/compiler/src/compile.erl
+++ b/lib/compiler/src/compile.erl
@@ -717,7 +717,7 @@ read_beam_file(St) ->
case file:read_file(St#compile.ifile) of
{ok,Beam} ->
Infile = St#compile.ifile,
- case is_too_old(Infile) of
+ case no_native_compilation(Infile, St) of
true ->
{ok,St#compile{module=none,code=none}};
false ->
@@ -730,12 +730,15 @@ read_beam_file(St) ->
{error,St#compile{errors=St#compile.errors ++ Es}}
end.
-is_too_old(BeamFile) ->
+no_native_compilation(BeamFile, #compile{options=Opts0}) ->
case beam_lib:chunks(BeamFile, ["CInf"]) of
{ok,{_,[{"CInf",Term0}]}} ->
Term = binary_to_term(Term0),
- Opts = proplists:get_value(options, Term, []),
- lists:member(no_new_funs, Opts);
+
+ %% Compiler options in the beam file will override
+ %% options passed to the compiler.
+ Opts = proplists:get_value(options, Term, []) ++ Opts0,
+ member(no_new_funs, Opts) orelse not is_native_enabled(Opts);
_ -> false
end.
@@ -1046,7 +1049,14 @@ beam_asm(#compile{ifile=File,code=Code0,abstract_code=Abst,options=Opts0}=St) ->
test_native(#compile{options=Opts}) ->
%% This test is done late, in case some other option has turned off native.
- member(native, Opts).
+ %% 'native' given on the command line can be overridden by
+ %% 'no_native' in the module itself.
+ is_native_enabled(Opts).
+
+is_native_enabled([native|_]) -> true;
+is_native_enabled([no_native|_]) -> false;
+is_native_enabled([H|T]) -> is_native_enabled(T);
+is_native_enabled([]) -> false.
native_compile(#compile{code=none}=St) -> {ok,St};
native_compile(St) ->