-(** .moo file format
- * - an integer -- magic number -- denoting the version of the dumped data
- * structure. Different magic numbers stand for incompatible data structures
- * - an integer -- checksum -- denoting the hash value (computed with
- * Hashtbl.hash) of the string representation of the dumped data structur
- * - marshalled pair: first component is a list of GrafiteAst.command (real moo
- * content), second component is a list of GrafiteAst.metadata
- *)
+let save_moo_to_file ~fname moo =
+ HMarshal.save ~fmt:format_name ~version:GrafiteAst.magic ~fname moo
+
+let load_moo_from_file ~fname =
+ let raw = HMarshal.load ~fmt:format_name ~version:GrafiteAst.magic ~fname in
+ (raw: moo)
+
+let rehash_cmd_uris =
+ let rehash_uri uri =
+ UriManager.uri_of_string (UriManager.string_of_uri uri) in
+ function
+ | GrafiteAst.Default (loc, name, uris) ->
+ let uris = List.map rehash_uri uris in
+ GrafiteAst.Default (loc, name, uris)
+ | GrafiteAst.Coercion (loc, uri, close) ->
+ GrafiteAst.Coercion (loc, rehash_uri uri, close)
+ | cmd ->
+ prerr_endline "Found a command not expected in a .moo:";
+ let obj_pp _ = assert false in
+ prerr_endline (GrafiteAstPp.pp_command ~obj_pp cmd);
+ assert false