Skip to content

Commit 8fb9b99

Browse files
committed
Update compiler and erlc documentation
* Document the `to_abstr`, `to_exp`, and `from_abstr` compiler options. * Document that `erlc` accepts the `.abstr` extension. * Add a new section with recommendations for language implementors.
1 parent 841002c commit 8fb9b99

2 files changed

Lines changed: 70 additions & 10 deletions

File tree

erts/doc/references/erlc_cmd.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ The following compilers are supported:
166166

167167
Supported options: same as for `.erl`.
168168

169-
- **`.core`** - Erlang core source code. It generates a `.beam` file.
169+
- **`.core`** - Core Erlang source code. It generates a `.beam` file.
170+
171+
Supported options: same as for `.erl`.
172+
173+
- **`.abstr`** - Erlang abstract format as produced by `to_abstr`.
174+
It generates a `.beam` file.
170175

171176
Supported options: same as for `.erl`.
172177

lib/compiler/src/compile.erl

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,49 @@ other Erlang code.
154154
See `m:erl_id_trans` for an example and an explanation of the function
155155
`parse_transform_info/0`.
156156

157+
## Recommendations for Language Implementors
158+
159+
Except for Erlang, there are quite a few other languges that can run
160+
on the Erlang runtime system. Generally, such compilers produce a file
161+
or binary that is fed into the Erlang compiler. There are four ways
162+
to do that using documented functionality:
163+
164+
* **Erlang source code (`.erl` file)**: The file is compiled
165+
using `compile:file/2` or `erlc <FILE>.erl`. This is the most
166+
straightforward and portable way. The main disadvantage is that
167+
it is hard or impossible to map each line of Erlang code back to the
168+
corresponding line in the original source file.
169+
170+
* **[The abstract format](`e:erts:absform.html`)**: This format
171+
supports mapping every Erlang source line back to its corresponding
172+
line in the original source file. To compile from the abstract
173+
format, do one following:
174+
175+
* Call `compile:forms/2` to directly pass in the term
176+
representation of the [abstract format](`e:erts:absform.html`).
177+
178+
* Write the term representation to a file with the extension
179+
`.abstr` and compile that file using `compile:file(<File>,
180+
[from_abstr])` or `erlc <File>.abstr`.
181+
182+
* **Core Erlang**: While there is a specification for Core Erlang,
183+
certain details are left to the implementation via the `primop`
184+
expression. Primops can be added, deleted, or changed in any major
185+
release without notice. Note that by generating Core Erlang
186+
directly, it is possible to construct code that the Core-to-BEAM
187+
backend has never encountered before, and there are no guarantees
188+
that the final BEAM code will be safe.
189+
190+
* **BEAM assembly code**: Strongly discouraged, as it is very hard to
191+
get right and requires continuous maintenance. New instructions are
192+
typically introduced in each major release (and sometimes old ones
193+
are removed). In particular, note that BEAM code that does not
194+
follow the correct conventions can cause the runtime system to crash
195+
(segfault).
196+
197+
Our recommendation is to use either the abstract format or Erlang
198+
source code.
199+
157200
## See Also
158201

159202
`m:epp`, `m:erl_expand_records`, `m:erl_id_trans`, `m:erl_lint`, `m:beam_lib`
@@ -476,19 +519,31 @@ Available options:
476519
`Module:parse_transform/2` to be applied to the parsed code before the code is
477520
checked for errors.
478521

479-
- **`from_abstr`** - The input file is expected to contain Erlang terms
480-
representing forms in abstract format (default file suffix ".abstr"). Note
481-
that the format of such terms can change between releases.
522+
- **`to_abstr`** - Dumps the terms representing the [abstract
523+
format](`e:erts:absform.html`), after preprocessing and parse
524+
transforms, in the file `<File>.abstr`. No object file is produced.
482525

483-
See also the `no_lint` option.
526+
- **`to_exp`** - Dumps the terms representing the [abstract
527+
format](`e:erts:absform.html`), after all source code
528+
transformations have been performed, to the file `<File>.exp`. No
529+
object file is produced.
484530

485-
- **`from_asm`** - The input file is expected to be assembler code (default file
486-
suffix ".S"). Notice that the format of assembler files is not documented, and
531+
- **`from_abstr`** - The input file is expected to contain Erlang
532+
terms representing forms in the [abstract
533+
format](`e:erts:absform.html`) as generated by the `to_abstr` option
534+
(default file suffix ".abstr"). Note that the format of such terms
487535
can change between releases.
488536

489-
- **`from_core`** - The input file is expected to be core code (default file
490-
suffix ".core"). Notice that the format of core files is not documented, and
491-
can change between releases.
537+
See also the `no_lint` option.
538+
539+
- **`from_asm`** - The input file is expected to be BEAM assembly code
540+
as generated by the `'S'` option (default file suffix ".S"). Note
541+
that the format of assembler files is not documented, and can change
542+
between releases.
543+
544+
- **`from_core`** - The input file is expected to be Core Erlang code
545+
(default file suffix ".core"). Note that the exact format of Core Erlang
546+
files is not documented, and can change between releases.
492547

493548
- **`no_spawn_compiler_process`** - By default, all code is compiled in a
494549
separate process which is terminated at the end of compilation. However, some

0 commit comments

Comments
 (0)