diff options
Diffstat (limited to 'lib/compiler')
-rw-r--r-- | lib/compiler/src/compile.erl | 39 | ||||
-rw-r--r-- | lib/compiler/test/compile_SUITE.erl | 35 |
2 files changed, 53 insertions, 21 deletions
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index b4aa8f04bf..8815cfb26f 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -237,7 +237,8 @@ format_error({module_name,Mod,Filename}) -> code=[], core_code=[], abstract_code=[], %Abstract code for debugger. - options=[] :: [option()], + options=[] :: [option()], %Options for compilation + mod_options=[] :: [option()], %Options for module_info errors=[], warnings=[]}). @@ -248,10 +249,11 @@ internal(Master, Input, Opts) -> internal({forms,Forms}, Opts) -> {_,Ps} = passes(forms, Opts), - internal_comp(Ps, "", "", #compile{code=Forms,options=Opts}); + internal_comp(Ps, "", "", #compile{code=Forms,options=Opts, + mod_options=Opts}); internal({file,File}, Opts) -> {Ext,Ps} = passes(file, Opts), - Compile = #compile{options=Opts}, + Compile = #compile{options=Opts,mod_options=Opts}, internal_comp(Ps, File, Ext, Compile). internal_comp(Passes, File, Suffix, St0) -> @@ -1230,12 +1232,13 @@ beam_unused_labels(#compile{code=Code0}=St) -> Code = beam_jump:module_labels(Code0), {ok,St#compile{code=Code}}. -beam_asm(#compile{ifile=File,code=Code0,abstract_code=Abst,options=Opts0}=St) -> +beam_asm(#compile{ifile=File,code=Code0, + abstract_code=Abst,mod_options=Opts0}=St) -> Source = filename:absname(File), Opts1 = lists:map(fun({debug_info_key,_}) -> {debug_info_key,'********'}; (Other) -> Other end, Opts0), - Opts2 = [O || O <- Opts1, is_informative_option(O)], + Opts2 = [O || O <- Opts1, effects_code_generation(O)], case beam_asm:module(Code0, Abst, Source, Opts2) of {ok,Code} -> {ok,St#compile{code=Code,abstract_code=[]}} end. @@ -1305,15 +1308,23 @@ embed_native_code(St, {Architecture,NativeCode}) -> {ok, BeamPlusNative} = beam_lib:build_module(Chunks), St#compile{code=BeamPlusNative}. -%% Returns true if the option is informative and therefore should be included -%% in the option list of the compiled module. - -is_informative_option(beam) -> false; -is_informative_option(report_warnings) -> false; -is_informative_option(report_errors) -> false; -is_informative_option(binary) -> false; -is_informative_option(verbose) -> false; -is_informative_option(_) -> true. +%% effects_code_generation(Option) -> true|false. +%% Determine whether the option could have any effect on the +%% generated code in the BEAM file (as opposed to how +%% errors will be reported). + +effects_code_generation(Option) -> + case Option of + beam -> false; + report_warnings -> false; + report_errors -> false; + return_errors-> false; + return_warnings-> false; + binary -> false; + verbose -> false; + {cwd,_} -> false; + _ -> true + end. save_binary(#compile{code=none}=St) -> {ok,St}; save_binary(#compile{module=Mod,ofile=Outfile, diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl index 8c6a623dfb..fedbd98f71 100644 --- a/lib/compiler/test/compile_SUITE.erl +++ b/lib/compiler/test/compile_SUITE.erl @@ -77,12 +77,22 @@ file_1(Config) when is_list(Config) -> ?line {Simple, Target} = files(Config, "file_1"), ?line {ok, Cwd} = file:get_cwd(), ?line ok = file:set_cwd(filename:dirname(Target)), - ?line {ok,simple} = compile:file(Simple), %Smoke test only. + + %% Native from BEAM without compilation info. ?line {ok,simple} = compile:file(Simple, [slim]), %Smoke test only. - ?line {ok,simple} = compile:file(Simple, [native,report]), %Smoke test. ?line {ok,simple} = compile:file(Target, [native,from_beam]), %Smoke test. - ?line {ok,simple} = compile:file(Simple, [debug_info]), + + %% Native from BEAM with compilation info. + ?line {ok,simple} = compile:file(Simple), %Smoke test only. + ?line {ok,simple} = compile:file(Target, [native,from_beam]), %Smoke test. + + ?line {ok,simple} = compile:file(Simple, [native,report]), %Smoke test. + + ?line compile_and_verify(Simple, Target, []), + ?line compile_and_verify(Simple, Target, [native]), + ?line compile_and_verify(Simple, Target, [debug_info]), ?line {ok,simple} = compile:file(Simple, [no_line_info]), %Coverage + ?line ok = file:set_cwd(Cwd), ?line true = exists(Target), ?line passed = run(Target, test, []), @@ -113,10 +123,9 @@ big_file(Config) when is_list(Config) -> ?line Big = filename:join(DataDir, "big.erl"), ?line Target = filename:join(PrivDir, "big.beam"), ?line ok = file:set_cwd(PrivDir), - ?line {ok,big} = compile:file(Big, []), - ?line {ok,big} = compile:file(Big, [r9,debug_info]), - ?line {ok,big} = compile:file(Big, [no_postopt]), - ?line true = exists(Target), + ?line compile_and_verify(Big, Target, []), + ?line compile_and_verify(Big, Target, [debug_info]), + ?line compile_and_verify(Big, Target, [no_postopt]), %% Cleanup. ?line ok = file:delete(Target), @@ -775,3 +784,15 @@ do_asm(Beam, Outdir) -> [M,Class,Error,erlang:get_stacktrace()]), error end. + +%%% +%%% Utilities. +%%% + +compile_and_verify(Name, Target, Opts) -> + Mod = list_to_atom(filename:basename(Name, ".erl")), + {ok,Mod} = compile:file(Name, Opts), + {ok,{Mod,[{compile_info,CInfo}]}} = + beam_lib:chunks(Target, [compile_info]), + {options,BeamOpts} = lists:keyfind(options, 1, CInfo), + Opts = BeamOpts. |