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
|
|
|
|
|
|
|
|
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
|
1998-04-14 07:48:34 -07:00
|
|
|
let pos_trailer = in_channel_length ic - 36 in
|
1995-05-04 03:15:53 -07:00
|
|
|
seek_in ic pos_trailer;
|
1998-04-14 07:48:34 -07:00
|
|
|
let path_size = input_binary_int ic in
|
1995-05-04 03:15:53 -07:00
|
|
|
let code_size = input_binary_int ic in
|
1997-06-15 04:57:23 -07:00
|
|
|
let prim_size = input_binary_int ic in
|
1995-05-04 03:15:53 -07:00
|
|
|
let data_size = input_binary_int ic in
|
|
|
|
let symbol_size = input_binary_int ic in
|
|
|
|
let debug_size = input_binary_int ic in
|
|
|
|
let header = String.create(String.length Config.exec_magic_number) in
|
|
|
|
really_input ic header 0 (String.length Config.exec_magic_number);
|
|
|
|
if header <> Config.exec_magic_number then begin
|
1995-05-04 05:48:07 -07:00
|
|
|
prerr_endline "Wrong magic number"; exit 2
|
1995-05-04 03:15:53 -07:00
|
|
|
end;
|
1996-11-25 07:55:16 -08:00
|
|
|
if Sys.os_type = "MacOS" then begin
|
|
|
|
(* Create it as a text file for bytecode scripts *)
|
|
|
|
let c = open_out_gen [Open_wronly; Open_creat] 0o777 output_name in
|
|
|
|
close_out c
|
|
|
|
end;
|
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;
|
|
|
|
copy_file_chunk ic oc (pos_trailer - symbol_size - debug_size);
|
|
|
|
(* Read, expunge and rewrite the symbol section *)
|
|
|
|
let global_map = (input_value ic : Symtable.global_map) in
|
|
|
|
let pos1 = pos_out oc in
|
1995-08-09 06:17:15 -07:00
|
|
|
output_value oc (expunge_map global_map);
|
1995-05-04 03:15:53 -07:00
|
|
|
let pos2 = pos_out oc in
|
|
|
|
(* Rewrite the trailer *)
|
1998-04-14 07:48:34 -07:00
|
|
|
output_binary_int oc path_size;
|
1995-05-04 03:15:53 -07:00
|
|
|
output_binary_int oc code_size;
|
1997-06-15 04:57:23 -07:00
|
|
|
output_binary_int oc prim_size;
|
1995-05-04 03:15:53 -07:00
|
|
|
output_binary_int oc data_size;
|
|
|
|
output_binary_int oc (pos2 - pos1);
|
|
|
|
output_binary_int oc 0;
|
|
|
|
output_string oc Config.exec_magic_number;
|
|
|
|
(* Done *)
|
|
|
|
close_in ic;
|
|
|
|
close_out oc
|
|
|
|
|
|
|
|
let _ = Printexc.catch main (); exit 0
|