From: Kim Nguyễn Date: Sun, 21 Oct 2012 07:43:52 +0000 (+0200) Subject: Split the Options module in two to remove a circular dependency in X-Git-Url: http://git.nguyen.vg/gitweb/?p=SXSI%2Fxpathcomp.git;a=commitdiff_plain;h=798507d52a5c11a6d852740056464241538fe76a Split the Options module in two to remove a circular dependency in the pretty-printing module: Options depends on Logger to have the list of all logs levels Logger depends on Options to check whether we are in verbose mode or not. Split: Config options holds the references storing the options Options only handles the parsing of the command line --- diff --git a/include/utils.ml b/include/utils.ml index 4a844f4..e61ee19 100644 --- a/include/utils.ml +++ b/include/utils.ml @@ -103,7 +103,7 @@ let stop_perf () = Unix.kill !pid Sys.sigint let time f ?(count=1) ?(msg="") x = - if not !Options.verbose then f x + if not !Config.verbose then f x else let rec loop i = Gc.compact(); diff --git a/src/config.ml b/src/config.ml new file mode 100644 index 0000000..67ec6d4 --- /dev/null +++ b/src/config.ml @@ -0,0 +1,21 @@ +let index_empty_texts = ref true +let sample_factor = ref 64 +let disable_text_collection = ref false +let tc_threshold = ref 60000 + +let query = ref "" +let input_file = ref "" +let output_file : string option ref = ref None +let save_file = ref "" +let count_only = ref false +let time = ref false +let bottom_up = ref false +let no_jump = ref false +let no_cache = ref false +let verbose = ref false +let text_index_type = ref 0 +let do_perf = ref false +let twopass = ref false +let repeat = ref 1 +let docstats = ref false +let no_wrap_results = ref false diff --git a/src/l2JIT.ml b/src/l2JIT.ml index 8e623e0..c3f212e 100644 --- a/src/l2JIT.ml +++ b/src/l2JIT.ml @@ -219,7 +219,7 @@ let memo = Memo.create 1024 let init () = Memo.clear memo let compute_jump auto tree tag states dir = - if !Options.no_jump then + if !Config.no_jump then if dir == DIR_LEFT then FIRST_CHILD states else NEXT_SIBLING states else @@ -267,7 +267,7 @@ let compile cache2 auto tree tag states = | BOTH(tr, NOP _, r) -> RIGHT (tr, r) | _ -> op in - if not !Options.no_cache then add cache2 tag states op; + if not !Config.no_cache then add cache2 tag states op; op let get_transitions = function diff --git a/src/main.ml b/src/main.ml index 2030452..af00682 100644 --- a/src/main.ml +++ b/src/main.ml @@ -21,19 +21,19 @@ let tuned_gc = { default_gc with let mk_runtime run auto doc arg count print outfile = fun () -> - if !Options.do_perf then start_perf (); - let r = time ~count:!Options.repeat ~msg:"Execution time" (run auto doc) arg in - if !Options.do_perf then stop_perf (); + if !Config.do_perf then start_perf (); + let r = time ~count:!Config.repeat ~msg:"Execution time" (run auto doc) arg in + if !Config.do_perf then stop_perf (); Logger.verbose Format.err_formatter "Number of results: %i@\n" (count r); match outfile with None -> () | Some file -> - time ~count:1 ~msg:"Serialization time" (print file !Options.no_wrap_results doc) r + time ~count:1 ~msg:"Serialization time" (print file !Config.no_wrap_results doc) r ;; let main v query_string output = Tag.init (Tree.tag_operations v); - if !Options.docstats then Tree.stats v; + if !Config.docstats then Tree.stats v; let query = time ~msg:"Parsing query" XPath.parse query_string in @@ -42,39 +42,39 @@ let main v query_string output = let auto, bu_info = time ~msg:"Compiling query" Compile.compile query in - if !Options.verbose then Ata.print Format.err_formatter auto; + if !Config.verbose then Ata.print Format.err_formatter auto; Gc.full_major(); Gc.compact(); Gc.set (tuned_gc); let runtime = - match !Options.bottom_up, bu_info with + match !Config.bottom_up, bu_info with | true, Some [ (query, pattern) ] -> - if !Options.count_only then + if !Config.count_only then let module R = ResJIT.Count in let module M = Runtime.Make(R) in - mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Options.output_file + mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Config.output_file else let module R = ResJIT.Mat in let module M = Runtime.Make(R) in - mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Options.output_file + mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Config.output_file | _ -> (* run the query top_down *) - if !Options.bottom_up then + if !Config.bottom_up then Logger.verbose Format.err_formatter "Cannot run the query in bottom-up mode, using top-down evaluator@\n@?"; - if !Options.count_only then + if !Config.count_only then let module R = ResJIT.Count in let module M = Runtime.Make(R) in - if !Options.twopass then + if !Config.twopass then mk_runtime M.twopass_top_down_run auto v Tree.root R.NS.length R.NS.serialize None else - mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Options.output_file + mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Config.output_file else let module R = ResJIT.Mat in let module M = Runtime.Make(R) in - mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Options.output_file + mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Config.output_file in runtime () ;; @@ -85,32 +85,32 @@ let _ = try Printexc.record_backtrace true; let document = - if Filename.check_suffix !Options.input_file ".srx" + if Filename.check_suffix !Config.input_file ".srx" then time ~msg:"Loading file" (Tree.load - ~sample:!Options.sample_factor - ~load_text:(not !Options.disable_text_collection)) - !Options.input_file + ~sample:!Config.sample_factor + ~load_text:(not !Config.disable_text_collection)) + !Config.input_file else let v = time ~msg:"Parsing document" (Tree.parse_xml_uri) - !Options.input_file + !Config.input_file in let () = - if !Options.save_file <> "" + if !Config.save_file <> "" then time ~msg:"Writing file to disk" (Tree.save v) - !Options.save_file; + !Config.save_file; in v in - main document !Options.query !Options.output_file; + main document !Config.query !Config.output_file; Logger.verbose Format.err_formatter "Maximum resident set size: %s @\n" (read_procmem()); Gc.full_major(); Profile.summary Format.err_formatter diff --git a/src/options.ml b/src/options.ml index 4a7a0c7..babad16 100644 --- a/src/options.ml +++ b/src/options.ml @@ -1,27 +1,6 @@ open Utils open Format - -let index_empty_texts = ref true -let sample_factor = ref 64 -let disable_text_collection = ref false -let tc_threshold = ref 60000 - -let query = ref "" -let input_file = ref "" -let output_file = ref None -let save_file = ref "" -let count_only = ref false -let time = ref false -let bottom_up = ref false -let no_jump = ref false -let no_cache = ref false -let verbose = ref false -let text_index_type = ref 0 -let do_perf = ref false -let twopass = ref false -let repeat = ref 1 -let docstats = ref false -let no_wrap_results = ref false +open Config let set_index_type = function | "default" -> text_index_type := 0 diff --git a/src/options.mli b/src/options.mli index 4626e57..bf18180 100644 --- a/src/options.mli +++ b/src/options.mli @@ -1,21 +1 @@ val parse_cmdline : unit -> unit -val index_empty_texts : bool ref -val sample_factor : int ref -val disable_text_collection : bool ref -val count_only : bool ref -val query : string ref -val input_file : string ref -val output_file : string option ref -val save_file : string ref -val time : bool ref -val tc_threshold : int ref -val bottom_up : bool ref -val no_jump : bool ref -val no_cache : bool ref -val verbose : bool ref -val text_index_type : int ref -val do_perf : bool ref -val twopass : bool ref -val repeat : int ref -val docstats : bool ref -val no_wrap_results : bool ref diff --git a/src/runtime.ml b/src/runtime.ml index 0ba08a2..7d1e79f 100644 --- a/src/runtime.ml +++ b/src/runtime.ml @@ -76,7 +76,7 @@ module Make (U : ResJIT.S) : S with type result_set = U.NS.t = Logger.print err_formatter "@?L3JIT: %i used entries@\n@?" !count let create () = let v = Cache.Lvl3.create 1024 dummy in - if !Options.verbose then at_exit (fun () -> show_stats v); + if !Config.verbose then at_exit (fun () -> show_stats v); v let find t tlist s1 s2 = @@ -151,7 +151,7 @@ module Make (U : ResJIT.S) : S with type result_set = U.NS.t = let f = gen_code auto tlist s1 s2 in LOG(__ "top-down-run" 2 "Inserting: %i, %a, %a\n%!" (Uid.to_int tlist.Translist.Node.id) StateSet.print s1 StateSet.print s2); - if not !Options.no_cache then add cache tlist s1 s2 f; + if not !Config.no_cache then add cache tlist s1 s2 f; f end diff --git a/src/tree.ml b/src/tree.ml index 84de829..0c62ec7 100644 --- a/src/tree.ml +++ b/src/tree.ml @@ -81,7 +81,7 @@ struct let do_text b t = if Buffer.length t > 0 then begin let s = Buffer.contents t in - if (!Options.index_empty_texts) || not (is_whitespace s) then + if (!Config.index_empty_texts) || not (is_whitespace s) then begin open_tag b "<$>"; text b s; @@ -133,7 +133,7 @@ struct Expat.set_end_element_handler parser_ (end_element_handler parser_ build buf); Expat.set_character_data_handler parser_ (character_data_handler parser_ build buf); LOG ( __ "parsing" 2 "%s\n" "Started parsing"); - open_document build !Options.sample_factor !Options.disable_text_collection !Options.text_index_type; + open_document build !Config.sample_factor !Config.disable_text_collection !Config.text_index_type; open_tag build ""; parser_, finalize