1 (***********************************************************************)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
7 (* Copyright 1996 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 (* "Expunge" a toplevel by removing compiler modules from the global List.map.
16 Usage: expunge <source file> <dest file> <names of modules to keep> *)
27 let to_keep = ref StringSet.empty
30 Symtable.filter_global_map
31 (fun id
-> StringSet.mem
(Ident.name id
) !to_keep)
34 let expunge_crcs tbl
=
35 List.filter
(fun (unit, crc
) -> StringSet.mem
unit !to_keep) tbl
38 let input_name = Sys.argv
.(1) in
39 let output_name = Sys.argv
.(2) in
41 (fun exn
-> to_keep := StringSet.add exn
!to_keep)
42 Runtimedef.builtin_exceptions
;
43 for i
= 3 to Array.length
Sys.argv
- 1 do
44 to_keep := StringSet.add
(String.capitalize
Sys.argv
.(i
)) !to_keep
46 let ic = open_in_bin
input_name in
47 Bytesections.read_toc
ic;
48 let toc = Bytesections.toc() in
49 let pos_first_section = Bytesections.pos_first_section ic in
51 open_out_gen
[Open_wronly
; Open_creat
; Open_trunc
; Open_binary
] 0o777
53 (* Copy the file up to the symbol section as is *)
55 copy_file_chunk
ic oc pos_first_section;
56 (* Copy each section, modifying the symbol section in passing *)
57 Bytesections.init_record
oc;
62 let global_map = (input_value
ic : Symtable.global_map) in
63 output_value
oc (expunge_map global_map)
65 let crcs = (input_value
ic : (string * Digest.t
) list
) in
66 output_value
oc (expunge_crcs crcs)
68 copy_file_chunk
ic oc len
70 Bytesections.record
oc name
)
72 (* Rewrite the toc and trailer *)
73 Bytesections.write_toc_and_trailer
oc;
78 let _ = Printexc.catch
main (); exit
0