Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / CompileTimeOptions.adoc
CommitLineData
7f918cf1
CE
1CompileTimeOptions
2==================
3
4MLton's compile-time options control the name of the output file, the
5verbosity of compile-time messages, and whether or not certain
6optimizations are performed. They also can specify which intermediate
7files are saved and can stop the compilation process early, at some
8intermediate pass, in which case compilation can be resumed by passing
9the generated files to MLton. MLton uses the input file suffix to
10determine the type of input program. The possibilities are `.c`,
11`.mlb`, `.o`, `.s`, and `.sml`.
12
13With no arguments, MLton prints the version number and exits. For a
14usage message, run MLton with an invalid switch, e.g. `mlton -z`. In
15the explanation below and in the usage message, for flags that take a
16number of choices (e.g. `{true|false}`), the first value listed is the
17default.
18
19
20== Options ==
21
22* ++-align __n__++
23+
24Aligns object in memory by the specified alignment (+4+ or +8+).
25The default varies depending on architecture.
26
27* ++-as-opt __option__++
28+
29Pass _option_ to `gcc` when compiling assembler code. If you wish to
30pass an option to the assembler, you must use `gcc`'s `-Wa,` syntax.
31
32* ++-cc-opt __option__++
33+
34Pass _option_ to `gcc` when compiling C code.
35
36* ++-codegen {native|amd64|c|llvm|x86}++
37+
38Generate native object code via amd64 assembly, C code, LLVM code, or
39x86 code or C code. With `-codegen native` (`-codegen amd64` or
40`-codegen x86`), MLton typically compiles more quickly and generates
41better code.
42
43* ++-const __name__ __value__++
44+
45Set the value of a compile-time constant. Here is a list of
46available constants, their default values, and what they control.
47+
48** ++Exn.keepHistory {false|true}++
49+
50Enable `MLton.Exn.history`. See <:MLtonExn:> for details. There is a
51performance cost to setting this to `true`, both in memory usage of
52exceptions and in run time, because of additional work that must be
53performed at each exception construction, raise, and handle.
54
55* ++-default-ann __ann__++
56+
57Specify default <:MLBasisAnnotations:ML Basis annotations>. For
58example, `-default-ann 'warnUnused true'` causes unused variable
59warnings to be enabled by default. A default is overridden by the
60corresponding annotation in an ML Basis file.
61
62* ++-default-type __type__++
63+
64Specify the default binding for a primitive type. For example,
65`-default-type word64` causes the top-level type `word` and the
66top-level structure `Word` in the <:BasisLibrary:Basis Library> to be
67equal to `Word64.word` and `Word64:WORD`, respectively. Similarly,
68`-default-type intinf` causes the top-level type `int` and the
69top-level structure `Int` in the <:BasisLibrary:Basis Library> to be
70equal to `IntInf.int` and `IntInf:INTEGER`, respectively.
71
72* ++-disable-ann __ann__++
73+
74Ignore the specified <:MLBasisAnnotations:ML Basis annotation> in
75every ML Basis file. For example, to see _all_ match and unused
76warnings, compile with
77+
78----
79-default-ann 'warnUnused true'
80-disable-ann forceUsed
81-disable-ann nonexhaustiveMatch
82-disable-ann redundantMatch
83-disable-ann warnUnused
84----
85
86* ++-export-header __file__++
87+
88Write C prototypes to _file_ for all of the functions in the program
89<:CallingFromCToSML:exported from SML to C>.
90
91* ++-ieee-fp {false|true}++
92+
93Cause the x86 native code generator to be pedantic about following the
94IEEE floating point standard. By default, it is not, because of the
95performance cost. This only has an effect with `-codegen x86`.
96
97* ++-inline __n__++
98+
99Set the inlining threshold used in the optimizer. The threshold is an
100approximate measure of code size of a procedure. The default is
101`320`.
102
103* ++-keep {g|o}++
104+
105Save intermediate files. If no `-keep` argument is given, then only
106the output file is saved.
107+
108[cols="^25%,<75%"]
109|====
110| `g` | generated `.c` and `.s` files passed to `gcc` and generated `.ll` files passed to `llvm-as`
111| `o` | object (`.o`) files
112|====
113
114* ++-link-opt __option__++
115+
116Pass _option_ to `gcc` when linking. You can use this to specify
117library search paths, e.g. `-link-opt -Lpath`, and libraries to link
118with, e.g., `-link-opt -lfoo`, or even both at the same time,
119e.g. `-link-opt '-Lpath -lfoo'`. If you wish to pass an option to the
120linker, you must use `gcc`'s `-Wl,` syntax, e.g.,
121`-link-opt '-Wl,--export-dynamic'`.
122
123* ++-llvm-as-opt __option__++
124+
125Pass _option_ to `llvm-as` when assembling (`.ll` to `.bc`) LLVM code.
126
127* ++-llvm-llc-opt __option__++
128+
129Pass _option_ to `llc` when compiling (`.bc` to `.o`) LLVM code.
130
131* ++-llvm-opt-opt __option__++
132+
133Pass _option_ to `opt` when optimizing (`.bc` to `.bc`) LLVM code.
134
135* ++-mlb-path-map __file__++
136+
137Use _file_ as an <:MLBasisPathMap:ML Basis path map> to define
138additional MLB path variables. Multiple uses of `-mlb-path-map` and
139`-mlb-path-var` are allowed, with variable definitions in later path
140maps taking precedence over earlier ones.
141
142* ++-mlb-path-var __name__ __value__++
143+
144Define an additional MLB path variable. Multiple uses of
145`-mlb-path-map` and `-mlb-path-var` are allowed, with variable
146definitions in later path maps taking precedence over earlier ones.
147
148* ++-output __file__++
149+
150Specify the name of the final output file. The default name is the
151input file name with its suffix removed and an appropriate, possibly
152empty, suffix added.
153
154* ++-profile {no|alloc|count|time}++
155+
156Produce an executable that gathers <:Profiling: profiling> data. When
157such an executable is run, it produces an `mlmon.out` file.
158
159* ++-profile-branch {false|true}++
160+
161If true, the profiler will separately gather profiling data for each
162branch of a function definition, `case` expression, and `if`
163expression.
164
165* ++-profile-stack {false|true}++
166+
167If `true`, the executable will gather profiling data for all functions
168on the stack, not just the currently executing function. See
169<:ProfilingTheStack:>.
170
171* ++-profile-val {false|true}++
172+
173If `true`, the profiler will separately gather profiling data for each
174(expansive) `val` declaration.
175
176* ++-runtime __arg__++
177+
178Pass argument to the runtime system via `@MLton`. See
179<:RunTimeOptions:>. The argument will be processed before other
180`@MLton` command line switches. Multiple uses of `-runtime` are
181allowed, and will pass all the arguments in order. If the same
182runtime switch occurs more than once, then the last setting will take
183effect. There is no need to supply the leading `@MLton` or the
184trailing `--`; these will be supplied automatically.
185+
186An argument to `-runtime` may contain spaces, which will cause the
187argument to be treated as a sequence of words by the runtime. For
188example the command line:
189+
190----
191mlton -runtime 'ram-slop 0.4' foo.sml
192----
193+
194will cause `foo` to run as if it had been called like:
195+
196----
197foo @MLton ram-slop 0.4 --
198----
199+
200An executable created with `-runtime stop` doesn't process any
201`@MLton` arguments. This is useful to create an executable, e.g.,
202`echo`, that must treat `@MLton` like any other command-line argument.
203+
204----
205% mlton -runtime stop echo.sml
206% echo @MLton --
207@MLton --
208----
209
210* ++-show-basis __file__++
211+
212Pretty print to _file_ the basis defined by the input program. See
213<:ShowBasis:>.
214
215* ++-show-def-use __file__++
216+
217Output def-use information to _file_. Each identifier that is defined
218appears on a line, followed on subsequent lines by the position of
219each use.
220
221* ++-stop {f|g|o|tc}++
222+
223Specify when to stop.
224+
225[cols="^25%,<75%"]
226|====
227| `f` | list of files on stdout (only makes sense when input is `foo.mlb`)
228| `g` | generated `.c` and `.s` files
229| `o` | object (`.o`) files
230| `tc` | after type checking
231|====
232+
233If you compile with `-stop g` or `-stop o`, you can resume compilation
234by running MLton on the generated `.c` and `.s` or `.o` files.
235
236* ++-target {self|__...__}++
237+
238Generate an executable that runs on the specified platform. The
239default is `self`, which means to compile for the machine that MLton
240is running on. To use any other target, you must first install a
241<:CrossCompiling: cross compiler>.
242
243* ++-target-as-opt __target__ __option__++
244+
245Like `-as-opt`, this passes _option_ to `gcc` when compliling
246assembler code, except it only passes _option_ when the target
247architecture, operating system, or arch-os pair is _target_.
248
249* ++-target-cc-opt __target__ __option__++
250+
251Like `-cc-opt`, this passes _option_ to `gcc` when compiling C code,
252except it only passes _option_ when the target architecture, operating
253system, or arch-os pair is _target_.
254
255* ++-target-link-opt __target__ __option__++
256+
257Like `-link-opt`, this passes _option_ to `gcc` when linking, except
258it only passes _option_ when the target architecture, operating
259system, or arch-os pair is _target_.
260
261* ++-verbose {0|1|2|3}++
262+
263How verbose to be about what passes are running. The default is `0`.
264+
265[cols="^25%,<75%"]
266|====
267| `0` | silent
268| `1` | calls to compiler, assembler, and linker
269| `2` | 1, plus intermediate compiler passes
270| `3` | 2, plus some data structure sizes
271|====