File: compile.html

package info (click to toggle)
erlang-doc-html 1%3A10.b.1a-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 22,488 kB
  • ctags: 9,933
  • sloc: erlang: 505; ansic: 323; perl: 61; sh: 45; makefile: 39
file content (728 lines) | stat: -rw-r--r-- 18,609 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.2 -->
<HTML>
<HEAD>
  <TITLE>compile
</TITLE>
  <SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
  <STYLE TYPE="text/css">
<!--
    .REFBODY     { margin-left: 13mm }
    .REFTYPES    { margin-left: 8mm }
-->
  </STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
      ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
  <IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>compile
</H1>
</CENTER>

<H3>MODULE</H3>
<DIV CLASS=REFBODY>
compile
</DIV>

<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
Erlang Compiler
</DIV>

<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>

<P>This module provides an interface to the standard Erlang
compiler. It can generate either a new file which contains the object
code, or return a binary which can be loaded directly.

</DIV>

<H3>EXPORTS</H3>

<P><A NAME="file/1"><STRONG><CODE>file(File)</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY>

<P>Is the same as <CODE>file(File,
        [verbose,report_errors,report_warnings])</CODE>.

</DIV>

<P><A NAME="file/2"><STRONG><CODE>file(File, Options) -&#62; CompRet</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>CompRet = ModRet | BinRet | ErrRet</CODE></STRONG><BR>
<STRONG><CODE>ModRet = {ok,ModuleName} | {ok,ModuleName,Warnings}</CODE></STRONG><BR>
<STRONG><CODE>BinRet = {ok,ModuleName,Binary} | {ok,ModuleName,Binary,Warnings}</CODE></STRONG><BR>
<STRONG><CODE>ErrRet = error | {error,Errors,Warnings}</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Compiles the code in the file <CODE>File</CODE>, which is an
         Erlang source code file without the <CODE>.erl</CODE>
         extension. <CODE>Options</CODE> determine the behavior of the compiler.

        
<P>Returns <CODE>{ok,ModuleName}</CODE> if successful, or
         <CODE>error</CODE> if there are errors. An object code file is created if the compilation succeeds with no errors.
        
<P>Here follows first all elements of <CODE>Options</CODE> that in some
        way control the behavior of the compiler.
<P>
<DL>

<DT>
<CODE>basic_validation</CODE>
</DT>

<DD>
         This option is fast way to test whether a
         module will compile successfully (mainly useful for code generators
         that want to verify the code they emit). No code will generated.
         If warnings are enabled, warnings generated by the <CODE>erl_lint</CODE>
         module (such as warnings for unused variables and functions)
         will be returned too.<BR>

         Use the <CODE>strong_validation</CODE> option to generate all warnings
         that the compiler would generate.
         <BR>

</DD>

<DT>
<CODE>strong_validation</CODE>
</DT>

<DD>
         Similar to the <CODE>basic_validation</CODE> option,
         no code will be generated, but more compiler passes will be run
         to ensure also warnings generated by the optimization passes are
         generated (such as clauses that will not match or expressions that
         are guaranteed to fail with an exception at run-time).
         <BR>

</DD>

<DT>
<CODE>binary</CODE>
</DT>

<DD>
         Causes the compiler to return the object code in a
         binary instead of creating an object file. If successful,
         the compiler returns <CODE>{ok,ModuleName,Binary}</CODE>
         <BR>

</DD>

<DT>
<CODE>debug_info</CODE>
</DT>

<DD>
         
         Include debug information in the compiled beam module.
         Currently, the only Erlang/OTP applications that use the
         debug information are Xref and Debugger.<BR>


         Warning: Note that the source code can be reconstructed from the abstract
         code. Therefore, never include debug information if you want to keep the
         source code secret.
         <BR>

</DD>

<DT>
<CODE>'P'</CODE>
</DT>

<DD>
         Produces a listing of the parsed code after preprocessing and parse transforms, in the file
         <CODE>&#60;File&#62;.P</CODE>.
         No object file is produced.
         <BR>

</DD>

<DT>
<CODE>'E'</CODE>
</DT>

<DD>
         Produces a listing of the
         code after all source code transformations have been performed,
         in the file <CODE>&#60;File&#62;.E</CODE>.
         No object file is produced.
         <BR>

</DD>

<DT>
<CODE>'S'</CODE>
</DT>

<DD>
         Produces a listing of the assembler code in the file
         <CODE>&#60;File&#62;.S</CODE>.
         No object file is produced.
         <BR>

</DD>

