.TH mlton 1 "February 6, 2018" .SH NAME \fBmlton\fP \- whole-program compiler for the Standard ML (SML) programming language .SH SYNOPSIS \fBmlton\fP \fI[option ...] file\fB.\fP{\fBc\fP|\fBmlb\fP|\fBo\fP|\fBsml\fP} [file\fB.\fP{\fBc\fP|\fBo\fP|\fBs\fP|\fBS\fP} ...]\fR .SH DESCRIPTION .PP \fBMLton\fP is run from the command line with a collection of options followed by a file name and a list of files with which to compile, assemble, and link with. The simplest case is to run \fBmlton foo.sml\fP, where \fBfoo.sml\fP contains a valid SML program, in which case MLton compiles the program to produce an executable \fBfoo\fP. Since \fBMLton\fP does not support separate compilation, the program must be the entire program you wish to compile. However, the program may refer to signatures and structures defined in the Basis Library. Larger programs, spanning many files, may be compiled with the ML Basis system. In this case, \fBmlton foo.mlb\fP will compile the complete SML program described by the basis \fBfoo.mlb\fP, which may specify both SML files and additional bases. See the \fBMLton Guide\fP for details. \fBMLton\fP's compile-time options control the name of the output file, the verbosity of compile-time messages, and whether or not certain optimizations are performed. They also can specify which intermediate files are saved and can stop the compilation process early, at some intermediate pass, in which case compilation can be resumed by passing the generated files to \fBMLton\fP. \fBMLton\fP uses the input file suffix to determine the type of input program. The possibilities are \fB.c\fP, \fB.mlb\fP, \fB.o\fP, \fB.s\fP, and \fB.sml\fP. With no arguments, \fBMLton\fP prints the version number and exits. For a usage message, run \fBMLton\fP with an invalid switch, e.g. \fBmlton \-z\fP. In the explanation below and in the usage message, for flags that take a number of choices (e.g. \fI{\fBtrue\fP|\fBfalse\fP}\fR), the first value listed is the default. .SH Compile-time options .TP \fB\-align \fIn\fP\fR Aligns objects in memory by the specified alignment (\fB4\fP or \fB8\fP). The default varies depending on architecture. .TP \fB\-as\-opt \fIoption\fP\fR Pass \fIoption\fP to \fBgcc\fP when compiling assembler code. If you wish to pass an option to the assembler, you must use \fBgcc\fP's \fB\-Wa,\fP syntax. .TP \fB\-cc\-opt \fIoption\fP\fR Pass \fIoption\fP to \fBgcc\fP when compiling C code. .TP \fB\-codegen \fI{\fBnative\fP|\fBx86\fP|\fBamd64\fP|\fBc\fP|\fBllvm\fP}\fP\fR Generate native object code via amd64 assembly, C code, LLVM code, or x86 assembly. With \fB\-codegen native\fP (\fB\-codegen amd64\fP or \fB\-codegen x86\fP), \fBMLton\fP typically compiles more quickly and generates better code. .TP \fB\-const '\fIname value\fP'\fR Set the value of a compile-time constant. Here is a list of available constants, their default values, and what they control. \fBExn.keepHistory \fI{\fBfalse\fP|\fBtrue\fP}\fP\fR .in +.5i Enable \fBMLton.Exn.history\fP. There is a performance cost to setting this to \fBtrue\fP, both in memory usage of exceptions and in run time, because of additional work that must be performed at each exception construction, raise, and handle. .in -.5i .TP \fB\-default\-ann \fIann\fP\fR Specify default ML Basis annotations. For example, \fB\-default\-ann 'warnUnused true'\fP causes unused variable warnings to be enabled by default. Defaults may be overridden by an annotation in an ML Basis file. .TP \fB\-default\-type \fItype\fP\fR Specify the default binding for a primitive type. For example, \fB\-default\-type word64\fP causes the top-level type \fBword\fP and the top-level structure \fBWord\fP in the Basis Library to be equal to \fBWord64.word\fP and \fBWord64:WORD\fP, respectively. Similarly, \fB\-default\-type intinf\fP causes the top-level type \fBint\fP and the top-level structure \fBInt\fP in the Basis Library to be equal to \fBIntInf.int\fP and \fBIntInf:INTEGER\fP, respectively. .TP \fB\-disable\-ann \fIann\fP\fR Ignore the specified ML Basis annotation in every ML Basis File. For example, to see \fIall\fP match and unused warnings, compile with \fB\-default\-ann 'warnUnused true'\fP, \fB\-disable\-ann forceUsed\fP, \fB\-disable\-ann nonexhaustiveMatch\fP, \fB\-disable\-ann redundantMatch\fP, and \fB\-disable\-ann warnUnused\fP. .TP \fB\-export\-header \fIfile\fP\fR Write C prototypes to \fIfile\fP for all of the functions in the program exported from SML to C. .TP \fB\-ieee\-fp \fI{\fBfalse\fP|\fBtrue\fP}\fP\fR Cause the x86 native code generator to be pedantic about following the IEEE floating point standard. By default, it is not, because of the performance cost. This only has an effect with \fB\-codegen x86\fP. .TP \fB\-inline \fIn\fP\fR Set the inlining threshold used in the optimizer. The threshold is an approximate measure of code size of a procedure. The default is 320. .TP \fB\-keep \fI{\fBg\fP|\fBo\fP}\fP\fR Save intermediate files. If no \fB\-keep\fP argument is given, then only the output file is saved. .in +.5i \fBg\fP generated \fB.c\fP and \fB.s\fP files passed to \fBgcc\fP and generated \fB.ll\fP files passed to \fBllvm-as\fP .br \fBo\fP object (\fB.o\fP) files .in -.5i .TP \fB\-llvm\-as\-opt \fIoption\fP\fR Pass \fIoption\fP to \fBllvm-as\fP when assembling (\fB.ll\fP to \fB.bc\fP) LLVM code. .TP \fB\-llvm\-llc\-opt \fIoption\fP\fR Pass \fIoption\fP to \fBllc\fP when compiling (\fB.bc\fP to \fB.o\fP) LLVM code. .TP \fB\-llvm\-opt\-opt \fIoption\fP\fR Pass \fIoption\fP to \fBopt\fP when optimizing (\fB.bc\fP to \fB.bc\fP) LLVM code. .TP \fB\-link\-opt \fIoption\fP\fR Pass \fIoption\fP to \fBgcc\fP when linking. You can use this to specify library search paths, e.g. \fB\-link\-opt \-Lpath\fP, and libraries to link with, e.g. \fB\-link\-opt \-lfoo\fP, or even both at the same time, e.g. \fB\-link\-opt '\-Lpath \-lfoo'\fP. If you wish to pass an option to the linker, you must use \fBgcc\fP's \fB\-Wl,\fP syntax, e.g., \fB\-link\-opt '\-Wl,\-\-export\-dynamic'\fP. .TP \fB\-mlb\-path\-map \fIfile\fP\fR Use \fIfile\fP as an ML Basis path map to define additional MLB path variables. Multiple uses of \fB\-mlb\-path\-map\fP and \fB\-mlb\-path\-var\fP are allowed, with variable definitions in later path maps taking precedence over earlier ones. .TP \fB\-mlb\-path\-var '\fIname value\fP'\fR Define an additional MLB path variable. Multiple uses of \fB\-mlb\-path\-map\fP and \fB\-mlb\-path\-var\fP are allowed, with variable definitions in later path maps taking precedence over earlier ones. .TP \fB\-output \fIfile\fP\fR Specify the name of the final output file. The default name is the input file name with its suffix removed and an appropriate, possibly empty, suffix added. .TP \fB\-profile \fI{\fBno\fP|\fBalloc\fP|\fBcount\fP|\fBtime\fP}\fP\fR Produce an executable that gathers profiling data. When such an executable is run, it will produce an \fBmlmon.out\fP file. The man page on \fBmlprof\fP describes how to extract information from this file. .TP \fB\-profile\-branch \fI{\fBfalse\fP|\fBtrue\fP}\fP\fR If true, the profiler will separately gather profiling data for each branch of a function definition, \fBcase\fP expression, and \fBif\fP expression. .TP \fB\-profile\-stack \fI{\fBfalse\fP|\fBtrue\fP}\fP\fR If true, the profiler will gather profiling data for all functions on the stack, not just the currently executing function. .TP \fB\-profile\-val \fI{\fBfalse\fP|\fBtrue\fP}\fP\fR If true, the profiler will separately gather profiling data for each (expansive) \fBval\fP declaration. .TP \fB\-runtime \fIarg\fP\fR Pass argument to the runtime system via \fB@MLton\fP. The argument will be processed before other \fB@MLton\fP command line switches. Multiple uses of \fB\-runtime\fP are allowed, and will pass all the arguments in order. If the same runtime switch occurs more than once, then the last setting will take effect. There is no need to supply the leading \fB@MLton\fP or the trailing \fB\-\-\fP; these will be supplied automatically. An argument to \fB\-runtime\fP may contain spaces, which will cause the argument to be treated as a sequence of words by the runtime. For example, the command line: .in +.5i \fBmlton \-runtime 'ram\-slop 0.4' foo.sml\fP .in -.5i will cause foo to run as if it had been called like .in +.5i \fBfoo @MLton ram\-slop 0.4 \-\-\fP .in -.5i An executable created with \fB\-runtime stop\fP doesn't process any \fB@MLton\fP arguments. This is useful to create an executable, e.g. \fBecho\fP, that must treat \fB@MLton\fP like any other command-line argument. .in +.5i \fB% mlton \-runtime stop echo.sml\fP .in -.5i .in +.5i \fB% echo @MLton \-\-\fP .in -.5i .in +.5i \fB@MLton \-\-\fP .in -.5i .TP \fB\-show\-basis \fIfile\fP\fR Pretty print to \fIfile\fP the basis defined by the input program. .TP \fB\-show\-def\-use \fIfile\fP\fR Output def-use information to \fIfile\fP. Each identifier that is defined appears on a line, followed on subsequent lines by the position of each use. .TP \fB\-stop \fI{\fBf\fP|\fBg\fP|\fBo\fP|\fBtc\fP}\fP\fR Specify when to stop. .in +.5i \fBf\fP list of files on stdout (only makes sense when input is \fBfoo.mlb\fP) .br \fBg\fP generated \fB.c\fP and \fB.s\fP files .br \fBo\fP object (\fB.o\fP) files .br \fBtc\fP after type checking .in -.5i If you compile \fB\-stop g\fP or \fB\-stop o\fP, you can resume compilation by running \fBMLton\fP on the generated \fB.c\fP and \fB.s\fP or \fB.o\fP files. .TP \fB\-target \fI{\fBself\fP|...}\fP\fR Generate an executable that runs on the specified platform. The default is \fBself\fP, which means to compile for the machine that \fBMLton\fP is running on. To use any other target, you must first install a cross compiler. See the \fBMLton Guide\fP for details. .TP \fB\-target\-as\-opt \fItarget\fP \fIoption\fP\fR Like \fB\-as\-opt\fP, this passes \fIoption\fP to \fBgcc\fP when assembling, except it only passes \fIoption\fP when the target architecture or operating system is \fItarget\fP. .TP \fB\-target\-cc\-opt \fItarget\fP \fIoption\fP\fR Like \fB\-cc\-opt\fP, this passes \fIoption\fP to \fBgcc\fP when compiling C code, except it only passes \fIoption\fP when the target architecture or operating system is \fItarget\fP. .TP \fB\-target\-link\-opt \fItarget\fP \fIoption\fP\fR Like \fB\-link\-opt\fP, this passes \fIoption\fP to \fBgcc\fP when linking, except it only passes \fIoption\fP when the target architecture or operating system is \fItarget\fP. .TP \fB\-verbose \fI{\fB0\fP|\fB1\fP|\fB2\fP|\fB3\fP}\fP\fR How verbose to be about what passes are running. The default is 0. .in +.5i \fB0\fP silent .br \fB1\fP calls to compiler, assembler, and linker .br \fB2\fP 1, plus intermediate compiler passes .br \fB3\fP 2, plus some data structure sizes .in -.5i .SH Runtime system options Executables produced by \fBMLton\fP take command line arguments that control the runtime system. These arguments are optional, and occur before the executable's usual arguments. To use these options, the first argument to the executable must be \fB@MLton\fP. The optional arguments then follow, must be terminated by \fB\-\-\fP, and are followed by any arguments to the program. The optional arguments are \fInot\fP made available to the SML program via \fBCommandLine.arguments\fP. For example, a valid call to \fBhello-world\fP is: .in +.5i \fBhello-world @MLton gc\-summary fixed\-heap 10k \-\- a b c\fP .in -.5i In the above example, \fBCommandLine.arguments () = ["a", "b", "c"]\fP. It is allowed to have a sequence of \fB@MLton\fP arguments, as in: .in +.5i \fBhello-world @MLton gc\-summary \-\- @MLton fixed\-heap 10k \-\- a b c\fP .in -.5i Run-time options can also control \fBMLton\fP, as in .in +.5i \fBmlton @MLton fixed\-heap 0.5g \-\- foo.sml\fP .in -.5i .TP \fBfixed\-heap \fIx{\fBk\fP|\fBK\fP|\fBm\fP|\fBM\fP|\fBg\fP|\fBG\fP}\fP\fR Use a fixed size heap of size \fIx\fP, where \fIx\fP is a real number and the trailing letter indicates its units. .in +.5i \fBk\fP or \fBK\fP 1024 .br \fPm\fP or \fBM\fP 1,048,576 .br \fBg\fP or \fBG\fP 1,073,741,824 .in -.5i A value of \fB0\fP means to use almost all the RAM present on the machine. The heap size used by \fBfixed\-heap\fP includes all memory allocated by SML code, including memory for the stack (or stacks, if there are multiple threads). It does not, however, include any memory used for code itself or memory used by C globals, the C stack, or malloc. .TP \fBgc\-messages\fP Print a message at the start and end of every garbage collection. .TP \fBgc\-summary\fP Print a summary of garbage collection statistics upon program termination. .TP \fBgc\-summary\-file \fIfile\fP\fP Print a summary of garbage collection statistics upon program termination to the file specified by \fIfile\fP. .TP \fBload\-world \fIworld\fP\fR Restart the computation with the file specified by \fIworld\fP, which must have been created by a call to \fBMLton.World.save\fP by the same executable. See the \fBMLton Guide\fP for details. .TP \fBmax\-heap \fIx{\fBk\fP|\fBK\fP|\fBm\fP|\fBM\fP|\fBg\fP|\fBG\fP}\fP\fR Run the computation with an automatically resized heap that is never larger than \fIx\fP, where \fIx\fP is a real number and the trailing letter indicates the units as with \fBfixed\-heap\fP. The heap size for \fBmax\-heap\fP is accounted for as with \fBfixed\-heap\fP. .TP \fBmay\-page\-heap \fI{\fBfalse\fP|\fBtrue\fP}\fP\fR Enable paging the heap to disk when unable to grow the heap to a desired size. .TP \fBno\-load\-world\fP Disable \fBload\-world\fP. This can be used as an argument to the compiler via \fB\-runtime no\-load\-world\fP to create executables that will not load a world. This may be useful to ensure that set-uid executables do not load some strange world. .TP \fBram\-slop \fIx\fP\fR Multiply \fBx\fP by the amount of RAM on the machine to obtain what the runtime views as the amount of RAM it can use. Typically \fBx\fP is less than 1, and is used to account for space used by other programs running on the same machine. .TP \fBstop\fP Causes the runtime to stop processing \fB@MLton\fP arguments once the next \fB\-\-\fP is reached. This can be used as an argument to the compiler via \fB\-runtime stop\fP to create executables that don't process any \fB@MLton\fP arguments. .SH DIAGNOSTICS MLton's type error messages are not in a form suitable for processing by Emacs. For details on how to fix this, see http://mlton.org/Emacs. .SH "SEE ALSO" .BR mlprof (1) and the \fBMLton Guide\fP.