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 ";
|
1995-07-02 09:51:07 -07:00
|
|
|
print_string Config.version;
|
|
|
|
print_newline()
|
|
|
|
|
1996-10-24 07:17:48 -07:00
|
|
|
let usage = "Usage: ocamlopt <options> <files>\noptions are:"
|
|
|
|
|
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";
|
|
|
|
"-intf", Arg.String process_interface_file,
|
|
|
|
"<file> Compile <file> as a .mli file";
|
|
|
|
"-linkall", Arg.Set link_everything, " Don't remove unused modules";
|
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>";
|
|
|
|
"-S", Arg.Set keep_asm_file, " Don't delete assembly file";
|
|
|
|
"-v", Arg.Unit print_version_number, " Print compiler version number";
|
|
|
|
"-unsafe", Arg.Set fast, " No bound checking on array and string access";
|
|
|
|
|
|
|
|
"-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 ()
|