Debian Codegraph @

doc/guide/src/CompileTimeOptions.adoc

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