1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1996-02-15 08:19:09 -08:00
|
|
|
open Config
|
1995-07-02 09:51:07 -07:00
|
|
|
open Clflags
|
|
|
|
|
1996-05-22 05:41:36 -07:00
|
|
|
let process_interface_file name =
|
|
|
|
Optcompile.interface name
|
|
|
|
|
|
|
|
let process_implementation_file name =
|
|
|
|
Optcompile.implementation name;
|
|
|
|
objfiles := (Filename.chop_extension name ^ ".cmx") :: !objfiles
|
|
|
|
|
1995-07-02 09:51:07 -07:00
|
|
|
let process_file name =
|
1995-10-24 08:37:23 -07:00
|
|
|
if Filename.check_suffix name ".ml"
|
|
|
|
or Filename.check_suffix name ".mlt" then begin
|
1995-07-02 09:51:07 -07:00
|
|
|
Optcompile.implementation name;
|
1995-10-24 08:37:23 -07:00
|
|
|
objfiles := (Filename.chop_extension name ^ ".cmx") :: !objfiles
|
1995-07-02 09:51:07 -07:00
|
|
|
end
|
|
|
|
else if Filename.check_suffix name ".mli" then
|
|
|
|
Optcompile.interface name
|
|
|
|
else if Filename.check_suffix name ".cmx"
|
|
|
|
or Filename.check_suffix name ".cmxa" then
|
|
|
|
objfiles := name :: !objfiles
|
1996-02-15 08:19:09 -08:00
|
|
|
else if Filename.check_suffix name ext_obj
|
|
|
|
or Filename.check_suffix name ext_lib then
|
1995-07-02 09:51:07 -07:00
|
|
|
ccobjs := name :: !ccobjs
|
|
|
|
else if Filename.check_suffix name ".c" then begin
|
|
|
|
Optcompile.c_file name;
|
1996-02-15 08:19:09 -08:00
|
|
|
ccobjs := (Filename.chop_suffix (Filename.basename name) ".c" ^ ext_obj)
|
1995-07-02 09:51:07 -07:00
|
|
|
:: !ccobjs
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise(Arg.Bad("don't know what to do with " ^ name))
|
|
|
|
|
|
|
|
let print_version_number () =
|
1996-04-30 07:53:58 -07:00
|
|
|
print_string "The Objective Caml native-code compiler, version ";
|
1997-02-19 08:10:33 -08:00
|
|
|
print_string Config.version; print_newline();
|
|
|
|
print_string "Standard library directory: ";
|
|
|
|
print_string Config.standard_library; print_newline()
|
1995-07-02 09:51:07 -07:00
|
|
|
|
1997-02-19 08:10:33 -08:00
|
|
|
let usage = "Usage: ocamlopt <options> <files>\nOptions are:"
|
1996-10-24 07:17:48 -07:00
|
|
|
|
1995-07-02 09:51:07 -07:00
|
|
|
let main () =
|
|
|
|
try
|
1996-10-22 06:37:20 -07:00
|
|
|
native_code := true;
|
1996-10-24 07:17:48 -07:00
|
|
|
Arg.parse [
|
|
|
|
"-a", Arg.Set make_archive, " Build a library";
|
|
|
|
"-c", Arg.Set compile_only, " Compile only (do not link)";
|
|
|
|
"-cclib", Arg.String(fun s -> ccobjs := s :: !ccobjs),
|
|
|
|
"<opt> Pass option <opt> to the C linker";
|
1996-10-26 13:47:34 -07:00
|
|
|
"-ccopt", Arg.String(fun s -> ccopts := s :: !ccopts),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<opt> Pass option <opt> to the C compiler and linker";
|
|
|
|
"-compact", Arg.Clear optimize_for_speed,
|
|
|
|
" Optimize code size rather than speed";
|
|
|
|
"-i", Arg.Set print_types, " Print the types";
|
1996-10-26 13:47:34 -07:00
|
|
|
"-I", Arg.String(fun dir -> include_dirs := dir :: !include_dirs),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<dir> Add <dir> to the list of include directories";
|
|
|
|
"-impl", Arg.String process_implementation_file,
|
|
|
|
"<file> Compile <file> as a .ml file";
|
1997-02-19 08:10:33 -08:00
|
|
|
"-inline", Arg.Int(fun n -> inline_threshold := n * 8),
|
1997-02-16 09:20:11 -08:00
|
|
|
"<n> Set aggressiveness of inlining to <n>";
|
1996-10-24 07:17:48 -07:00
|
|
|
"-intf", Arg.String process_interface_file,
|
|
|
|
"<file> Compile <file> as a .mli file";
|
1997-02-19 08:10:33 -08:00
|
|
|
"-linkall", Arg.Set link_everything,
|
|
|
|
" Link all modules, even unused ones";
|
1997-05-13 11:28:25 -07:00
|
|
|
"-noassert", Arg.Set noassert, " Don't compile assertion checks";
|
1996-11-08 06:46:18 -08:00
|
|
|
"-o", Arg.String(fun s -> exec_name := s;
|
|
|
|
archive_name := s;
|
|
|
|
object_name := s),
|
1996-10-24 07:17:48 -07:00
|
|
|
"<file> Set output file name to <file> (default a.out)";
|
1996-11-08 06:46:18 -08:00
|
|
|
"-output-obj", Arg.Unit(fun () -> output_c_object := true),
|
|
|
|
"Output a C object file instead of an executable";
|
1996-10-24 07:17:48 -07:00
|
|
|
"-pp", Arg.String(fun s -> preprocessor := Some s),
|
|
|
|
"<command> Pipe sources through preprocessor <command>";
|
1997-02-19 08:10:33 -08:00
|
|
|
"-S", Arg.Set keep_asm_file, " Keep intermediate assembly file";
|
1997-05-13 11:28:25 -07:00
|
|
|
"-unsafe", Arg.Set fast,
|
|
|
|
" No bounds checking on array and string access";
|
1996-10-24 07:17:48 -07:00
|
|
|
"-v", Arg.Unit print_version_number, " Print compiler version number";
|
1997-05-15 06:26:34 -07:00
|
|
|
"-verbose", Arg.Set verbose, " Print calls to external commands";
|
1996-10-24 07:17:48 -07:00
|
|
|
|
|
|
|
"-nopervasives", Arg.Set nopervasives, " (undocumented)";
|
|
|
|
"-drawlambda", Arg.Set dump_rawlambda, " (undocumented)";
|
|
|
|
"-dlambda", Arg.Set dump_lambda, " (undocumented)";
|
|
|
|
"-dcmm", Arg.Set dump_cmm, " (undocumented)";
|
|
|
|
"-dsel", Arg.Set dump_selection, " (undocumented)";
|
1995-07-13 10:17:20 -07:00
|
|
|
"-dlive", Arg.Unit(fun () -> dump_live := true;
|
1996-10-24 07:17:48 -07:00
|
|
|
Printmach.print_live := true),
|
|
|
|
" (undocumented)";
|
|
|
|
"-dspill", Arg.Set dump_spill, " (undocumented)";
|
|
|
|
"-dsplit", Arg.Set dump_split, " (undocumented)";
|
|
|
|
"-dinterf", Arg.Set dump_interf, " (undocumented)";
|
|
|
|
"-dprefer", Arg.Set dump_prefer, " (undocumented)";
|
|
|
|
"-dalloc", Arg.Set dump_regalloc, " (undocumented)";
|
|
|
|
"-dreload", Arg.Set dump_reload, " (undocumented)";
|
|
|
|
"-dscheduling", Arg.Set dump_scheduling, " (undocumented)";
|
|
|
|
"-dlinear", Arg.Set dump_linear, " (undocumented)";
|
|
|
|
"-dstartup", Arg.Set keep_startup_file, " (undocumented)";
|
|
|
|
|
|
|
|
"-", Arg.String process_file,
|
|
|
|
"<file> Treat <file> as a file name (even if it starts with `-')"
|
|
|
|
] process_file usage;
|
1995-07-02 09:51:07 -07:00
|
|
|
if !make_archive then begin
|
|
|
|
Optcompile.init_path();
|
1995-07-11 11:07:53 -07:00
|
|
|
Asmlibrarian.create_archive (List.rev !objfiles) !archive_name
|
1995-07-02 09:51:07 -07:00
|
|
|
end
|
1995-07-11 11:07:53 -07:00
|
|
|
else if not !compile_only & !objfiles <> [] then begin
|
1995-07-02 09:51:07 -07:00
|
|
|
Optcompile.init_path();
|
|
|
|
Asmlink.link (List.rev !objfiles)
|
|
|
|
end;
|
|
|
|
exit 0
|
|
|
|
with x ->
|
1996-07-15 09:33:27 -07:00
|
|
|
Format.set_formatter_out_channel stderr;
|
1995-07-02 09:51:07 -07:00
|
|
|
Opterrors.report_error x;
|
|
|
|
exit 2
|
|
|
|
|
|
|
|
let _ = Printexc.catch main ()
|