Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / CompileTimeOptions
CommitLineData
7f918cf1
CE
1<!DOCTYPE html>\r
2<html lang="en">\r
3<head>\r
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\r
5<meta name="generator" content="AsciiDoc 8.6.9">\r
6<title>CompileTimeOptions</title>\r
7<link rel="stylesheet" href="./asciidoc.css" type="text/css">\r
8<link rel="stylesheet" href="./pygments.css" type="text/css">\r
9\r
10\r
11<script type="text/javascript" src="./asciidoc.js"></script>\r
12<script type="text/javascript">\r
13/*<![CDATA[*/\r
14asciidoc.install();\r
15/*]]>*/\r
16</script>\r
17<link rel="stylesheet" href="./mlton.css" type="text/css">\r
18</head>\r
19<body class="article">\r
20<div id="banner">\r
21<div id="banner-home">\r
22<a href="./Home">MLton 20180207</a>\r
23</div>\r
24</div>\r
25<div id="header">\r
26<h1>CompileTimeOptions</h1>\r
27</div>\r
28<div id="content">\r
29<div id="preamble">\r
30<div class="sectionbody">\r
31<div class="paragraph"><p>MLton&#8217;s compile-time options control the name of the output file, the\r
32verbosity of compile-time messages, and whether or not certain\r
33optimizations are performed. They also can specify which intermediate\r
34files are saved and can stop the compilation process early, at some\r
35intermediate pass, in which case compilation can be resumed by passing\r
36the generated files to MLton. MLton uses the input file suffix to\r
37determine the type of input program. The possibilities are <span class="monospaced">.c</span>,\r
38<span class="monospaced">.mlb</span>, <span class="monospaced">.o</span>, <span class="monospaced">.s</span>, and <span class="monospaced">.sml</span>.</p></div>\r
39<div class="paragraph"><p>With no arguments, MLton prints the version number and exits. For a\r
40usage message, run MLton with an invalid switch, e.g. <span class="monospaced">mlton -z</span>. In\r
41the explanation below and in the usage message, for flags that take a\r
42number of choices (e.g. <span class="monospaced">{true|false}</span>), the first value listed is the\r
43default.</p></div>\r
44</div>\r
45</div>\r
46<div class="sect1">\r
47<h2 id="_options">Options</h2>\r
48<div class="sectionbody">\r
49<div class="ulist"><ul>\r
50<li>\r
51<p>\r
52<span class="monospaced">-align <em>n</em></span>\r
53</p>\r
54<div class="paragraph"><p>Aligns object in memory by the specified alignment (<span class="monospaced">4</span> or <span class="monospaced">8</span>).\r
55The default varies depending on architecture.</p></div>\r
56</li>\r
57<li>\r
58<p>\r
59<span class="monospaced">-as-opt <em>option</em></span>\r
60</p>\r
61<div class="paragraph"><p>Pass <em>option</em> to <span class="monospaced">gcc</span> when compiling assembler code. If you wish to\r
62pass an option to the assembler, you must use <span class="monospaced">gcc</span>'s <span class="monospaced">-Wa,</span> syntax.</p></div>\r
63</li>\r
64<li>\r
65<p>\r
66<span class="monospaced">-cc-opt <em>option</em></span>\r
67</p>\r
68<div class="paragraph"><p>Pass <em>option</em> to <span class="monospaced">gcc</span> when compiling C code.</p></div>\r
69</li>\r
70<li>\r
71<p>\r
72<span class="monospaced">-codegen {native|amd64|c|llvm|x86}</span>\r
73</p>\r
74<div class="paragraph"><p>Generate native object code via amd64 assembly, C code, LLVM code, or\r
75x86 code or C code. With <span class="monospaced">-codegen native</span> (<span class="monospaced">-codegen amd64</span> or\r
76<span class="monospaced">-codegen x86</span>), MLton typically compiles more quickly and generates\r
77better code.</p></div>\r
78</li>\r
79<li>\r
80<p>\r
81<span class="monospaced">-const <em>name</em> <em>value</em></span>\r
82</p>\r
83<div class="paragraph"><p>Set the value of a compile-time constant. Here is a list of\r
84available constants, their default values, and what they control.</p></div>\r
85<div class="ulist"><ul>\r
86<li>\r
87<p>\r
88<span class="monospaced">Exn.keepHistory {false|true}</span>\r
89</p>\r
90<div class="paragraph"><p>Enable <span class="monospaced">MLton.Exn.history</span>. See <a href="MLtonExn">MLtonExn</a> for details. There is a\r
91performance cost to setting this to <span class="monospaced">true</span>, both in memory usage of\r
92exceptions and in run time, because of additional work that must be\r
93performed at each exception construction, raise, and handle.</p></div>\r
94</li>\r
95</ul></div>\r
96</li>\r
97<li>\r
98<p>\r
99<span class="monospaced">-default-ann <em>ann</em></span>\r
100</p>\r
101<div class="paragraph"><p>Specify default <a href="MLBasisAnnotations">ML Basis annotations</a>. For\r
102example, <span class="monospaced">-default-ann 'warnUnused true'</span> causes unused variable\r
103warnings to be enabled by default. A default is overridden by the\r
104corresponding annotation in an ML Basis file.</p></div>\r
105</li>\r
106<li>\r
107<p>\r
108<span class="monospaced">-default-type <em>type</em></span>\r
109</p>\r
110<div class="paragraph"><p>Specify the default binding for a primitive type. For example,\r
111<span class="monospaced">-default-type word64</span> causes the top-level type <span class="monospaced">word</span> and the\r
112top-level structure <span class="monospaced">Word</span> in the <a href="BasisLibrary">Basis Library</a> to be\r
113equal to <span class="monospaced">Word64.word</span> and <span class="monospaced">Word64:WORD</span>, respectively. Similarly,\r
114<span class="monospaced">-default-type intinf</span> causes the top-level type <span class="monospaced">int</span> and the\r
115top-level structure <span class="monospaced">Int</span> in the <a href="BasisLibrary">Basis Library</a> to be\r
116equal to <span class="monospaced">IntInf.int</span> and <span class="monospaced">IntInf:INTEGER</span>, respectively.</p></div>\r
117</li>\r
118<li>\r
119<p>\r
120<span class="monospaced">-disable-ann <em>ann</em></span>\r
121</p>\r
122<div class="paragraph"><p>Ignore the specified <a href="MLBasisAnnotations">ML Basis annotation</a> in\r
123every ML Basis file. For example, to see <em>all</em> match and unused\r
124warnings, compile with</p></div>\r
125<div class="listingblock">\r
126<div class="content monospaced">\r
127<pre>-default-ann 'warnUnused true'\r
128-disable-ann forceUsed\r
129-disable-ann nonexhaustiveMatch\r
130-disable-ann redundantMatch\r
131-disable-ann warnUnused</pre>\r
132</div></div>\r
133</li>\r
134<li>\r
135<p>\r
136<span class="monospaced">-export-header <em>file</em></span>\r
137</p>\r
138<div class="paragraph"><p>Write C prototypes to <em>file</em> for all of the functions in the program\r
139<a href="CallingFromCToSML">exported from SML to C</a>.</p></div>\r
140</li>\r
141<li>\r
142<p>\r
143<span class="monospaced">-ieee-fp {false|true}</span>\r
144</p>\r
145<div class="paragraph"><p>Cause the x86 native code generator to be pedantic about following the\r
146IEEE floating point standard. By default, it is not, because of the\r
147performance cost. This only has an effect with <span class="monospaced">-codegen x86</span>.</p></div>\r
148</li>\r
149<li>\r
150<p>\r
151<span class="monospaced">-inline <em>n</em></span>\r
152</p>\r
153<div class="paragraph"><p>Set the inlining threshold used in the optimizer. The threshold is an\r
154approximate measure of code size of a procedure. The default is\r
155<span class="monospaced">320</span>.</p></div>\r
156</li>\r
157<li>\r
158<p>\r
159<span class="monospaced">-keep {g|o}</span>\r
160</p>\r
161<div class="paragraph"><p>Save intermediate files. If no <span class="monospaced">-keep</span> argument is given, then only\r
162the output file is saved.</p></div>\r
163<table class="tableblock frame-all grid-all"\r
164style="\r
165width:100%;\r
166">\r
167<col style="width:25%;">\r
168<col style="width:75%;">\r
169<tbody>\r
170<tr>\r
171<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">g</span></p></td>\r
172<td class="tableblock halign-left valign-top" ><p class="tableblock">generated <span class="monospaced">.c</span> and <span class="monospaced">.s</span> files passed to <span class="monospaced">gcc</span> and generated <span class="monospaced">.ll</span> files passed to <span class="monospaced">llvm-as</span></p></td>\r
173</tr>\r
174<tr>\r
175<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">o</span></p></td>\r
176<td class="tableblock halign-left valign-top" ><p class="tableblock">object (<span class="monospaced">.o</span>) files</p></td>\r
177</tr>\r
178</tbody>\r
179</table>\r
180</li>\r
181<li>\r
182<p>\r
183<span class="monospaced">-link-opt <em>option</em></span>\r
184</p>\r
185<div class="paragraph"><p>Pass <em>option</em> to <span class="monospaced">gcc</span> when linking. You can use this to specify\r
186library search paths, e.g. <span class="monospaced">-link-opt -Lpath</span>, and libraries to link\r
187with, e.g., <span class="monospaced">-link-opt -lfoo</span>, or even both at the same time,\r
188e.g. <span class="monospaced">-link-opt '-Lpath -lfoo'</span>. If you wish to pass an option to the\r
189linker, you must use <span class="monospaced">gcc</span>'s <span class="monospaced">-Wl,</span> syntax, e.g.,\r
190<span class="monospaced">-link-opt '-Wl,--export-dynamic'</span>.</p></div>\r
191</li>\r
192<li>\r
193<p>\r
194<span class="monospaced">-llvm-as-opt <em>option</em></span>\r
195</p>\r
196<div class="paragraph"><p>Pass <em>option</em> to <span class="monospaced">llvm-as</span> when assembling (<span class="monospaced">.ll</span> to <span class="monospaced">.bc</span>) LLVM code.</p></div>\r
197</li>\r
198<li>\r
199<p>\r
200<span class="monospaced">-llvm-llc-opt <em>option</em></span>\r
201</p>\r
202<div class="paragraph"><p>Pass <em>option</em> to <span class="monospaced">llc</span> when compiling (<span class="monospaced">.bc</span> to <span class="monospaced">.o</span>) LLVM code.</p></div>\r
203</li>\r
204<li>\r
205<p>\r
206<span class="monospaced">-llvm-opt-opt <em>option</em></span>\r
207</p>\r
208<div class="paragraph"><p>Pass <em>option</em> to <span class="monospaced">opt</span> when optimizing (<span class="monospaced">.bc</span> to <span class="monospaced">.bc</span>) LLVM code.</p></div>\r
209</li>\r
210<li>\r
211<p>\r
212<span class="monospaced">-mlb-path-map <em>file</em></span>\r
213</p>\r
214<div class="paragraph"><p>Use <em>file</em> as an <a href="MLBasisPathMap">ML Basis path map</a> to define\r
215additional MLB path variables. Multiple uses of <span class="monospaced">-mlb-path-map</span> and\r
216<span class="monospaced">-mlb-path-var</span> are allowed, with variable definitions in later path\r
217maps taking precedence over earlier ones.</p></div>\r
218</li>\r
219<li>\r
220<p>\r
221<span class="monospaced">-mlb-path-var <em>name</em> <em>value</em></span>\r
222</p>\r
223<div class="paragraph"><p>Define an additional MLB path variable. Multiple uses of\r
224<span class="monospaced">-mlb-path-map</span> and <span class="monospaced">-mlb-path-var</span> are allowed, with variable\r
225definitions in later path maps taking precedence over earlier ones.</p></div>\r
226</li>\r
227<li>\r
228<p>\r
229<span class="monospaced">-output <em>file</em></span>\r
230</p>\r
231<div class="paragraph"><p>Specify the name of the final output file. The default name is the\r
232input file name with its suffix removed and an appropriate, possibly\r
233empty, suffix added.</p></div>\r
234</li>\r
235<li>\r
236<p>\r
237<span class="monospaced">-profile {no|alloc|count|time}</span>\r
238</p>\r
239<div class="paragraph"><p>Produce an executable that gathers <a href="Profiling"> profiling</a> data. When\r
240such an executable is run, it produces an <span class="monospaced">mlmon.out</span> file.</p></div>\r
241</li>\r
242<li>\r
243<p>\r
244<span class="monospaced">-profile-branch {false|true}</span>\r
245</p>\r
246<div class="paragraph"><p>If true, the profiler will separately gather profiling data for each\r
247branch of a function definition, <span class="monospaced">case</span> expression, and <span class="monospaced">if</span>\r
248expression.</p></div>\r
249</li>\r
250<li>\r
251<p>\r
252<span class="monospaced">-profile-stack {false|true}</span>\r
253</p>\r
254<div class="paragraph"><p>If <span class="monospaced">true</span>, the executable will gather profiling data for all functions\r
255on the stack, not just the currently executing function. See\r
256<a href="ProfilingTheStack">ProfilingTheStack</a>.</p></div>\r
257</li>\r
258<li>\r
259<p>\r
260<span class="monospaced">-profile-val {false|true}</span>\r
261</p>\r
262<div class="paragraph"><p>If <span class="monospaced">true</span>, the profiler will separately gather profiling data for each\r
263(expansive) <span class="monospaced">val</span> declaration.</p></div>\r
264</li>\r
265<li>\r
266<p>\r
267<span class="monospaced">-runtime <em>arg</em></span>\r
268</p>\r
269<div class="paragraph"><p>Pass argument to the runtime system via <span class="monospaced">@MLton</span>. See\r
270<a href="RunTimeOptions">RunTimeOptions</a>. The argument will be processed before other\r
271<span class="monospaced">@MLton</span> command line switches. Multiple uses of <span class="monospaced">-runtime</span> are\r
272allowed, and will pass all the arguments in order. If the same\r
273runtime switch occurs more than once, then the last setting will take\r
274effect. There is no need to supply the leading <span class="monospaced">@MLton</span> or the\r
275trailing <span class="monospaced">--</span>; these will be supplied automatically.</p></div>\r
276<div class="paragraph"><p>An argument to <span class="monospaced">-runtime</span> may contain spaces, which will cause the\r
277argument to be treated as a sequence of words by the runtime. For\r
278example the command line:</p></div>\r
279<div class="listingblock">\r
280<div class="content monospaced">\r
281<pre>mlton -runtime 'ram-slop 0.4' foo.sml</pre>\r
282</div></div>\r
283<div class="paragraph"><p>will cause <span class="monospaced">foo</span> to run as if it had been called like:</p></div>\r
284<div class="listingblock">\r
285<div class="content monospaced">\r
286<pre>foo @MLton ram-slop 0.4 --</pre>\r
287</div></div>\r
288<div class="paragraph"><p>An executable created with <span class="monospaced">-runtime stop</span> doesn&#8217;t process any\r
289<span class="monospaced">@MLton</span> arguments. This is useful to create an executable, e.g.,\r
290<span class="monospaced">echo</span>, that must treat <span class="monospaced">@MLton</span> like any other command-line argument.</p></div>\r
291<div class="listingblock">\r
292<div class="content monospaced">\r
293<pre>% mlton -runtime stop echo.sml\r
294% echo @MLton --\r
295@MLton --</pre>\r
296</div></div>\r
297</li>\r
298<li>\r
299<p>\r
300<span class="monospaced">-show-basis <em>file</em></span>\r
301</p>\r
302<div class="paragraph"><p>Pretty print to <em>file</em> the basis defined by the input program. See\r
303<a href="ShowBasis">ShowBasis</a>.</p></div>\r
304</li>\r
305<li>\r
306<p>\r
307<span class="monospaced">-show-def-use <em>file</em></span>\r
308</p>\r
309<div class="paragraph"><p>Output def-use information to <em>file</em>. Each identifier that is defined\r
310appears on a line, followed on subsequent lines by the position of\r
311each use.</p></div>\r
312</li>\r
313<li>\r
314<p>\r
315<span class="monospaced">-stop {f|g|o|tc}</span>\r
316</p>\r
317<div class="paragraph"><p>Specify when to stop.</p></div>\r
318<table class="tableblock frame-all grid-all"\r
319style="\r
320width:100%;\r
321">\r
322<col style="width:25%;">\r
323<col style="width:75%;">\r
324<tbody>\r
325<tr>\r
326<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">f</span></p></td>\r
327<td class="tableblock halign-left valign-top" ><p class="tableblock">list of files on stdout (only makes sense when input is <span class="monospaced">foo.mlb</span>)</p></td>\r
328</tr>\r
329<tr>\r
330<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">g</span></p></td>\r
331<td class="tableblock halign-left valign-top" ><p class="tableblock">generated <span class="monospaced">.c</span> and <span class="monospaced">.s</span> files</p></td>\r
332</tr>\r
333<tr>\r
334<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">o</span></p></td>\r
335<td class="tableblock halign-left valign-top" ><p class="tableblock">object (<span class="monospaced">.o</span>) files</p></td>\r
336</tr>\r
337<tr>\r
338<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">tc</span></p></td>\r
339<td class="tableblock halign-left valign-top" ><p class="tableblock">after type checking</p></td>\r
340</tr>\r
341</tbody>\r
342</table>\r
343<div class="paragraph"><p>If you compile with <span class="monospaced">-stop g</span> or <span class="monospaced">-stop o</span>, you can resume compilation\r
344by running MLton on the generated <span class="monospaced">.c</span> and <span class="monospaced">.s</span> or <span class="monospaced">.o</span> files.</p></div>\r
345</li>\r
346<li>\r
347<p>\r
348<span class="monospaced">-target {self|<em>&#8230;</em>}</span>\r
349</p>\r
350<div class="paragraph"><p>Generate an executable that runs on the specified platform. The\r
351default is <span class="monospaced">self</span>, which means to compile for the machine that MLton\r
352is running on. To use any other target, you must first install a\r
353<a href="CrossCompiling"> cross compiler</a>.</p></div>\r
354</li>\r
355<li>\r
356<p>\r
357<span class="monospaced">-target-as-opt <em>target</em> <em>option</em></span>\r
358</p>\r
359<div class="paragraph"><p>Like <span class="monospaced">-as-opt</span>, this passes <em>option</em> to <span class="monospaced">gcc</span> when compliling\r
360assembler code, except it only passes <em>option</em> when the target\r
361architecture, operating system, or arch-os pair is <em>target</em>.</p></div>\r
362</li>\r
363<li>\r
364<p>\r
365<span class="monospaced">-target-cc-opt <em>target</em> <em>option</em></span>\r
366</p>\r
367<div class="paragraph"><p>Like <span class="monospaced">-cc-opt</span>, this passes <em>option</em> to <span class="monospaced">gcc</span> when compiling C code,\r
368except it only passes <em>option</em> when the target architecture, operating\r
369system, or arch-os pair is <em>target</em>.</p></div>\r
370</li>\r
371<li>\r
372<p>\r
373<span class="monospaced">-target-link-opt <em>target</em> <em>option</em></span>\r
374</p>\r
375<div class="paragraph"><p>Like <span class="monospaced">-link-opt</span>, this passes <em>option</em> to <span class="monospaced">gcc</span> when linking, except\r
376it only passes <em>option</em> when the target architecture, operating\r
377system, or arch-os pair is <em>target</em>.</p></div>\r
378</li>\r
379<li>\r
380<p>\r
381<span class="monospaced">-verbose {0|1|2|3}</span>\r
382</p>\r
383<div class="paragraph"><p>How verbose to be about what passes are running. The default is <span class="monospaced">0</span>.</p></div>\r
384<table class="tableblock frame-all grid-all"\r
385style="\r
386width:100%;\r
387">\r
388<col style="width:25%;">\r
389<col style="width:75%;">\r
390<tbody>\r
391<tr>\r
392<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">0</span></p></td>\r
393<td class="tableblock halign-left valign-top" ><p class="tableblock">silent</p></td>\r
394</tr>\r
395<tr>\r
396<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">1</span></p></td>\r
397<td class="tableblock halign-left valign-top" ><p class="tableblock">calls to compiler, assembler, and linker</p></td>\r
398</tr>\r
399<tr>\r
400<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">2</span></p></td>\r
401<td class="tableblock halign-left valign-top" ><p class="tableblock">1, plus intermediate compiler passes</p></td>\r
402</tr>\r
403<tr>\r
404<td class="tableblock halign-center valign-top" ><p class="tableblock"><span class="monospaced">3</span></p></td>\r
405<td class="tableblock halign-left valign-top" ><p class="tableblock">2, plus some data structure sizes</p></td>\r
406</tr>\r
407</tbody>\r
408</table>\r
409</li>\r
410</ul></div>\r
411</div>\r
412</div>\r
413</div>\r
414<div id="footnotes"><hr></div>\r
415<div id="footer">\r
416<div id="footer-text">\r
417</div>\r
418<div id="footer-badges">\r
419</div>\r
420</div>\r
421</body>\r
422</html>\r