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 *)
|
|
|
|
(* *)
|
2002-02-08 01:27:48 -08:00
|
|
|
(* Copyright 2002 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. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* The batch compiler *)
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
open Config
|
2000-03-06 14:12:09 -08:00
|
|
|
open Format
|
1995-05-04 03:15:53 -07:00
|
|
|
open Typedtree
|
|
|
|
|
|
|
|
(* Initialize the search path.
|
|
|
|
The current directory is always searched first,
|
|
|
|
then the directories specified with the -I option (in command-line order),
|
2002-02-14 07:17:11 -08:00
|
|
|
then the standard library directory (unless the -nostdlib option is given).
|
|
|
|
*)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let init_path () =
|
1996-09-09 05:35:00 -07:00
|
|
|
let dirs =
|
2003-07-17 01:38:28 -07:00
|
|
|
if !Clflags.use_threads then "+threads" :: !Clflags.include_dirs
|
|
|
|
else if !Clflags.use_vmthreads then "+vmthreads" :: !Clflags.include_dirs
|
2000-11-07 06:41:12 -08:00
|
|
|
else !Clflags.include_dirs in
|
|
|
|
let exp_dirs =
|
2000-12-27 21:02:43 -08:00
|
|
|
List.map (expand_directory Config.standard_library) dirs in
|
2002-02-14 07:17:11 -08:00
|
|
|
load_path := "" :: List.rev_append exp_dirs (Clflags.std_include_dir ());
|
1995-05-04 03:15:53 -07:00
|
|
|
Env.reset_cache()
|
|
|
|
|
|
|
|
(* Return the initial environment in which compilation proceeds. *)
|
|
|
|
|
2003-07-25 05:17:19 -07:00
|
|
|
(* Note: do not do init_path() in initial_env, this breaks
|
|
|
|
toplevel initialization (PR#1775) *)
|
1995-05-04 03:15:53 -07:00
|
|
|
let initial_env () =
|
2003-05-12 02:34:05 -07:00
|
|
|
Ident.reinit();
|
1995-05-04 03:15:53 -07:00
|
|
|
try
|
|
|
|
if !Clflags.nopervasives
|
|
|
|
then Env.initial
|
|
|
|
else Env.open_pers_signature "Pervasives" Env.initial
|
|
|
|
with Not_found ->
|
1998-10-01 05:32:46 -07:00
|
|
|
fatal_error "cannot open pervasives.cmi"
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-25 09:06:43 -07:00
|
|
|
(* Compile a .mli file *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let interface ppf sourcefile =
|
2003-07-25 05:17:19 -07:00
|
|
|
init_path();
|
2002-01-28 09:25:26 -08:00
|
|
|
let prefixname = chop_extension_if_any sourcefile in
|
1996-10-31 08:03:27 -08:00
|
|
|
let modulename = String.capitalize(Filename.basename prefixname) in
|
2002-02-08 02:14:31 -08:00
|
|
|
let inputfile = Pparse.preprocess sourcefile in
|
2001-09-22 05:17:33 -07:00
|
|
|
try
|
2002-02-08 02:14:31 -08:00
|
|
|
let ast =
|
|
|
|
Pparse.file ppf inputfile Parse.interface ast_intf_magic_number in
|
2001-09-22 05:17:33 -07:00
|
|
|
if !Clflags.dump_parsetree then fprintf ppf "%a@." Printast.interface ast;
|
|
|
|
let sg = Typemod.transl_signature (initial_env()) ast in
|
2002-03-12 04:35:10 -08:00
|
|
|
if !Clflags.print_types then
|
|
|
|
fprintf std_formatter "%a@." Printtyp.signature
|
|
|
|
(Typemod.simplify_signature sg);
|
2001-09-22 05:17:33 -07:00
|
|
|
Warnings.check_fatal ();
|
2003-06-23 06:22:09 -07:00
|
|
|
if not !Clflags.print_types then
|
|
|
|
Env.save_signature sg modulename (prefixname ^ ".cmi");
|
2002-02-08 02:14:31 -08:00
|
|
|
Pparse.remove_preprocessed inputfile
|
2001-09-22 05:17:33 -07:00
|
|
|
with e ->
|
2002-02-08 02:14:31 -08:00
|
|
|
Pparse.remove_preprocessed_if_ast inputfile;
|
2001-09-22 05:17:33 -07:00
|
|
|
raise e
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1995-07-02 09:45:41 -07:00
|
|
|
(* Compile a .ml file *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let print_if ppf flag printer arg =
|
|
|
|
if !flag then fprintf ppf "%a@." printer arg;
|
1995-05-04 03:15:53 -07:00
|
|
|
arg
|
|
|
|
|
1998-04-27 08:16:48 -07:00
|
|
|
let (++) x f = f x
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let implementation ppf sourcefile =
|
2003-07-25 05:17:19 -07:00
|
|
|
init_path();
|
2002-01-28 09:25:26 -08:00
|
|
|
let prefixname = chop_extension_if_any sourcefile in
|
1996-10-31 08:03:27 -08:00
|
|
|
let modulename = String.capitalize(Filename.basename prefixname) in
|
2002-02-08 02:14:31 -08:00
|
|
|
let inputfile = Pparse.preprocess sourcefile in
|
1998-04-27 08:16:48 -07:00
|
|
|
let env = initial_env() in
|
2003-06-23 06:22:09 -07:00
|
|
|
if !Clflags.print_types then begin
|
|
|
|
try ignore(
|
|
|
|
Pparse.file ppf inputfile Parse.implementation ast_impl_magic_number
|
|
|
|
++ print_if ppf Clflags.dump_parsetree Printast.implementation
|
|
|
|
++ Typemod.type_implementation sourcefile prefixname modulename env)
|
|
|
|
with x ->
|
|
|
|
Pparse.remove_preprocessed_if_ast inputfile;
|
|
|
|
raise x
|
|
|
|
end else begin
|
|
|
|
let objfile = prefixname ^ ".cmo" in
|
|
|
|
let oc = open_out_bin objfile in
|
|
|
|
try
|
|
|
|
Pparse.file ppf inputfile Parse.implementation ast_impl_magic_number
|
|
|
|
++ print_if ppf Clflags.dump_parsetree Printast.implementation
|
|
|
|
++ Typemod.type_implementation sourcefile prefixname modulename env
|
|
|
|
++ Translmod.transl_implementation modulename
|
|
|
|
++ print_if ppf Clflags.dump_rawlambda Printlambda.lambda
|
|
|
|
++ Simplif.simplify_lambda
|
|
|
|
++ print_if ppf Clflags.dump_lambda Printlambda.lambda
|
|
|
|
++ Bytegen.compile_implementation modulename
|
|
|
|
++ print_if ppf Clflags.dump_instr Printinstr.instrlist
|
|
|
|
++ Emitcode.to_file oc modulename;
|
|
|
|
Warnings.check_fatal ();
|
|
|
|
Pparse.remove_preprocessed inputfile;
|
|
|
|
close_out oc;
|
|
|
|
with x ->
|
|
|
|
close_out oc;
|
|
|
|
remove_file objfile;
|
|
|
|
Pparse.remove_preprocessed_if_ast inputfile;
|
|
|
|
raise x
|
|
|
|
end
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let c_file name =
|
1998-11-06 07:39:43 -08:00
|
|
|
if Ccomp.compile_file name <> 0 then exit 2
|