(* Oukseh Lee Copyright(c) 2000-2004 KAIST/SNU Research On Program Analysis System (National Creative Research Initiative Center 1998-2003) http://ropas.snu.ac.kr/n All rights reserved. This file is distributed under the terms of an Open Source License. *) structure Dump = struct open NEnv type header = { dstrs: string list, dfcts: string list, dsigs: string list, toptid: int, version: string } type dump = { header: header, body : F.m * G.m * se, constructors: Ty.CE.t } val version = "0.91" val dumpext = ".nty" exception Invalid_header fun dump_it ch x = Marshal.to_channel ch x [] fun dump_all ch {header = x, body = y, constructors = z} = (dump_it ch x; dump_it ch y; dump_it ch z) fun load_header ch = let val h = Marshal.from_channel ch in if h.version = version then h else raise Invalid_header end fun load_it ch = Marshal.from_channel ch fun load_all ch = let val h = load_header ch val b = load_it ch val c = load_it ch in {header = h, body = b, constructors = c} end fun makename nfile = (Filename.chop_extension nfile)^dumpext fun make_header (f,g,s) = let val s' = let val l=ref[] in SE.iter (fn k _ => l := k::(!l)) s; !l end val f' = let val l=ref[] in F.M.iter (fn k _ => l := k::(!l)) f; !l end val g' = let val l=ref[] in G.M.iter (fn k _ => l := k::(!l)) g; !l end in (* Format.printf "Dump %d strs," (List.length s'); Format.printf "%d fcts," (List.length f'); Format.printf "%d sigs.@." (List.length g'); *) {dstrs = s', dfcts = f', dsigs = g', toptid = Ty.Tn.current(), version = version} end fun dump nfile = let val oc = open_out_bin (makename nfile) val e = stabilize_file () val b' = (get_f(), get_g(), E.se e) in dump_all oc {header = make_header b', body = b', constructors = !Ty.CE.m}; close_out oc end fun load tfile = let val ic = open_in_bin tfile val l = (load_all ic) handle x => (close_in ic; raise x) in (* if !Ty.Tn.count < l.header.toptid then Ty.Tn.count := l.header.toptid; *) close_in ic; (l.body, l.constructors) end end