LL
"path/to/module.ex"
|> File.read!()
|> Code.string_to_quoted!()
|> Macro.prewalk(& Macro.expand(&1, __ENV__))
|> Macro.to_string()
|> Code.format_string!()
Size: a a a
LL
"path/to/module.ex"
|> File.read!()
|> Code.string_to_quoted!()
|> Macro.prewalk(& Macro.expand(&1, __ENV__))
|> Macro.to_string()
|> Code.format_string!()
M
M
AB
M
AB
M
AB
AB
AB
~ $ cat ~/.iex.exs
...
defmodule X do
def d(name) when is_atom(name) do
{^name, bin, _filename} = :code.get_object_code(name)
decompile_binary(bin)
end
def d({:module, _name, bin, _names}) do
decompile_binary(bin)
end
def decompile_binary(bin) do
bin
|> :beam_lib.chunks([:abstract_code])
|> elem(1) |> elem(1)
|> get_in([:abstract_code])
|> elem(1)
|> :erl_syntax.form_list |> :erl_prettypr.format
|> IO.puts
end
end
M
Aß
AB
M
AB
AB
iex(1)> X.d X
** (MatchError) no match of right hand side value: :error
.iex.exs:26: X.d/1
iex(1)> :code.get_object_code(X)
:error
AB
M
((