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 *)
|
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
|
|
|
(* "Expunge" a toplevel by removing compiler modules from the global List.map.
|
|
|
|
Usage: expunge <source file> <dest file> <names of modules to keep> *)
|
|
|
|
|
|
|
|
open Sys
|
|
|
|
open Misc
|
|
|
|
|
1995-05-30 06:36:40 -07:00
|
|
|
module StringSet =
|
|
|
|
Set.Make(struct
|
|
|
|
type t = string
|
|
|
|
let compare = compare
|
|
|
|
end)
|
|
|
|
|
|
|
|
let to_keep = ref StringSet.empty
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let expunge_map tbl =
|
|
|
|
Symtable.filter_global_map
|
1995-05-30 06:36:40 -07:00
|
|
|
(fun id -> StringSet.mem (Ident.name id) !to_keep)
|
1995-05-04 03:15:53 -07:00
|
|
|
tbl
|
|
|
|
|
2002-11-17 08:42:12 -08:00
|
|
|
let expunge_crcs tbl =
|
|
|
|
List.filter (fun (unit, crc) -> StringSet.mem unit !to_keep) tbl
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let main () =
|
|
|
|
let input_name = Sys.argv.(1) in
|
|
|
|
let output_name = Sys.argv.(2) in
|
|
|
|
Array.iter
|
1995-05-30 06:36:40 -07:00
|
|
|
(fun exn -> to_keep := StringSet.add exn !to_keep)
|
1995-05-04 03:15:53 -07:00
|
|
|
Runtimedef.builtin_exceptions;
|
|
|
|
for i = 3 to Array.length Sys.argv - 1 do
|
1996-10-31 08:03:27 -08:00
|
|
|
to_keep := StringSet.add (String.capitalize Sys.argv.(i)) !to_keep
|
1995-05-04 03:15:53 -07:00
|
|
|
done;
|
|
|
|
let ic = open_in_bin input_name in
|
2000-03-05 11:18:50 -08:00
|
|
|
Bytesections.read_toc ic;
|
|
|
|
let toc = Bytesections.toc() in
|
|
|
|
let pos_first_section = Bytesections.pos_first_section ic in
|
1995-05-04 03:15:53 -07:00
|
|
|
let oc =
|
1996-11-25 07:55:16 -08:00
|
|
|
open_out_gen [Open_wronly; Open_creat; Open_trunc; Open_binary] 0o777
|
|
|
|
output_name in
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Copy the file up to the symbol section as is *)
|
|
|
|
seek_in ic 0;
|
2000-03-05 11:18:50 -08:00
|
|
|
copy_file_chunk ic oc pos_first_section;
|
|
|
|
(* Copy each section, modifying the symbol section in passing *)
|
|
|
|
Bytesections.init_record oc;
|
|
|
|
List.iter
|
|
|
|
(fun (name, len) ->
|
2002-11-17 08:42:12 -08:00
|
|
|
begin match name with
|
|
|
|
"SYMB" ->
|
|
|
|
let global_map = (input_value ic : Symtable.global_map) in
|
|
|
|
output_value oc (expunge_map global_map)
|
|
|
|
| "CRCS" ->
|
|
|
|
let crcs = (input_value ic : (string * Digest.t) list) in
|
|
|
|
output_value oc (expunge_crcs crcs)
|
|
|
|
| _ ->
|
|
|
|
copy_file_chunk ic oc len
|
2000-03-05 11:18:50 -08:00
|
|
|
end;
|
|
|
|
Bytesections.record oc name)
|
|
|
|
toc;
|
|
|
|
(* Rewrite the toc and trailer *)
|
|
|
|
Bytesections.write_toc_and_trailer oc;
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Done *)
|
|
|
|
close_in ic;
|
|
|
|
close_out oc
|
|
|
|
|
|
|
|
let _ = Printexc.catch main (); exit 0
|