-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdump_source.erl
30 lines (26 loc) · 975 Bytes
/
dump_source.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
%% @copyright Geoff Cant 2009
%% @author Geoff Cant <[email protected]>
%% @version {@vsn}, {@date} {@time}
%% @doc Reprints the source code of a module compiled with debug_info.
%% @end
f(GetAST).
GetAST = fun (Module) ->
{ok,{_,[{abstract_code,{_,AC}}]}} =
beam_lib:chunks(code:which(Module),[abstract_code]),
erl_syntax:form_list(AC)
end.
f(GetSrc).
GetSrc = fun (Module) ->
erl_prettypr:format(GetAST(Module))
end.
f(PrintSrc).
PrintSrc = fun (Module) ->
io:format("~s", [GetSrc(Module)])
end.
f(NPrintSrc).
NPrintSrc = fun (Module, Node) ->
File = rpc:call(Node, code,which,[Module]),
{ok,{_,[{abstract_code,{_,AC}}]}} =
rpc:call(Node, beam_lib,chunks, [File,[abstract_code]]),
io:put_chars(erl_prettypr:format(erl_syntax:form_list(AC)))
end.