1996-03-05 01:57:50 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1996-03-05 01:57:50 -08:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1998-04-06 09:34:56 -07:00
|
|
|
(* Copyright 1998 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1996-03-05 01:57:50 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1998-04-06 09:34:56 -07:00
|
|
|
open Printf
|
|
|
|
|
1996-05-11 11:26:49 -07:00
|
|
|
let compargs = ref ([] : string list)
|
1996-03-05 01:57:50 -08:00
|
|
|
let profargs = ref ([] : string list)
|
|
|
|
let toremove = ref ([] : string list)
|
|
|
|
|
1996-05-11 11:26:49 -07:00
|
|
|
let option opt () = compargs := opt :: !compargs
|
2002-11-04 02:49:35 -08:00
|
|
|
let option_with_arg opt arg =
|
|
|
|
compargs := (Filename.quote arg) :: opt :: !compargs
|
|
|
|
;;
|
1996-03-05 01:57:50 -08:00
|
|
|
|
2002-11-04 02:49:35 -08:00
|
|
|
let make_archive = ref false;;
|
|
|
|
let with_impl = ref false;;
|
|
|
|
let with_intf = ref false;;
|
|
|
|
let with_mli = ref false;;
|
|
|
|
let with_ml = ref false;;
|
|
|
|
|
|
|
|
let process_file filename =
|
|
|
|
if Filename.check_suffix filename ".ml" then with_ml := true;
|
|
|
|
if Filename.check_suffix filename ".mli" then with_mli := true;
|
|
|
|
compargs := (Filename.quote filename) :: !compargs
|
|
|
|
;;
|
1998-04-06 09:34:56 -07:00
|
|
|
|
1996-10-24 07:17:48 -07:00
|
|
|
let usage = "Usage: ocamlcp <options> <files>\noptions are:"
|
|
|
|
|
1998-04-06 09:34:56 -07:00
|
|
|
let incompatible o =
|
|
|
|
fprintf stderr "ocamlcp: profiling is incompatible with the %s option\n" o;
|
|
|
|
exit 2
|
1996-10-24 07:17:48 -07:00
|
|
|
|
2010-04-13 03:44:25 -07:00
|
|
|
module Options = Main_args.Make_bytecomp_options (struct
|
1998-04-06 09:34:56 -07:00
|
|
|
let _a () = make_archive := true; option "-a" ()
|
2011-12-20 02:35:43 -08:00
|
|
|
let _absname = option "-absname"
|
2007-05-16 01:21:41 -07:00
|
|
|
let _annot = option "-annot"
|
2012-05-30 07:52:37 -07:00
|
|
|
let _binannot = option "-bin-annot"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _c = option "-c"
|
1998-11-06 07:39:43 -08:00
|
|
|
let _cc s = option_with_arg "-cc" s
|
1998-04-06 09:34:56 -07:00
|
|
|
let _cclib s = option_with_arg "-cclib" s
|
|
|
|
let _ccopt s = option_with_arg "-ccopt" s
|
2005-05-09 06:39:17 -07:00
|
|
|
let _config = option "-config"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _custom = option "-custom"
|
2001-10-30 01:32:32 -08:00
|
|
|
let _dllib = option_with_arg "-dllib"
|
2001-08-28 07:47:48 -07:00
|
|
|
let _dllpath = option_with_arg "-dllpath"
|
2003-04-03 05:59:38 -08:00
|
|
|
let _dtypes = option "-dtypes"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _g = option "-g"
|
|
|
|
let _i = option "-i"
|
|
|
|
let _I s = option_with_arg "-I" s
|
2002-11-04 02:49:35 -08:00
|
|
|
let _impl s = with_impl := true; option_with_arg "-impl" s
|
|
|
|
let _intf s = with_intf := true; option_with_arg "-intf" s
|
1998-11-04 02:56:20 -08:00
|
|
|
let _intf_suffix s = option_with_arg "-intf-suffix" s
|
2000-03-24 11:31:25 -08:00
|
|
|
let _labels = option "-labels"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _linkall = option "-linkall"
|
1998-11-04 02:56:20 -08:00
|
|
|
let _make_runtime = option "-make-runtime"
|
2009-07-15 07:06:37 -07:00
|
|
|
let _no_app_funct = option "-no-app-funct"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _noassert = option "-noassert"
|
2001-09-06 01:52:32 -07:00
|
|
|
let _nolabels = option "-nolabels"
|
2000-03-09 01:12:28 -08:00
|
|
|
let _noautolink = option "-noautolink"
|
2002-02-14 07:17:11 -08:00
|
|
|
let _nostdlib = option "-nostdlib"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _o s = option_with_arg "-o" s
|
|
|
|
let _output_obj = option "-output-obj"
|
2002-02-08 08:55:44 -08:00
|
|
|
let _pack = option "-pack"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _pp s = incompatible "-pp"
|
2012-06-13 01:00:27 -07:00
|
|
|
let _ppx s = incompatible "-ppx"
|
2002-04-18 00:27:47 -07:00
|
|
|
let _principal = option "-principal"
|
1999-11-09 01:14:54 -08:00
|
|
|
let _rectypes = option "-rectypes"
|
2011-03-17 09:18:05 -07:00
|
|
|
let _runtime_variant s = option_with_arg "-runtime-variant" s
|
2009-12-09 01:17:12 -08:00
|
|
|
let _strict_sequence = option "-strict-sequence"
|
2005-03-24 09:20:54 -08:00
|
|
|
let _thread () = option "-thread" ()
|
|
|
|
let _vmthread () = option "-vmthread" ()
|
1998-04-06 09:34:56 -07:00
|
|
|
let _unsafe = option "-unsafe"
|
1998-11-04 02:56:20 -08:00
|
|
|
let _use_prims s = option_with_arg "-use-prims" s
|
|
|
|
let _use_runtime s = option_with_arg "-use-runtime" s
|
1998-04-06 09:34:56 -07:00
|
|
|
let _v = option "-v"
|
2002-08-01 08:18:03 -07:00
|
|
|
let _version = option "-version"
|
2010-05-20 07:06:29 -07:00
|
|
|
let _vnum = option "-vnum"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _verbose = option "-verbose"
|
1998-11-05 00:04:40 -08:00
|
|
|
let _w = option_with_arg "-w"
|
2000-08-23 10:13:17 -07:00
|
|
|
let _warn_error = option_with_arg "-warn-error"
|
2010-05-08 13:11:27 -07:00
|
|
|
let _warn_help = option "-warn-help"
|
2000-11-07 06:41:12 -08:00
|
|
|
let _where = option "-where"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _nopervasives = option "-nopervasives"
|
1999-09-08 10:42:52 -07:00
|
|
|
let _dparsetree = option "-dparsetree"
|
1998-04-06 09:34:56 -07:00
|
|
|
let _drawlambda = option "-drawlambda"
|
|
|
|
let _dlambda = option "-dlambda"
|
|
|
|
let _dinstr = option "-dinstr"
|
|
|
|
let anonymous = process_file
|
2002-11-04 02:49:35 -08:00
|
|
|
end);;
|
|
|
|
|
|
|
|
let add_profarg s =
|
|
|
|
profargs := (Filename.quote s) :: "-m" :: !profargs
|
|
|
|
;;
|
1996-10-24 07:17:48 -07:00
|
|
|
|
2002-11-04 02:49:35 -08:00
|
|
|
let optlist =
|
|
|
|
("-p", Arg.String add_profarg,
|
2006-11-28 07:59:35 -08:00
|
|
|
"[afilmt] Profile constructs specified by argument (default fm):\n\
|
2002-11-04 02:49:35 -08:00
|
|
|
\032 a Everything\n\
|
|
|
|
\032 f Function calls and method calls\n\
|
|
|
|
\032 i if ... then ... else\n\
|
|
|
|
\032 l while and for loops\n\
|
|
|
|
\032 m match ... with\n\
|
|
|
|
\032 t try ... with")
|
|
|
|
:: Options.list
|
|
|
|
in
|
|
|
|
Arg.parse optlist process_file usage;
|
|
|
|
if !with_impl && !with_intf then begin
|
|
|
|
fprintf stderr "ocamlcp cannot deal with both \"-impl\" and \"-intf\"\n";
|
|
|
|
fprintf stderr "please compile interfaces and implementations separately\n";
|
|
|
|
exit 2;
|
|
|
|
end else if !with_impl && !with_mli then begin
|
|
|
|
fprintf stderr "ocamlcp cannot deal with both \"-impl\" and .mli files\n";
|
|
|
|
fprintf stderr "please compile interfaces and implementations separately\n";
|
|
|
|
exit 2;
|
|
|
|
end else if !with_intf && !with_ml then begin
|
|
|
|
fprintf stderr "ocamlcp cannot deal with both \"-intf\" and .ml files\n";
|
|
|
|
fprintf stderr "please compile interfaces and implementations separately\n";
|
|
|
|
exit 2;
|
|
|
|
end;
|
|
|
|
if !with_impl then profargs := "-impl" :: !profargs;
|
|
|
|
if !with_intf then profargs := "-intf" :: !profargs;
|
|
|
|
let status =
|
|
|
|
Sys.command
|
2005-03-24 09:20:54 -08:00
|
|
|
(Printf.sprintf "ocamlc -pp \"ocamlprof -instrument %s\" %s %s"
|
2002-11-04 02:49:35 -08:00
|
|
|
(String.concat " " (List.rev !profargs))
|
|
|
|
(if !make_archive then "" else "profiling.cmo")
|
|
|
|
(String.concat " " (List.rev !compargs)))
|
|
|
|
in
|
|
|
|
exit status
|
|
|
|
;;
|