<DT>
<CODE>report_errors/report_warnings</CODE>
</DT>

<DD>
         Causes errors/warnings to be printed as they occur.
         <BR>

</DD>

<DT>
<CODE>report</CODE>
</DT>

<DD>
         This is a short form for both <CODE>report_errors</CODE> and
         <CODE>report_warnings</CODE>.
         <BR>

</DD>

<DT>
<CODE>return_errors</CODE>
</DT>

<DD>
         If this flag is set, then
         <CODE>{error,ErrorList,WarningList}</CODE> is returned when
         there are errors.
         <BR>

</DD>

<DT>
<CODE>return_warnings</CODE>
</DT>

<DD>
         If this flag is set, then an extra field containing
         <CODE>WarningList</CODE> is added to the tuples returned on
         success.
         <BR>

</DD>

<DT>
<CODE>return</CODE>
</DT>

<DD>
         This is a short form for both <CODE>return_errors</CODE> and
         <CODE>return_warnings</CODE>.
         <BR>

</DD>

<DT>
<CODE>verbose</CODE>
</DT>

<DD>
         Causes more verbose information from the compiler
         describing what it is doing.
         <BR>

</DD>

<DT>
<CODE>{outdir,Dir}</CODE>
</DT>

<DD>
         Sets a new directory for the object code. The current
         directory is used for output, except when a directory
         has been specified with this option.
         <BR>

</DD>

<DT>
<CODE>export_all</CODE>
</DT>

<DD>
         Causes all functions in the module to be exported.
         <BR>

</DD>

<DT>
<CODE>{i,Dir}</CODE>
</DT>

<DD>
Add <CODE>Dir</CODE> to the list of directories to be searched
         when including a file. When encountering an <CODE>-include</CODE> or
         <CODE>-include_dir</CODE> directive, the compiler searches for header
         files in the following directories:<BR>

         
<OL>

<LI>
<CODE>&#34;.&#34;</CODE>, the current working directory of the
         file server;<BR>

</LI>


<LI>
the base name of the compiled file;<BR>

</LI>


<LI>
the directories specified using the <CODE>i</CODE> option.
         The directory specified last is searched first.<BR>

</LI>


</OL>

         
</DD>

<DT>
<CODE>{d,Macro}</CODE>
</DT>

<DD>
         
</DD>

<DT>
<CODE>{d,Macro,Value}</CODE>
</DT>

<DD>
         Defines a macro <CODE>Macro</CODE> to have the value
         <CODE>Value</CODE>. The default is <CODE>true</CODE>).
         <BR>

</DD>

<DT>
<CODE>{parse_transform,Module}</CODE>
</DT>

<DD>
         Causes the parse transformation function
         <CODE>Module:parse_transform/2</CODE> to be applied to the
         parsed code before the code is checked for errors.
         <BR>

</DD>

<DT>
<CODE>asm</CODE>
</DT>

<DD>
         The input file is expected to be assembler
         code (default file suffix &#34;.S&#34;).
         Note that the format of assembler files
         is not documented, and may change between releases - this
         option is primarily for internal debugging use.
         <BR>

</DD>

<DT>
<CODE>warn_export_vars</CODE>
</DT>

<DD>
Causes warnings to be emitted for all implicitly
         exported variables referred to after the primitives
         where they were first defined. No warnings for exported
         variables unless they are referred to in some pattern,
         which is the default, can be selected by the option
         <CODE>nowarn_export_vars</CODE>.
         <BR>

</DD>

<DT>
<CODE>ignore_try</CODE>
</DT>

<DD>
<CODE>try</CODE> is a reserved keyword from the R9 release 
         and may not be used as atom names or field names in records (unless
         single-quoted). To compile old code where <CODE>try</CODE> is used,
         the <CODE>ignore_try</CODE> can be given.
<BR>

</DD>

<DT>
<CODE>ignore_cond</CODE>
</DT>

<DD>
<CODE>cond</CODE> is a reserved keyword starting with the R9 release
         and may not be used as atom names or field names in records (unless
         single-quoted). To compile old code where <CODE>cond</CODE> is used,
         the <CODE>ignore_cond</CODE> can be given.
<BR>

</DD>

</DL>

<P>If warnings are turned on (the <CODE>report_warnings</CODE> option
        described above), the following options control what type of
        warnings that will be generated.
        With the exception of <CODE>{warn_format,Verbosity}</CODE> all options
        below have two forms; one <CODE>warn_xxx</CODE> form to turn on
        the warning and one <CODE>nowarn_xxx</CODE> form to turn off the
        warning. In the description that follows, the form that is used
        to change the default value is listed.
<P>
<DL>

<DT>
<CODE>{warn_format, Verbosity}</CODE>
</DT>

<DD>
Causes warnings to be emitted for malformed format
         strings as arguments to <CODE>io:format</CODE> and similar
         functions. <CODE>Verbosity</CODE> selects the amount of
         warnings: 0 = no warnings; 1 = warnings for invalid
         format strings and incorrect number of arguments; 2 =
         warnings also when the validity could not be checked
         (for example, when the format string argument is a
         variable). The default verbosity is 1. Verbosity 0 can
         also be selected by the option <CODE>nowarn_format</CODE>.
         <BR>

</DD>

<DT>
<CODE>nowarn_bif_clash</CODE>
</DT>

<DD>
By default, a warning will be emitted when a
         module contains an exported function with the same name
         as an auto-imported BIF (such as <CODE>size/1</CODE>) AND
         there is a call to it without a qualifying module name.
         The reason is that the BIF will be called, not the function
         in the same module. The recommended way to eliminate
         that warning is to use a call with a module name - either
         <CODE>erlang</CODE> to call the BIF or <CODE>?MODULE</CODE> to call
         the function in the same module.
         The warning can also be turned off using <CODE>nowarn_bif_clash</CODE>,
         but that is not recommended.
         <BR>

</DD>

<DT>
<CODE>warn_shadow_vars</CODE>
</DT>

<DD>
Causes warnings to be emitted for &#34;fresh&#34; variables
         in functional objects or list comprehensions with the
         same name as some already defined variable. The default
         is to warn for such variables. No warnings for shadowed
         variables can be selected by the option 
         <CODE>nowarn_shadow_vars</CODE>.
         <BR>

</DD>

<DT>
<CODE>nowarn_unused_function</CODE>
</DT>

<DD>
Turns off warnings for unused local functions.
         By default (<CODE>warn_unused_function</CODE>), warnings are emitted
         for all local functions that are not called directly or indirectly by an
         exported function.
         The compiler does include unused local functions in the
         generated beam file, but the warning is still useful to keep
         the source code cleaner.
<BR>

</DD>

<DT>
<CODE>warn_unused_import</CODE>
</DT>

<DD>
Causes warnings to be emitted for unused imported
         functions. No warnings for imported functions, which is
         the default, can be selected by the option
         <CODE>nowarn_unused_import</CODE>. 
<BR>

</DD>

<DT>
<CODE>nowarn_unused_vars</CODE>
</DT>

<DD>
By default, warnings are emitted for variables which
         are not used, with the exception of variables beginning
         with an underscore (&#34;Prolog style warnings&#34;).
         Use this option to turn off this kind of warnings.
         <BR>

</DD>

</DL>

<P>Another class of warnings (introduced in the R10B release)
        are generated by the compiler during optimization and code generation.
        They warn about patterns that will never match (such as
        <CODE>a=b</CODE>), guards that will always evaluate to false, and
        expressions that will always fail (such as <CODE>atom+42</CODE>).
        Currently, those warnings cannot be disabled (except by disabling
        all warnings).
        
<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Warning!" SRC="warning.gif"></TD>
    <TD>

<P>Obviously, the absence of warnings does not mean that there are
         no remaining errors in the code.
            </TD>
  </TR>
</TABLE>

<P>Note that all the options except the include path (<CODE>{i,Dir}</CODE>)
         can also be given in the file with a <CODE>-compile([Option,...])</CODE>.
         attribute.
        
<P>For debugging of the compiler, or for pure curiosity,
        the intermediate code generated by each compiler pass can
        be inspected.
        A complete list of the options to produce list files can
        be printed by typing <CODE>compile:options()</CODE> at the
        Erlang shell prompt.
        The options will be printed in order that the passes are executed.
        If more than one listing option is used, the one representing the
        earliest pass takes effect.

        
<P><STRONG>Unrecognized options are ignored.</STRONG>
<P>Both <CODE>WarningList</CODE> and <CODE>ErrorList</CODE> have the
        following format:

        
<PRE>
[{FileName,[ErrorInfo]}].
</PRE>

<P><CODE>ErrorInfo</CODE> is described below. The file name
         has been included here as the compiler uses the Erlang
         pre-processor <CODE>epp</CODE>, which allows the code to be included in
         other files. For this reason, it is important to know to
         <STRONG>which</STRONG> file an error or warning line number refers.


</DIV>

<P><A NAME="forms/1"><STRONG><CODE>forms(Forms)</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY>

<P>Is the same as <CODE>forms(File,
        [verbose,report_errors,report_warnings])</CODE>.

</DIV>

<P><A NAME="forms/2"><STRONG><CODE>forms(Forms, Options) -&#62; CompRet</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Forms = [Form]</CODE></STRONG><BR>
<STRONG><CODE>CompRet = BinRet | ErrRet</CODE></STRONG><BR>
<STRONG><CODE>BinRet = {ok,ModuleName,BinaryOrCode} |
        {ok,ModuleName,BinaryOrCode,Warnings}</CODE></STRONG><BR>
<STRONG><CODE>BinaryOrCode = binary() | term()
        &#60;V&#62;ErrRet = error | {error,Errors,Warnings}</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Analogous to <CODE>file/1</CODE>, but takes a list of forms (in the
        Erlang abstract format representation) as first argument.
        The option <CODE>binary</CODE> is implicit; i.e., no object code file
        is produced. Options that would ordinarily produce a listing file,
        such as 'E', will instead cause the internal format for that compiler
        pass (an Erlang term; usually not a binary) to be returned instead
        of a binary.

</DIV>

<P><A NAME="format_error/1"><STRONG><CODE>format_error(ErrorDescriptor) -&#62; string()</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>ErrorDescriptor = errordesc()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Uses an <CODE>ErrorDescriptor</CODE> and returns a string
which describes the error. This function is usually called
implicitly when an <CODE>ErrorInfo</CODE> structure is processed.
See below.

</DIV>

<H3>Default compiler options</H3>
<DIV CLASS=REFBODY>

<P>The (host operating system) environment variable <CODE>ERL_COMPILER_OPTIONS</CODE>
can be used to give default compiler options.
Its value must be a valid Erlang term. If the value is a list, it will
be used as is. If it is not a list, it will be put into a list.
The list will be appended to any options given to <CODE>file/2</CODE> or <CODE>forms/2</CODE>.

</DIV>

<H3>Inlining</H3>
<DIV CLASS=REFBODY>

<P>The compiler can now do function inlining within an Erlang module.
Inlining means that a call to a function is replaced with the function
body with the arguments replaced with the actual values. The semantics
are preserved, except if exceptions are generated in the inlined code.
Exceptions will be reported as occurring in the function the body was
inlined into. Also, <CODE>function_clause</CODE> exceptions will be converted
to similar <CODE>case_clause</CODE> exceptions.


<P>When a function is inlined, the original function may be kept
as a separate function as well, because there might still be calls
to it. Therefore, inlining almost always increases code size.


<P>Inlining does not necessarily improve running time.
For instance, inlining may increase Beam stack usage which
will probably be detrimental to performance for recursive
functions.


<P>Inlining is never default; it must be explicitly enabled with a
compiler option or a '<CODE>-compile()</CODE>' attribute in the source module.


<P>To enable inlining, use the '<CODE>inline</CODE>' option.


<P>Example:

<PRE>
-compile(inline).
</PRE>

<P>The '<CODE>{inline_size,Size}</CODE>' option controls how large functions
that are allowed to be inlined. Default is <CODE>24</CODE>, which will keep
the size of the inlined code roughly the same as the un-inlined version
(only relatively small functions will be inlined).


<P>Example:

<PRE>
%% Aggressive inlining - will increase code size.
-compile(inline).
-compile({inline_size,100}).
</PRE>

</DIV>

<H3>Parse Transformations</H3>
<DIV CLASS=REFBODY>

<P>Parse transformations are used when a programmer wants to use
Erlang syntax but with different semantics. The original Erlang
code is then transformed into other Erlang code.

</DIV>

<H3>Error Information</H3>
<DIV CLASS=REFBODY>

<P>The <CODE>ErrorInfo</CODE> mentioned above is the standard
<CODE>ErrorInfo</CODE> structure which is returned from all IO
modules. It has the following format


<PRE>
    {ErrorLine, Module, ErrorDescriptor}
</PRE>

<P>A string describing the error is obtained with the following call:


<PRE>
apply(Module, format_error, ErrorDescriptor)
</PRE>

</DIV>

<H3>See Also</H3>
<DIV CLASS=REFBODY>

<P>epp(3), erl_id_trans(3), erl_lint(3)

</DIV>

<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Bjorn Gustavsson - support@erlang.ericsson.se<BR>

</DIV>
<CENTER>
<HR>
<SMALL>compiler 4.3.1<BR>
Copyright &copy; 1991-2004
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>