0% found this document useful (0 votes)
191 views

Module To Convert Erlang Beam File To Erlfile

This module converts an Erlang beam file containing abstract code to an erl source file by extracting the abstract code chunk from the beam file, parsing it to an Erlang form list, formatting it using erl_prettypr, and writing it to a new erl file. The transform function takes the beam and erl filenames as input and handles the file operations and code extraction/formatting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views

Module To Convert Erlang Beam File To Erlfile

This module converts an Erlang beam file containing abstract code to an erl source file by extracting the abstract code chunk from the beam file, parsing it to an Erlang form list, formatting it using erl_prettypr, and writing it to a new erl file. The transform function takes the beam and erl filenames as input and handles the file operations and code extraction/formatting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Module to convert erlang beam file to erlfile

-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.

You might also like