Skip to content

Instantly share code, notes, and snippets.

@sile
Created June 3, 2013 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sile/5702343 to your computer and use it in GitHub Desktop.
Save sile/5702343 to your computer and use it in GitHub Desktop.
beamからのソースコードを取得する方法のメモ
%% http://erlang.org/pipermail/erlang-questions/2006-January/018812.html
-module(abst_to_src).
-export([transform/2]).
transform(BeamFName, ErlFName) ->
case beam_lib:chunks(BeamFName, [abstract_code]) of
{ok, {_, [{abstract_code, {raw_abstract_v1,Forms}}]}} ->
Src =
erl_prettypr:format(erl_syntax:form_list(tl(Forms))),
{ok, Fd} = file:open(ErlFName, [write]),
io:fwrite(Fd, "~s~n", [Src]),
file:close(Fd);
Error ->
Error
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment