<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html xmlns:fn="http://www.w3.org/2005/02/xpath-functions"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css"> <title>Erlang -- compile</title> </head> <body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container"> <script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript"> <!-- function getWinHeight() { var myHeight = 0; if( typeof( window.innerHeight ) == 'number' ) { //Non-IE myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myHeight = document.body.clientHeight; } return myHeight; } function setscrollpos() { var objf=document.getElementById('loadscrollpos'); document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2; } function addEvent(obj, evType, fn){ if (obj.addEventListener){ obj.addEventListener(evType, fn, true); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } addEvent(window, 'load', setscrollpos); //--></script><div id="leftnav"><div class="innertube"> <img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/compiler-4.8.2.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>Compiler</strong><br><strong>Reference Manual</strong><br><small>Version 4.8.2</small></p> <br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Table of Contents</strong></small></p> <ul class="flipMenu"><li id="loadscrollpos" title="compile " expanded="true">compile<ul> <li><a href="compile.html"> Top of manual page </a></li> <li title="file-1"><a href="compile.html#file-1">file/1</a></li> <li title="file-2"><a href="compile.html#file-2">file/2</a></li> <li title="forms-1"><a href="compile.html#forms-1">forms/1</a></li> <li title="forms-2"><a href="compile.html#forms-2">forms/2</a></li> <li title="format_error-1"><a href="compile.html#format_error-1">format_error/1</a></li> <li title="output_generated-1"><a href="compile.html#output_generated-1">output_generated/1</a></li> <li title="noenv_file-2"><a href="compile.html#noenv_file-2">noenv_file/2</a></li> <li title="noenv_forms-2"><a href="compile.html#noenv_forms-2">noenv_forms/2</a></li> <li title="noenv_output_generated-1"><a href="compile.html#noenv_output_generated-1">noenv_output_generated/1</a></li> </ul> </li></ul> </div></div> <div id="content"> <div class="innertube"> <!-- refpage --><center><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> <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. </p> </p></div> <h3>EXPORTS</h3> <p><a name="file-1"><span class="bold_code">file(File)</span></a><br></p> <div class="REFBODY"><p> <p>Is the same as <span class="code">file(File, [verbose,report_errors,report_warnings])</span>. </p> </p></div> <p><a name="file-2"><span class="bold_code">file(File, Options) -> CompRet</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">CompRet = ModRet | BinRet | ErrRet</span><br> </div> <div class="REFTYPES"> <span class="bold_code">ModRet = {ok,ModuleName} | {ok,ModuleName,Warnings}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">BinRet = {ok,ModuleName,Binary} | {ok,ModuleName,Binary,Warnings}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">ErrRet = error | {error,Errors,Warnings}</span><br> </div> </div> <div class="REFBODY"><p> <p>Compiles the code in the file <span class="code">File</span>, which is an Erlang source code file without the <span class="code">.erl</span> extension. <span class="code">Options</span> determine the behavior of the compiler.</p> <p>Returns <span class="code">{ok,ModuleName}</span> if successful, or <span class="code">error</span> if there are errors. An object code file is created if the compilation succeeds with no errors. It is considered to be an error if the module name in the source code is not the same as the basename of the output file.</p> <p><a name="type-option"></a>Here follows first all elements of <span class="code">Options</span> that in some way control the behavior of the compiler.</p> <dl> <dt><strong><span class="code">basic_validation</span></strong></dt> <dd> <p>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 <span class="code">erl_lint</span> module (such as warnings for unused variables and functions) will be returned too.</p> <p>Use the <span class="code">strong_validation</span> option to generate all warnings that the compiler would generate.</p> </dd> <dt><strong><span class="code">strong_validation</span></strong></dt> <dd> <p>Similar to the <span class="code">basic_validation</span> 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).</p> </dd> <dt><strong><span class="code">binary</span></strong></dt> <dd> <p>Causes the compiler to return the object code in a binary instead of creating an object file. If successful, the compiler returns <span class="code">{ok,ModuleName,Binary}</span>.</p> </dd> <dt><strong><span class="code">bin_opt_info</span></strong></dt> <dd> <p>The compiler will emit informational warnings about binary matching optimizations (both successful and unsuccessful). See the <strong>Efficiency Guide</strong> for further information.</p> </dd> <dt><strong><span class="code">compressed</span></strong></dt> <dd> <p>The compiler will compress the generated object code, which can be useful for embedded systems.</p> </dd> <dt><strong><span class="code">debug_info</span></strong></dt> <dd> <a name="debug_info"></a> <p>Include debug information in the form of abstract code (see <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','erts','absform.html');">The Abstract Format</a></span> in ERTS User's Guide) in the compiled beam module. Tools such as Debugger, Xref and Cover require the debug information to be included.</p> <p><strong>Warning</strong>: Source code can be reconstructed from the debug information. Use encrypted debug information (see below) to prevent this.</p> <p>See <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','stdlib','beam_lib.html#debug_info');">beam_lib(3)</a></span> for details.</p> </dd> <dt><strong><span class="code">{debug_info_key,KeyString}</span></strong></dt> <dd></dd> <dt><strong><span class="code">{debug_info_key,{Mode,KeyString}}</span></strong></dt> <dd> <a name="debug_info_key"></a> <p>Include debug information, but encrypt it, so that it cannot be accessed without supplying the key. (To give the <span class="code">debug_info</span> option as well is allowed, but is not necessary.) Using this option is a good way to always have the debug information available during testing, yet protect the source code.</p> <p><span class="code">Mode</span> is the type of crypto algorithm to be used for encrypting the debug information. The default type -- and currently the only type -- is <span class="code">des3_cbc</span>.</p> <p>See <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','stdlib','beam_lib.html#debug_info');">beam_lib(3)</a></span> for details.</p> </dd> <dt><strong><span class="code">encrypt_debug_info</span></strong></dt> <dd> <a name="encrypt_debug_info"></a> <p>Like the <span class="code">debug_info_key</span> option above, except that the key will be read from an <span class="code">.erlang.crypt</span> file. </p> <p>See <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','stdlib','beam_lib.html#debug_info');">beam_lib(3)</a></span> for details.</p> </dd> <dt><strong><span class="code">makedep</span></strong></dt> <dd> <p>Produce a Makefile rule to track headers dependencies. No object file is produced. </p> <p>By default, this rule is written to <span class="code"><File>.Pbeam</span>. However, if the option <span class="code">binary</span> is set, nothing is written and the rule is returned in <span class="code">Binary</span>. </p> <p>For instance, if one has the following module: </p> <div class="example"><pre> -module(module). -include_lib("eunit/include/eunit.hrl"). -include("header.hrl"). </pre></div> <p>Here is the Makefile rule generated by this option: </p> <div class="example"><pre> module.beam: module.erl \ /usr/local/lib/erlang/lib/eunit/include/eunit.hrl \ header.hrl </pre></div> </dd> <dt><strong><span class="code">{makedep_output, Output}</span></strong></dt> <dd> <p>Write generated rule(s) to <span class="code">Output</span> instead of the default <span class="code"><File>.Pbeam</span>. <span class="code">Output</span> can be a filename or an <span class="code">io_device()</span>. To write to stdout, use <span class="code">standard_io</span>. However if <span class="code">binary</span> is set, nothing is written to <span class="code">Output</span> and the result is returned to the caller with <span class="code">{ok, ModuleName, Binary}</span>. </p> </dd> <dt><strong><span class="code">{makedep_target, Target}</span></strong></dt> <dd> <p>Change the name of the rule emitted to <span class="code">Target</span>. </p> </dd> <dt><strong><span class="code">makedep_quote_target</span></strong></dt> <dd> <p>Characters in <span class="code">Target</span> special to make(1) are quoted. </p> </dd> <dt><strong><span class="code">makedep_add_missing</span></strong></dt> <dd> <p>Consider missing headers as generated files and add them to the dependencies. </p> </dd> <dt><strong><span class="code">makedep_phony</span></strong></dt> <dd> <p>Add a phony target for each dependency. </p> </dd> <dt><strong><span class="code">'P'</span></strong></dt> <dd> <p>Produces a listing of the parsed code after preprocessing and parse transforms, in the file <span class="code"><File>.P</span>. No object file is produced. </p> </dd> <dt><strong><span class="code">'E'</span></strong></dt> <dd> <p>Produces a listing of the code after all source code transformations have been performed, in the file <span class="code"><File>.E</span>. No object file is produced. </p> </dd> <dt><strong><span class="code">'S'</span></strong></dt> <dd> <p>Produces a listing of the assembler code in the file <span class="code"><File>.S</span>. No object file is produced. </p> </dd> <dt><strong><span class="code">report_errors/report_warnings</span></strong></dt> <dd> <p>Causes errors/warnings to be printed as they occur.</p> </dd> <dt><strong><span class="code">report</span></strong></dt> <dd> <p>This is a short form for both <span class="code">report_errors</span> and <span class="code">report_warnings</span>.</p> </dd> <dt><strong><span class="code">return_errors</span></strong></dt> <dd> <p>If this flag is set, then <span class="code">{error,ErrorList,WarningList}</span> is returned when there are errors.</p> </dd> <dt><strong><span class="code">return_warnings</span></strong></dt> <dd> <p>If this flag is set, then an extra field containing <span class="code">WarningList</span> is added to the tuples returned on success.</p> </dd> <dt><strong><span class="code">warnings_as_errors</span></strong></dt> <dd> <p>Causes warnings to be treated as errors. This option is supported since R13B04.</p> </dd> <dt><strong><span class="code">return</span></strong></dt> <dd> <p>This is a short form for both <span class="code">return_errors</span> and <span class="code">return_warnings</span>.</p> </dd> <dt><strong><span class="code">verbose</span></strong></dt> <dd> <p>Causes more verbose information from the compiler describing what it is doing.</p> </dd> <dt><strong><span class="code">{source,FileName}</span></strong></dt> <dd> <p>Sets the value of the source, as returned by <span class="code">module_info(compile)</span>.</p> </dd> <dt><strong><span class="code">{outdir,Dir}</span></strong></dt> <dd> <p>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.</p> </dd> <dt><strong><span class="code">export_all</span></strong></dt> <dd> <p>Causes all functions in the module to be exported.</p> </dd> <dt><strong><span class="code">{i,Dir}</span></strong></dt> <dd> <p>Add <span class="code">Dir</span> to the list of directories to be searched when including a file. When encountering an <span class="code">-include</span> or <span class="code">-include_lib</span> directive, the compiler searches for header files in the following directories:</p> <ul> <li> <p><span class="code">"."</span>, the current working directory of the file server;</p> </li> <li> <p>the base name of the compiled file;</p> </li> <li> <p>the directories specified using the <span class="code">i</span> option. The directory specified last is searched first.</p> </li> </ul> </dd> <dt><strong><span class="code">{d,Macro}</span></strong></dt> <dd></dd> <dt><strong><span class="code">{d,Macro,Value}</span></strong></dt> <dd> <p>Defines a macro <span class="code">Macro</span> to have the value <span class="code">Value</span>. <span class="code">Macro</span> is of type atom, and <span class="code">Value</span> can be any term. The default <span class="code">Value</span> is <span class="code">true</span>.</p> </dd> <dt><strong><span class="code">{parse_transform,Module}</span></strong></dt> <dd> <p>Causes the parse transformation function <span class="code">Module:parse_transform/2</span> to be applied to the parsed code before the code is checked for errors.</p> </dd> <dt><strong><span class="code">asm</span></strong></dt> <dd> <p>The input file is expected to be assembler code (default file suffix ".S"). Note that the format of assembler files is not documented, and may change between releases - this option is primarily for internal debugging use.</p> </dd> <dt><strong><span class="code">no_strict_record_tests</span></strong></dt> <dd> <p>This option is not recommended.</p> <p>By default, the generated code for the <span class="code">Record#record_tag.field</span> operation verifies that the tuple <span class="code">Record</span> is of the correct size for the record and that the first element is the tag <span class="code">record_tag</span>. Use this option to omit the verification code.</p> </dd> <dt><strong><span class="code">no_error_module_mismatch</span></strong></dt> <dd> <p>Normally the compiler verifies that the module name given in the source code is the same as the base name of the output file and refuses to generate an output file if there is a mismatch. If you have a good reason (or other reason) for having a module name unrelated to the name of the output file, this option disables that verification (there will not even be a warning if there is a mismatch).</p> </dd> <dt><strong><span class="code">{no_auto_import,[{F,A}, ...]}</span></strong></dt> <dd> <p>Makes the function <span class="code">F/A</span> no longer being auto-imported from the module <span class="code">erlang</span>, which resolves BIF name clashes. This option has to be used to resolve name clashes with BIFs auto-imported before R14A, if one wants to call the local function with the same name as an auto-imported BIF without module prefix.</p> <div class="note"> <div class="label">Note</div> <div class="content"><p> <p>From R14A and forward, the compiler resolves calls without module prefix to local or imported functions before trying auto-imported BIFs. If the BIF is to be called, use the <span class="code">erlang</span> module prefix in the call, not <span class="code">{ no_auto_import,[{F,A}, ...]}</span></p> </p></div> </div> <p>If this option is written in the source code, as a <span class="code">-compile</span> directive, the syntax <span class="code">F/A</span> can be used instead of <span class="code">{F,A}</span>. Example:</p> <div class="example"><pre>-compile({no_auto_import,[error/1]}).</pre></div> </dd> <dt><strong><span class="code">no_line_info</span></strong></dt> <dd> <p>Omit line number information in order to produce a slightly smaller output file. </p> </dd> </dl> <p>If warnings are turned on (the <span class="code">report_warnings</span> option described above), the following options control what type of warnings that will be generated. <a name="erl_lint_options"></a> With the exception of <span class="code">{warn_format,Verbosity}</span> all options below have two forms; one <span class="code">warn_xxx</span> form to turn on the warning and one <span class="code">nowarn_xxx</span> 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><strong><span class="code">{warn_format, Verbosity}</span></strong></dt> <dd> <p>Causes warnings to be emitted for malformed format strings as arguments to <span class="code">io:format</span> and similar functions. <span class="code">Verbosity</span> 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 <span class="code">nowarn_format</span>.</p> </dd> <dt><strong><span class="code">nowarn_bif_clash</span></strong></dt> <dd> <p>This option is removed, it will generate a fatal error if used.</p> <div class="warning"> <div class="label">Warning</div> <div class="content"><p> <p>Beginning with R14A, the compiler no longer calls the auto-imported BIF if the name clashes with a local or explicitly imported function and a call without explicit module name is issued. Instead the local or imported function is called. Still accepting <span class="code">nowarn_bif_clash</span> would makes a module calling functions clashing with autoimported BIFs compile with both the old and new compilers, but with completely different semantics, why the option was removed.</p> <p>The use of this option has always been strongly discouraged. From OTP R14A and forward it's an error to use it.</p> <p>To resolve BIF clashes, use explicit module names or the <span class="code">{no_auto_import,[F/A]}</span> compiler directive.</p> </p></div> </div> </dd> <dt><strong><span class="code">{nowarn_bif_clash, FAs}</span></strong></dt> <dd> <p>This option is removed, it will generate a fatal error if used.</p> <div class="warning"> <div class="label">Warning</div> <div class="content"><p> <p>The use of this option has always been strongly discouraged. From OTP R14A and forward it's an error to use it.</p> <p>To resolve BIF clashes, use explicit module names or the <span class="code">{no_auto_import,[F/A]}</span> compiler directive.</p> </p></div> </div> </dd> <dt><strong><span class="code">warn_export_all</span></strong></dt> <dd> <p>Causes a warning to be emitted if the <span class="code">export_all</span> option has also been given.</p> </dd> <dt><strong><span class="code">warn_export_vars</span></strong></dt> <dd> <p>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 <span class="code">nowarn_export_vars</span>.</p> </dd> <dt><strong><span class="code">warn_shadow_vars</span></strong></dt> <dd> <p>Causes warnings to be emitted for "fresh" 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 <span class="code">nowarn_shadow_vars</span>.</p> </dd> <dt><strong><span class="code">nowarn_unused_function</span></strong></dt> <dd> <p>Turns off warnings for unused local functions. By default (<span class="code">warn_unused_function</span>), warnings are emitted for all local functions that are not called directly or indirectly by an exported function. The compiler does not include unused local functions in the generated beam file, but the warning is still useful to keep the source code cleaner.</p> </dd> <dt><strong><span class="code">{nowarn_unused_function, FAs}</span></strong></dt> <dd> <p>Turns off warnings for unused local functions as <span class="code">nowarn_unused_function</span> but only for the mentioned local functions. <span class="code">FAs</span> is a tuple <span class="code">{Name,Arity}</span> or a list of such tuples.</p> </dd> <dt><strong><span class="code">nowarn_deprecated_function</span></strong></dt> <dd> <p>Turns off warnings for calls to deprecated functions. By default (<span class="code">warn_deprecated_function</span>), warnings are emitted for every call to a function known by the compiler to be deprecated. Note that the compiler does not know about the <span class="code">-deprecated()</span> attribute but uses an assembled list of deprecated functions in Erlang/OTP. To do a more general check the <span class="code">Xref</span> tool can be used. See also <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','tools','xref.html#deprecated_function');">xref(3)</a></span> and the function <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','tools','xref.html#m-1');">xref:m/1</a></span> also accessible through the <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','stdlib','c.html#xm-1');">c:xm/1</a></span> function.</p> </dd> <dt><strong><span class="code">{nowarn_deprecated_function, MFAs}</span></strong></dt> <dd> <p>Turns off warnings for calls to deprecated functions as <span class="code">nowarn_deprecated_function</span> but only for the mentioned functions. <span class="code">MFAs</span> is a tuple <span class="code">{Module,Name,Arity}</span> or a list of such tuples.</p> </dd> <dt><strong><span class="code">warn_obsolete_guard</span></strong></dt> <dd> <p>Causes warnings to be emitted for calls to old type testing BIFs such as <span class="code">pid/1</span> and <span class="code">list/1</span>. See the <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','doc/reference_manual','expressions.html#guards');">Erlang Reference Manual</a></span> for a complete list of type testing BIFs and their old equivalents. No warnings for calls to old type testing BIFs, which is the default, can be selected by the option <span class="code">nowarn_obsolete_guard</span>.</p> </dd> <dt><strong><span class="code">warn_unused_import</span></strong></dt> <dd> <p>Causes warnings to be emitted for unused imported functions. No warnings for unused imported functions, which is the default, can be selected by the option <span class="code">nowarn_unused_import</span>. </p> </dd> <dt><strong><span class="code">nowarn_unused_vars</span></strong></dt> <dd> <p>By default, warnings are emitted for variables which are not used, with the exception of variables beginning with an underscore ("Prolog style warnings"). Use this option to turn off this kind of warnings.</p> </dd> <dt><strong><span class="code">nowarn_unused_record</span></strong></dt> <dd> <p>Turns off warnings for unused record types. By default (<span class="code">warn_unused_records</span>), warnings are emitted for unused locally defined record types.</p> </dd> </dl> <p>Another class of warnings is generated by the compiler during optimization and code generation. They warn about patterns that will never match (such as <span class="code">a=b</span>), guards that will always evaluate to false, and expressions that will always fail (such as <span class="code">atom+42</span>).</p> <p>Note that the compiler does not warn for expressions that it does not attempt to optimize. For instance, the compiler tries to evaluate <span class="code">1/0</span>, notices that it will cause an exception and emits a warning. On the other hand, the compiler is silent about the similar expression <span class="code">X/0</span>; because of the variable in it, the compiler does not even try to evaluate and therefore it emits no warnings. </p> <p>Currently, those warnings cannot be disabled (except by disabling all warnings).</p> <div class="warning"> <div class="label">Warning</div> <div class="content"><p> <p>Obviously, the absence of warnings does not mean that there are no remaining errors in the code.</p> </p></div> </div> <p>Note that all the options except the include path (<span class="code">{i,Dir}</span>) can also be given in the file with a <span class="code">-compile([Option,...])</span>. attribute. The <span class="code">-compile()</span> attribute is allowed after function definitions.</p> <p>Note also that the <span class="code">{nowarn_unused_function, FAs}</span>, <span class="code">{nowarn_bif_clash, FAs}</span>, and <span class="code">{nowarn_deprecated_function, MFAs}</span> options are only recognized when given in files. They are not affected by the <span class="code">warn_unused_function</span>, <span class="code">warn_bif_clash</span>, or <span class="code">warn_deprecated_function</span> options.</p> <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 <span class="code">compile:options()</span> 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> <p><strong>Unrecognized options are ignored.</strong></p> <p>Both <span class="code">WarningList</span> and <span class="code">ErrorList</span> have the following format:</p> <div class="example"><pre> [{FileName,[ErrorInfo]}]. </pre></div> <p><span class="code">ErrorInfo</span> is described below. The file name has been included here as the compiler uses the Erlang pre-processor <span class="code">epp</span>, 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. </p> </p></div> <p><a name="forms-1"><span class="bold_code">forms(Forms)</span></a><br></p> <div class="REFBODY"><p> <p>Is the same as <span class="code">forms(File, [verbose,report_errors,report_warnings])</span>. </p> </p></div> <p><a name="forms-2"><span class="bold_code">forms(Forms, Options) -> CompRet</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Forms = [Form]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">CompRet = BinRet | ErrRet</span><br> </div> <div class="REFTYPES"> <span class="bold_code">BinRet = {ok,ModuleName,BinaryOrCode} | {ok,ModuleName,BinaryOrCode,Warnings}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">BinaryOrCode = binary() | term()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">ErrRet = error | {error,Errors,Warnings}</span><br> </div> </div> <div class="REFBODY"><p> <p>Analogous to <span class="code">file/1</span>, but takes a list of forms (in the Erlang abstract format representation) as first argument. The option <span class="code">binary</span> 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.</p> </p></div> <p><a name="format_error-1"><span class="bold_code">format_error(ErrorDescriptor) -> chars()</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">ErrorDescriptor = errordesc()</span><br> </div> </div> <div class="REFBODY"><p> <p>Uses an <span class="code">ErrorDescriptor</span> and returns a deep list of characters which describes the error. This function is usually called implicitly when an <span class="code">ErrorInfo</span> structure is processed. See below.</p> </p></div> <p><a name="output_generated-1"><span class="bold_code">output_generated(Options) -> true | false</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Options = [term()]</span><br> </div> </div> <div class="REFBODY"><p> <p>Determines whether the compiler would generate a <span class="code">beam</span> file with the given options. <span class="code">true</span> means that a <span class="code">beam</span> file would be generated; <span class="code">false</span> means that the compiler would generate some listing file, return a binary, or merely check the syntax of the source code.</p> </p></div> <p><a name="noenv_file-2"><span class="bold_code">noenv_file(File, Options) -> CompRet</span></a><br></p> <div class="REFBODY"><p> <p>Works exactly like <span class="bold_code"><a href="#file-2">file/2</a></span>, except that the environment variable <span class="code">ERL_COMPILER_OPTIONS</span> is not consulted.</p> </p></div> <p><a name="noenv_forms-2"><span class="bold_code">noenv_forms(Forms, Options) -> CompRet</span></a><br></p> <div class="REFBODY"><p> <p>Works exactly like <span class="bold_code"><a href="#forms-2">forms/2</a></span>, except that the environment variable <span class="code">ERL_COMPILER_OPTIONS</span> is not consulted.</p> </p></div> <p><a name="noenv_output_generated-1"><span class="bold_code">noenv_output_generated(Options) -> true | false</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Options = [term()]</span><br> </div> </div> <div class="REFBODY"><p> <p>Works exactly like <span class="bold_code"><a href="#output_generated-1">output_generated/1</a></span>, except that the environment variable <span class="code">ERL_COMPILER_OPTIONS</span> is not consulted.</p> </p></div> <h3><a name="id62295">Default compiler options</a></h3> <div class="REFBODY"> <p>The (host operating system) environment variable <span class="code">ERL_COMPILER_OPTIONS</span> 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.</p> <p>The list will be appended to any options given to <span class="bold_code"><a href="#file-2">file/2</a></span>, <span class="bold_code"><a href="#forms-2">forms/2</a></span>, and <span class="bold_code"><a href="#output_generated-1">output_generated/2</a></span>. Use the alternative functions <span class="bold_code"><a href="#noenv_file-2">noenv_file/2</a></span>, <span class="bold_code"><a href="#noenv_forms-2">noenv_forms/2</a></span>, or <span class="bold_code"><a href="#noenv_output_generated-1">noenv_output_generated/2</a></span> if you don't want the environment variable to be consulted (for instance, if you are calling the compiler recursively from inside a parse transform).</p> </div> <h3><a name="id62354">Inlining</a></h3> <div class="REFBODY"> <p>The compiler can 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, <span class="code">function_clause</span> exceptions will be converted to similar <span class="code">case_clause</span> exceptions.</p> <p>When a function is inlined, the original function will be kept if it is exported (either by an explicit export or if the <span class="code">export_all</span> option was given) or if not all calls to the function were inlined.</p> <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> <p>Inlining is never default; it must be explicitly enabled with a compiler option or a <span class="code">-compile()</span> attribute in the source module.</p> <p>To enable inlining, either use the <span class="code">inline</span> option to let the compiler decide which functions to inline or <span class="code">{inline,[{Name,Arity},...]}</span> to have the compiler inline all calls to the given functions. If the option is given inside a <span class="code">compile</span> directive in an Erlang module, <span class="code">{Name,Arity}</span> may be written as <span class="code">Name/Arity</span>.</p> <p>Example of explicit inlining:</p> <div class="example"><pre> -compile({inline,[pi/0]}). pi() -> 3.1416. </pre></div> <p>Example of implicit inlining:</p> <div class="example"><pre> -compile(inline). </pre></div> <p>The <span class="code">{inline_size,Size}</span> option controls how large functions that are allowed to be inlined. Default is <span class="code">24</span>, 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> <p>Example:</p> <div class="example"><pre> %% Aggressive inlining - will increase code size. -compile(inline). -compile({inline_size,100}). </pre></div> </div> <h3><a name="id61519">Parse Transformations</a></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.</p> </div> <h3><a name="id61532">Error Information</a></h3> <div class="REFBODY"> <p>The <span class="code">ErrorInfo</span> mentioned above is the standard <span class="code">ErrorInfo</span> structure which is returned from all IO modules. It has the following format:</p> <div class="example"><pre> {ErrorLine, Module, ErrorDescriptor} </pre></div> <p>A string describing the error is obtained with the following call:</p> <div class="example"><pre> Module:format_error(ErrorDescriptor) </pre></div> </div> <h3><a name="id61568">See Also</a></h3> <div class="REFBODY"> <p> <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','stdlib','epp.html');">epp(3)</a></span>, <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','stdlib','erl_id_trans.html');">erl_id_trans(3)</a></span>, <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','stdlib','erl_lint.html');">erl_lint(3)</a></span>, <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','stdlib','beam_lib.html');">beam_lib(3)</a></span> </p> </div> </div> <div class="footer"> <hr> <p>Copyright © 1997-2012 Ericsson AB. All Rights Reserved.</p> </div> </div> </div></body> </html>