[erlang-questions] compiler abstract syntax
Richard Carlsson
carlsson.richard@REDACTED
Sun Jul 17 12:48:27 CEST 2011
On 2011-07-15 12:19, Cláudio Amaral wrote:
> I would like to do some of the Erlang's compilation steps and make some
> fun stuff with the abstract/intermediate representation and generate C
> code after. The problem is that it is hard to navigate in the compiler
> modules without some guidance knowledge and I am getting easily lost.
>
> Do you know where should I be really spending my time on? Where is the
> right place to play with the internal representation, what steps were
> made already, what steps are missing and where can I find the individual
> compilation/analysis steps.
First of all, study the code in compile.erl. That will show you which
the different phases of the compilation are (and the corresponding
module for each phase), as well as some useful undocumented options like
to_core, from_core, etc. And of course, read
http://www.erlang.org/doc/man/compile.html#file-2 for info about the
documented options, in particular the 'binary' option.
The main compilation stages are:
- preprocessing (macros, conditional compilation, includes)
- source-level expansions, such as records to tuples
- translation to Core Erlang + optimizations and optional inlining
- translation to "Kernel Erlang" + pattern matching compilation
and further optimizations
- translation to Beam assembler + some more optimizations
- encoding as Beam bytecode
If you want to extract an intermediate representation and generate C
code from it, you should either take the Core Erlang representation
(which is fairly well documented and simpler to work with than the
"abstract forms" that are used for source-level Erlang), or the Beam
bytecode.
/Richard
More information about the erlang-questions
mailing list