aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/compile.erl
diff options
context:
space:
mode:
authorJosé Valim <[email protected]>2017-09-03 00:11:25 +0200
committerJosé Valim <[email protected]>2017-09-14 11:18:39 +0200
commit9bac40fb969bc23f0aa4e90618835fbd95b4dabc (patch)
tree5881310a92f7c878d1bb9edfd3f2aa43f99acd30 /lib/compiler/src/compile.erl
parentfdf359ff4063cf065f5355b9d13a2e76b6c9cd75 (diff)
downloadotp-9bac40fb969bc23f0aa4e90618835fbd95b4dabc.tar.gz
otp-9bac40fb969bc23f0aa4e90618835fbd95b4dabc.tar.bz2
otp-9bac40fb969bc23f0aa4e90618835fbd95b4dabc.zip
Add compile_info option to compile
This allows compilers built on top of the compile module to attach external compilation metadata to the compile_info chunk. For example, Erlang uses this chunk to store the compiler version. Elixir and LFE may augment this by also adding their own compiler versions, which can be useful when debugging. The deterministic option does not affect the user supplied compile_info. It is therefore the responsibility of external compilers to guarantee any added information does not violate the determinsitic option, if such option is supported. Finally, this code moves the building of the compile_info options to the compile module instead of beam_asm, moving all of the option mangling code to a single place.
Diffstat (limited to 'lib/compiler/src/compile.erl')
-rw-r--r--lib/compiler/src/compile.erl22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl
index ec7e7aed14..1b359d1e59 100644
--- a/lib/compiler/src/compile.erl
+++ b/lib/compiler/src/compile.erl
@@ -1448,15 +1448,33 @@ save_core_code(Code, St) ->
beam_asm(Code0, #compile{ifile=File,extra_chunks=ExtraChunks,options=CompilerOpts}=St) ->
case debug_info(St) of
{ok,DebugInfo,Opts0} ->
- Source = paranoid_absname(File),
Opts1 = [O || O <- Opts0, effects_code_generation(O)],
Chunks = [{<<"Dbgi">>, DebugInfo} | ExtraChunks],
- {ok,Code} = beam_asm:module(Code0, Chunks, Source, Opts1, CompilerOpts),
+ CompileInfo = compile_info(File, Opts1),
+ {ok,Code} = beam_asm:module(Code0, Chunks, CompileInfo, CompilerOpts),
{ok,Code,St#compile{abstract_code=[]}};
{error,Es} ->
{error,St#compile{errors=St#compile.errors ++ [{File,Es}]}}
end.
+compile_info(File, Opts) ->
+ IsSlim = member(slim, Opts),
+ IsDeterministic = member(deterministic, Opts),
+ Info0 = proplists:get_value(compile_info, Opts, []),
+ Info1 =
+ case paranoid_absname(File) of
+ [_|_] = Source when not IsSlim, not IsDeterministic ->
+ [{source,Source} | Info0];
+ _ ->
+ Info0
+ end,
+ Info2 =
+ case IsDeterministic of
+ false -> [{options,proplists:delete(compile_info, Opts)} | Info1];
+ true -> Info1
+ end,
+ Info2.
+
paranoid_absname(""=File) ->
File;
paranoid_absname(File) ->