1 (***********************************************************************)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
7 (* Copyright 2002 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
11 (***********************************************************************)
15 (* The batch compiler *)
22 (* Initialize the search path.
23 The current directory is always searched first,
24 then the directories specified with the -I option (in command-line order),
25 then the standard library directory. *)
29 if !Clflags.use_threads
30 then "+threads" :: !Clflags.include_dirs
31 else !Clflags.include_dirs
in
33 List.map
(expand_directory
Config.standard_library
) dirs in
34 load_path
:= "" :: List.rev_append
exp_dirs (Clflags.std_include_dir
());
37 (* Return the initial environment in which compilation proceeds. *)
42 if !Clflags.nopervasives
44 else Env.open_pers_signature
"Pervasives" Env.initial
46 fatal_error
"cannot open Pervasives.cmi"
48 (* Compile a .mli file *)
50 let interface ppf sourcefile outputprefix
=
53 String.capitalize
(Filename.basename
(chop_extension_if_any sourcefile
)) in
54 Env.set_unit_name
modulename;
55 let inputfile = Pparse.preprocess sourcefile
in
58 Pparse.file ppf
inputfile Parse.interface ast_intf_magic_number
in
59 if !Clflags.dump_parsetree
then fprintf ppf
"%a@." Printast.interface ast;
60 let sg = Typemod.transl_signature
(initial_env()) ast in
61 if !Clflags.print_types
then
62 fprintf std_formatter
"%a@." Printtyp.signature
63 (Typemod.simplify_signature
sg);
64 Warnings.check_fatal
();
65 if not
!Clflags.print_types
then
66 Env.save_signature
sg modulename (outputprefix ^
".cmi");
67 Pparse.remove_preprocessed
inputfile
69 Pparse.remove_preprocessed_if_ast
inputfile;
72 (* Compile a .ml file *)
74 let print_if ppf flag printer arg
=
75 if !flag
then fprintf ppf
"%a@." printer arg
;
79 let (+++) (x
, y
) f
= (x
, f y
)
81 let implementation ppf sourcefile outputprefix
=
84 String.capitalize
(Filename.basename
(chop_extension_if_any sourcefile
)) in
85 Env.set_unit_name
modulename;
86 let inputfile = Pparse.preprocess sourcefile
in
87 let env = initial_env() in
88 Compilenv.reset ?packname
:!Clflags.for_package
modulename;
90 if !Clflags.print_types
then ignore
(
91 Pparse.file ppf
inputfile Parse.implementation ast_impl_magic_number
92 ++ print_if ppf
Clflags.dump_parsetree
Printast.implementation
93 ++ Unused_var.warn ppf
94 ++ Typemod.type_implementation sourcefile outputprefix
modulename env)
96 Pparse.file ppf
inputfile Parse.implementation ast_impl_magic_number
97 ++ print_if ppf
Clflags.dump_parsetree
Printast.implementation
98 ++ Unused_var.warn ppf
99 ++ Typemod.type_implementation sourcefile outputprefix
modulename env
100 ++ Translmod.transl_store_implementation
modulename
101 +++ print_if ppf
Clflags.dump_rawlambda
Printlambda.lambda
102 +++ Simplif.simplify_lambda
103 +++ print_if ppf
Clflags.dump_lambda
Printlambda.lambda
104 ++ Asmgen.compile_implementation outputprefix ppf
;
105 Compilenv.save_unit_info
(outputprefix ^
".cmx");
107 Warnings.check_fatal
();
108 Pparse.remove_preprocessed
inputfile
110 Pparse.remove_preprocessed_if_ast
inputfile;
114 if Ccomp.compile_file name
<> 0 then exit
2