1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="manual.css">
<TITLE>
Native-code compilation (ocamlopt)
</TITLE>
</HEAD>
<BODY >
<A HREF="manual024.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="manual026.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<H1 CLASS="chapter"><A NAME="htoc120">Chapter 11</A> Native-code compilation (ocamlopt)</H1> <A NAME="c:nativecomp"></A>
This chapter describes the Objective Caml high-performance
native-code compiler <TT>ocamlopt</TT>, which compiles Caml source files to
native code object files and link these object files to produce
standalone executables. <BR>
<BR>
The native-code compiler is only available on certain platforms.
It produces code that runs faster than the bytecode produced by
<TT>ocamlc</TT>, at the cost of increased compilation time and executable code
size. Compatibility with the bytecode compiler is extremely high: the
same source code should run identically when compiled with <TT>ocamlc</TT> and
<TT>ocamlopt</TT>.<BR>
<BR>
It is not possible to mix native-code object files produced by <TT>ocamlopt</TT>
with bytecode object files produced by <TT>ocamlc</TT>: a program must be
compiled entirely with <TT>ocamlopt</TT> or entirely with <TT>ocamlc</TT>. Native-code
object files produced by <TT>ocamlopt</TT> cannot be loaded in the toplevel
system <TT>ocaml</TT>.<BR>
<BR>
<H2 CLASS="section"><A NAME="htoc121">11.1</A> Overview of the compiler</H2>
The <TT>ocamlopt</TT> command has a command-line interface very close to that
of <TT>ocamlc</TT>. It accepts the same types of arguments, and processes them
sequentially:
<UL CLASS="itemize"><LI CLASS="li-itemize">
Arguments ending in <TT>.mli</TT> are taken to be source files for
compilation unit interfaces. Interfaces specify the names exported by
compilation units: they declare value names with their types, define
public data types, declare abstract data types, and so on. From the
file <I>x</I><TT>.mli</TT>, the <TT>ocamlopt</TT> compiler produces a compiled interface
in the file <I>x</I><TT>.cmi</TT>. The interface produced is identical to that
produced by the bytecode compiler <TT>ocamlc</TT>.<BR>
<BR>
<LI CLASS="li-itemize">Arguments ending in <TT>.ml</TT> are taken to be source files for compilation
unit implementations. Implementations provide definitions for the
names exported by the unit, and also contain expressions to be
evaluated for their side-effects. From the file <I>x</I><TT>.ml</TT>, the <TT>ocamlopt</TT>
compiler produces two files: <I>x</I><TT>.o</TT>, containing native object code,
and <I>x</I><TT>.cmx</TT>, containing extra information for linking and
optimization of the clients of the unit. The compiled implementation
should always be referred to under the name <I>x</I><TT>.cmx</TT> (when given
a <TT>.o</TT> file, <TT>ocamlopt</TT> assumes that it contains code compiled from C,
not from Caml).<BR>
<BR>
The implementation is checked against the interface file <I>x</I><TT>.mli</TT>
(if it exists) as described in the manual for <TT>ocamlc</TT>
(chapter <A HREF="manual022.html#c:camlc">8</A>).<BR>
<BR>
<LI CLASS="li-itemize">Arguments ending in <TT>.cmx</TT> are taken to be compiled object code. These
files are linked together, along with the object files obtained
by compiling <TT>.ml</TT> arguments (if any), and the Caml standard
library, to produce a native-code executable program. The order in
which <TT>.cmx</TT> and <TT>.ml</TT> arguments are presented on the command line is
relevant: compilation units are initialized in that order at
run-time, and it is a link-time error to use a component of a unit
before having initialized it. Hence, a given <I>x</I><TT>.cmx</TT> file must come
before all <TT>.cmx</TT> files that refer to the unit <I>x</I>.<BR>
<BR>
<LI CLASS="li-itemize">Arguments ending in <TT>.cmxa</TT> are taken to be libraries of object code.
Such a library packs in two files (<I>lib</I><TT>.cmxa</TT> and <I>lib</I><TT>.a</TT>)
a set of object files (<TT>.cmx</TT>/<TT>.o</TT> files). Libraries are build with
<TT>ocamlopt -a</TT> (see the description of the <TT>-a</TT> option below). The object
files contained in the library are linked as regular <TT>.cmx</TT> files (see
above), in the order specified when the library was built. The only
difference is that if an object file contained in a library is not
referenced anywhere in the program, then it is not linked in.<BR>
<BR>
<LI CLASS="li-itemize">Arguments ending in <TT>.c</TT> are passed to the C compiler, which generates
a <TT>.o</TT> object file. This object file is linked with the program.<BR>
<BR>
<LI CLASS="li-itemize">Arguments ending in <TT>.o</TT>, <TT>.a</TT> or <TT>.so</TT> (<TT>.obj</TT>, <TT>.lib</TT> and <TT>.dll</TT>
under Windows) are assumed to be C object files and
libraries. They are linked with the program.</UL>
The output of the linking phase is a regular Unix executable file. It
does not need <TT>ocamlrun</TT> to run.<BR>
<BR>
<H2 CLASS="section"><A NAME="htoc122">11.2</A> Options</H2>
The following command-line options are recognized by <TT>ocamlopt</TT>.
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description"><TT><B>-a</B></TT><DD CLASS="dd-description">
Build a library (<TT>.cmxa</TT>/<TT>.a</TT> file) with the object files (<TT>.cmx</TT>/<TT>.o</TT>
files) given on the command line, instead of linking them into an
executable file. The name of the library can be set with the <TT>-o</TT>
option. The default name is <TT>library.cmxa</TT>.<BR>
<BR>
If <TT>-cclib</TT> or <TT>-ccopt</TT> options are passed on the command
line, these options are stored in the resulting <TT>.cmxa</TT> library. Then,
linking with this library automatically adds back the
<TT>-cclib</TT> and <TT>-ccopt</TT> options as if they had been provided on the
command line, unless the <TT>-noautolink</TT> option is given.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-c</B></TT><DD CLASS="dd-description">
Compile only. Suppress the linking phase of the
compilation. Source code files are turned into compiled files, but no
executable file is produced. This option is useful to
compile modules separately.<BR>
<BR>
<DT CLASS="dt-description"><B><TT>-cc</TT> <I>ccomp</I></B><DD CLASS="dd-description">
Use <I>ccomp</I> as the C linker called to build the final executable
and as the C compiler for compiling <TT>.c</TT> source files.<BR>
<BR>
<DT CLASS="dt-description"><B><TT>-cclib</TT> <TT>-l</TT><I>libname</I></B><DD CLASS="dd-description">
Pass the <TT>-l</TT><I>libname</I> option to the linker. This causes the given
C library to be linked with the program.<BR>
<BR>
<DT CLASS="dt-description"><B><TT>-ccopt</TT> <I>option</I></B><DD CLASS="dd-description">
Pass the given option to the C compiler and linker. For instance,
<TT>-ccopt -L</TT><I>dir</I> causes the C linker to search for C libraries in
directory <I>dir</I>.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-compact</B></TT><DD CLASS="dd-description">
Optimize the produced code for space rather than for time. This
results in slightly smaller but slightly slower programs. The default is to
optimize for speed.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-dtypes</B></TT><DD CLASS="dd-description">
Dump detailed type information. The information for file <I>x</I><TT>.ml</TT>
is put into file <I>x</I><TT>.annot</TT>. In case of a type error, dump
all the information inferred by the type-checker before the error.
The <I>x</I><TT>.annot</TT> file can be used with the emacs commands given in
<TT>emacs/caml-types.el</TT> to display types interactively.<BR>
<BR>
<DT CLASS="dt-description" style="background-color:yellow; color:red"><B><TT>-for-pack</TT> <I>module-path</I></B><DD CLASS="dd-description" style="background-color:yellow; color:red">
Generate an object file (<TT>.cmx</TT>/<TT>.o</TT> file) that can later be included
as a sub-module (with the given access path) of a compilation unit
constructed with <TT>-pack</TT>. For instance, <TT>ocamlopt -for-pack P -c A.ml</TT>
will generate <TT>a.cmx</TT> and <TT>a.o</TT> files that can later be used with
<TT>ocamlopt -pack -o P.cmx a.cmx</TT>.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-i</B></TT><DD CLASS="dd-description">
Cause the compiler to print all defined names (with their inferred
types or their definitions) when compiling an implementation (<TT>.ml</TT>
file). No compiled files (<TT>.cmo</TT> and <TT>.cmi</TT> files) are produced.
This can be useful to check the types inferred by the
compiler. Also, since the output follows the syntax of interfaces, it
can help in writing an explicit interface (<TT>.mli</TT> file) for a file:
just redirect the standard output of the compiler to a <TT>.mli</TT> file,
and edit that file to remove all declarations of unexported names.<BR>
<BR>
<DT CLASS="dt-description"><B><TT>-I</TT> <I>directory</I></B><DD CLASS="dd-description">
Add the given directory to the list of directories searched for
compiled interface files (<TT>.cmi</TT>), compiled object code files
(<TT>.cmx</TT>), and libraries (<TT>.cmxa</TT>). By default, the current directory
is searched first, then the standard library directory. Directories
added with <TT>-I</TT> are searched after the current directory, in the order
in which they were given on the command line, but before the standard
library directory.<BR>
<BR>
If the given directory starts with <TT>+</TT>, it is taken relative to the
standard library directory. For instance, <TT>-I +labltk</TT> adds the
subdirectory <TT>labltk</TT> of the standard library to the search path.<BR>
<BR>
<DT CLASS="dt-description"><B><TT>-inline</TT> <I>n</I></B><DD CLASS="dd-description">
Set aggressiveness of inlining to <I>n</I>, where <I>n</I> is a positive
integer. Specifying <TT>-inline 0</TT> prevents all functions from being
inlined, except those whose body is smaller than the call site. Thus,
inlining causes no expansion in code size. The default aggressiveness,
<TT>-inline 1</TT>, allows slightly larger functions to be inlined, resulting
in a slight expansion in code size. Higher values for the <TT>-inline</TT>
option cause larger and larger functions to become candidate for
inlining, but can result in a serious increase in code size.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-linkall</B></TT><DD CLASS="dd-description">
Forces all modules contained in libraries to be linked in. If this
flag is not given, unreferenced modules are not linked in. When
building a library (<TT>-a</TT> flag), setting the <TT>-linkall</TT> flag forces all
subsequent links of programs involving that library to link all the
modules contained in the library.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-noassert</B></TT><DD CLASS="dd-description">
Turn assertion checking off: assertions are not compiled.
This flag has no effect when linking already compiled files.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-noautolink</B></TT><DD CLASS="dd-description">
When linking <TT>.cmxa</TT> libraries, ignore <TT>-cclib</TT> and <TT>-ccopt</TT>
options potentially contained in the libraries (if these options were
given when building the libraries). This can be useful if a library
contains incorrect specifications of C libraries or C options; in this
case, during linking, set <TT>-noautolink</TT> and pass the correct C
libraries and options on the command line.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-nolabels</B></TT><DD CLASS="dd-description">
Ignore non-optional labels in types. Labels cannot be used in
applications, and parameter order becomes strict.<BR>
<BR>
<DT CLASS="dt-description"><B><TT>-o</TT> <I>exec-file</I></B><DD CLASS="dd-description">
Specify the name of the output file produced by the linker. The
default output name is <TT>a.out</TT>, in keeping with the Unix tradition. If
the <TT>-a</TT> option is given, specify the name of the library produced.
If the <TT>-output-obj</TT> option is given, specify the name of the output
file produced.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-output-obj</B></TT><DD CLASS="dd-description">
Cause the linker to produce a C object file instead of an executable
file. This is useful to wrap Caml code as a C library,
callable from any C program. See chapter <A HREF="manual032.html#c:intf-c">18</A>,
section <A HREF="manual032.html#s:embedded-code">18.7.5</A>. The name of the output object file is
<TT>camlprog.o</TT> by default; it can be set with the <TT>-o</TT> option.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-p</B></TT><DD CLASS="dd-description">
Generate extra code to write profile information when the program is
executed. The profile information can then be examined with the
analysis program <TT>gprof</TT>. (See chapter <A HREF="manual031.html#c:profiler">17</A> for more
information on profiling.) The <TT>-p</TT> option must be given both at
compile-time and at link-time. Linking object files not compiled with
<TT>-p</TT> is possible, but results in less precise profiling.<BR>
<BR>
<FONT COLOR=purple>Unix:</FONT>
<BLOCKQUOTE CLASS="quote"> See the Unix manual page for <TT>gprof(1)</TT> for more
information about the profiles.<BR>
<BR>
Full support for <TT>gprof</TT> is only available for certain platforms
(currently: Intel x86/Linux and Alpha/Digital Unix).
On other platforms, the <TT>-p</TT> option will result in a less precise
profile (no call graph information, only a time profile).
</BLOCKQUOTE>
<FONT COLOR=purple>Windows:</FONT>
<BLOCKQUOTE CLASS="quote">
The <TT>-p</TT> option does not work under Windows.
</BLOCKQUOTE><BR>
<BR>
<DT CLASS="dt-description"><TT><B>-pack</B></TT><DD CLASS="dd-description">
Build an object file (<TT>.cmx</TT>/<TT>.o</TT> file) and its associated compiled
interface (<TT>.cmi</TT>) that combines the <TT>.cmx</TT> object
files given on the command line, making them appear as sub-modules of
the output <TT>.cmx</TT> file. The name of the output <TT>.cmx</TT> file must be
given with the <TT>-o</TT> option. For instance,
<PRE CLASS="verbatim">
ocamlopt -pack -o P.cmx A.cmx B.cmx C.cmx
</PRE>generates compiled files <TT>P.cmx</TT>, <TT>P.o</TT> and <TT>P.cmi</TT> describing a
compilation unit having three sub-modules <TT>A</TT>, <TT>B</TT> and <TT>C</TT>,
corresponding to the contents of the object files <TT>A.cmx</TT>, <TT>B.cmx</TT> and
<TT>C.cmx</TT>. These contents can be referenced as <TT>P.A</TT>, <TT>P.B</TT> and <TT>P.C</TT>
in the remainder of the program.<BR>
<BR>
<div style="background-color:yellow; color:red; border-style:none; border-width:0.5pt">
The <TT>.cmx</TT> object files being combined must have been compiled with
the appropriate <TT>-for-pack</TT> option. In the example above,
<TT>A.cmx</TT>, <TT>B.cmx</TT> and <TT>C.cmx</TT> must have been compiled with
<TT>ocamlopt -for-pack P</TT>.<BR>
<BR>
Multiple levels of packing can be achieved by combining <TT>-pack</TT> with
<TT>-for-pack</TT>. Consider the following example:
<PRE CLASS="verbatim">
ocamlopt -for-pack P.Q -c A.ml
ocamlopt -pack -o Q.cmx -for-pack P A.cmx
ocamlopt -for-pack P -c B.ml
ocamlopt -pack -o P.cmx Q.cmx B.cmx
</PRE>The resulting <TT>P.cmx</TT> object file has sub-modules <TT>P.Q</TT>, <TT>P.Q.A</TT>
and <TT>P.B</TT>.<BR>
<BR>
The restriction to systems with GNU binutils has been droped.
</div>
<BR>
<DT CLASS="dt-description"><B><TT>-pp</TT> <I>command</I></B><DD CLASS="dd-description">
Cause the compiler to call the given <I>command</I> as a preprocessor
for each source file. The output of <I>command</I> is redirected to
an intermediate file, which is compiled. If there are no compilation
errors, the intermediate file is deleted afterwards. The name of this
file is built from the basename of the source file with the extension
<TT>.ppi</TT> for an interface (<TT>.mli</TT>) file and <TT>.ppo</TT> for an implementation
(<TT>.ml</TT>) file.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-principal</B></TT><DD CLASS="dd-description">
Check information path during type-checking, to make sure that all
types are derived in a principal way. All programs accepted in
<TT>-principal</TT> mode are also accepted in default mode with equivalent
types, but different binary signatures.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-rectypes</B></TT><DD CLASS="dd-description">
Allow arbitrary recursive types during type-checking. By default,
only recursive types where the recursion goes through an object type
are supported.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-S</B></TT><DD CLASS="dd-description">
Keep the assembly code produced during the compilation. The assembly
code for the source file <I>x</I><TT>.ml</TT> is saved in the file <I>x</I><TT>.s</TT>.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-thread</B></TT><DD CLASS="dd-description">
Compile or link multithreaded programs, in combination with the
system <TT>threads</TT> library described in chapter <A HREF="manual038.html#c:threads">24</A>.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-unsafe</B></TT><DD CLASS="dd-description">
Turn bound checking off on array and string accesses (the <TT>v.(i)</TT> and
<TT>s.[i]</TT> constructs). Programs compiled with <TT>-unsafe</TT> are therefore
faster, but unsafe: anything can happen if the program accesses an
array or string outside of its bounds.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-v</B></TT><DD CLASS="dd-description">
Print the version number of the compiler and the location of the
standard library directory, then exit.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-verbose</B></TT><DD CLASS="dd-description">
Print all external commands before they are executed, in particular
invocations of the assembler, C compiler, and linker.<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-version</B></TT><DD CLASS="dd-description">
Print the version number of the compiler in short form (e.g. <TT>3.06</TT>),
then exit.<BR>
<BR>
<DT CLASS="dt-description"><B><TT>-w</TT> <I>warning-list</I></B><DD CLASS="dd-description">
Enable or disable warnings according to the argument
<I>warning-list</I>. The argument is a string of one or several
characters, with the following meaning for each character:
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B><TT>A</TT>/<TT>a</TT></B><DD CLASS="dd-description"> enable/disable all warnings.
<DT CLASS="dt-description"><B><TT>C</TT>/<TT>c</TT></B><DD CLASS="dd-description"> enable/disable warnings for suspicious comments.
<DT CLASS="dt-description"><B><TT>D</TT>/<TT>d</TT></B><DD CLASS="dd-description"> enable/disable warnings for deprecated features.
<DT CLASS="dt-description" style="background-color:yellow; color:red"><B><TT>E</TT>/<TT>e</TT></B><DD CLASS="dd-description" style="background-color:yellow; color:red"> enable/disable warnings for fragile pattern matchings
(matchings that would remain complete if additional constructors are
added to a variant type involved).
<DT CLASS="dt-description"><B><TT>F</TT>/<TT>f</TT></B><DD CLASS="dd-description"> enable/disable warnings for partially applied functions
(i.e. <TT>f x; </TT><I>expr</I> where the application <TT>f x</TT> has a function type).
<DT CLASS="dt-description"><B><TT>L</TT>/<TT>l</TT></B><DD CLASS="dd-description"> enable/disable warnings for labels omitted in application.
<DT CLASS="dt-description"><B><TT>M</TT>/<TT>m</TT></B><DD CLASS="dd-description"> enable/disable warnings for overriden methods.
<DT CLASS="dt-description"><B><TT>P</TT>/<TT>p</TT></B><DD CLASS="dd-description"> enable/disable warnings for partial matches (missing cases
in pattern matchings).
<DT CLASS="dt-description"><B><TT>S</TT>/<TT>s</TT></B><DD CLASS="dd-description"> enable/disable warnings for statements that do not have
type <TT>unit</TT> (e.g. <I>expr1</I><TT>; </TT><I>expr2</I> when <I>expr1</I> does not
have type <TT>unit</TT>).
<DT CLASS="dt-description"><B><TT>U</TT>/<TT>u</TT></B><DD CLASS="dd-description"> enable/disable warnings for unused (redundant) match cases.
<DT CLASS="dt-description"><B><TT>V</TT>/<TT>v</TT></B><DD CLASS="dd-description"> enable/disable warnings for hidden instance variables.
<DT CLASS="dt-description" style="background-color:yellow; color:red"><B><TT>Y</TT>/<TT>y</TT></B><DD CLASS="dd-description" style="background-color:yellow; color:red"> enable/disable warnings for unused variables bound with the
<TT>let</TT> or <TT>as</TT> keywords and that don't start with an underscore.
<DT CLASS="dt-description" style="background-color:yellow; color:red"><B><TT>Z</TT>/<TT>z</TT></B><DD CLASS="dd-description" style="background-color:yellow; color:red"> enable/disable warnings for all unused variables that don't
start with an underscore.
<DT CLASS="dt-description"><B><TT>X</TT>/<TT>x</TT></B><DD CLASS="dd-description"> enable/disable all other warnings.
</DL>
<div style="background-color:yellow; color:red; border-style:none; border-width:0.5pt">
The default setting is <TT>-w Aelyz</TT>
</div>
(all warnings enabled except fragile
matchings, omitted labels, unused variables).<BR>
<BR>
<DT CLASS="dt-description"><B><TT>-warn-error</TT> <I>warning-list</I></B><DD CLASS="dd-description">
Turn the warnings indicated in the argument <I>warning-list</I> into
errors. The compiler will stop on an error as soon as one of these
warnings is emitted, instead of going on. The <I>warning-list</I>
is a string of one or several characters, with the same meaning as for
the <TT>-w</TT> option: an uppercase character turns the corresponding
warning into an error, a lowercase character leaves it as a warning.
The default setting is <TT>-warn-error a</TT> (all warnings are not treated
as errors).<BR>
<BR>
<DT CLASS="dt-description"><TT><B>-where</B></TT><DD CLASS="dd-description">
Print the location of the standard library.
</DL>
<H5 CLASS="paragraph">Options for the IA32 architecture</H5>
The IA32 code generator (Intel Pentium, AMD Athlon) supports the
following additional option:
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<TT><B>-ffast-math</B></TT><DD CLASS="dd-description"> Use the IA32 instructions to compute
trigonometric and exponential functions, instead of calling the
corresponding library routines. The functions affected are:
<TT>atan</TT>, <TT>atan2</TT>, <TT>cos</TT>, <TT>log</TT>, <TT>log10</TT>, <TT>sin</TT>, <TT>sqrt</TT>, and <TT>tan</TT>.
The resulting code runs faster, but the range of supported arguments
and the precision of the result can be reduced. In particular,
trigonometric operations <TT>cos</TT>, <TT>sin</TT>, <TT>tan</TT> have their range reduced to
[−2<SUP>64</SUP>, 2<SUP>64</SUP>].
</DL>
<H5 CLASS="paragraph">Options for the Sparc architecture</H5>
The Sparc code generator supports the following additional options:
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<TT><B>-march=v8</B></TT><DD CLASS="dd-description"> Generate SPARC version 8 code.
<DT CLASS="dt-description"><TT><B>-march=v9</B></TT><DD CLASS="dd-description"> Generate SPARC version 9 code.
</DL>
The default is to generate code for SPARC version 7, which runs on all
SPARC processors.<BR>
<BR>
<H2 CLASS="section"><A NAME="htoc123">11.3</A> Common errors</H2>
The error messages are almost identical to those of <TT>ocamlc</TT>.
See section <A HREF="manual022.html#s:comp-errors">8.4</A>.<BR>
<BR>
<H2 CLASS="section"><A NAME="htoc124">11.4</A> Running executables produced by ocamlopt</H2>
Executables generated by <TT>ocamlopt</TT> are native, statically-linked,
stand-alone executable files that can be invoked directly. They do
not depend on the <TT>ocamlrun</TT> bytecode runtime system.<BR>
<BR>
During execution of an <TT>ocamlopt</TT>-generated executable,
the following environment variables are also consulted:
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<TT><B>OCAMLRUNPARAM</B></TT><DD CLASS="dd-description"> Same usage as in <TT>ocamlrun</TT>
(see section <A HREF="manual024.html#ocamlrun-options">10.2</A>), except that option <TT>l</TT>
is ignored (the operating system's stack size limit
is used instead) and option <TT>b</TT> is ignored (stack backtraces on
uncaught exceptions are not printed).
<DT CLASS="dt-description"><TT><B>CAMLRUNPARAM</B></TT><DD CLASS="dd-description"> If <TT>OCAMLRUNPARAM</TT> is not found in the
environment, then <TT>CAMLRUNPARAM</TT> will be used instead. If
<TT>CAMLRUNPARAM</TT> is not found, then the default values will be used.
</DL>
<H2 CLASS="section"><A NAME="htoc125">11.5</A> Compatibility with the bytecode compiler</H2>
<A NAME="s:compat-native-bytecode"></A>
This section lists the known incompatibilities between the bytecode
compiler and the native-code compiler. Except on those points, the two
compilers should generate code that behave identically.
<UL CLASS="itemize"><LI CLASS="li-itemize">The following operations abort the program (via an hardware trap
or fatal Unix signal) instead of raising an exception:
<UL CLASS="itemize"><LI CLASS="li-itemize">
stack overflow (except on IA32/Linux);
<LI CLASS="li-itemize">on the Alpha processor only, floating-point operations involving
infinite or denormalized numbers (all other processors supported by
<TT>ocamlopt</TT> treat these numbers correctly, as per the IEEE 754 standard).
</UL>
In particular, notice that stack overflow caused by excessively deep
recursion is reported by most Unix kernels as a “segmentation
violation” signal.<BR>
<BR>
<LI CLASS="li-itemize">Signals are detected only when the program performs an
allocation in the heap. That is, if a signal is delivered while in a
piece of code that does not allocate, its handler will not be called
until the next heap allocation.</UL>
The best way to avoid running into those incompatibilities is to <EM>never</EM> trap the <TT>Stack_overflow</TT> exception, thus treating it
as a fatal error both with the bytecode compiler and with the
native-code compiler.
<BR>
<BR>
<HR>
<A HREF="manual024.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="manual026.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
|