1 (******************************************************************************)
2 (* SXSI : XPath evaluator *)
3 (* Kim Nguyen (Kim.Nguyen@nicta.com.au) *)
4 (* Copyright NICTA 2008 *)
5 (* Distributed under the terms of the LGPL (see LICENCE) *)
6 (******************************************************************************)
11 let () = init_timer();;
14 let default_gc = Gc.get()
15 let tuned_gc = { default_gc with
16 Gc.minor_heap_size = 32*1024*1024;
17 Gc.major_heap_increment = 8*1024*1024;
18 Gc.max_overhead = 1000000;
19 Gc.space_overhead = 100;
22 let mk_runtime run auto doc arg count print outfile =
24 if !Options.do_perf then start_perf ();
25 let r = time ~count:!Options.repeat ~msg:"Execution time" (run auto doc) arg in
26 if !Options.do_perf then stop_perf ();
27 Logger.print Format.err_formatter "Number of results: %i@\n" (count r);
31 time ~count:1 ~msg:"Serialization time" (print file doc) r
34 let main v query_string output =
35 Tag.init (Tree.tag_operations v);
37 time ~msg:"Parsing query" XPath.parse query_string
39 if !Options.verbose then begin
40 Logger.print Format.err_formatter "Parsed query:@\n%a@\n"
41 XPath.Ast.print query;
44 time ~msg:"Compiling query" Compile.compile query
46 if !Options.verbose then Ata.print Format.err_formatter auto;
51 match !Options.bottom_up, bu_info with
53 | true, Some [ (query, pattern) ] ->
54 if !Options.count_only then
55 let module R = ResJIT.Count in
56 let module M = Runtime.Make(R) in
57 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize None
59 let module R = ResJIT.Mat in
60 let module M = Runtime.Make(R) in
61 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Options.output_file
64 (* run the query top_down *)
66 if !Options.bottom_up then
67 Logger.print Format.err_formatter "Cannot run the query in bottom-up mode, using top-down evaluator@\n@?";
68 if !Options.count_only then
69 let module R = ResJIT.Count in
70 let module M = Runtime.Make(R) in
71 if !Options.twopass then
72 mk_runtime M.twopass_top_down_run auto v Tree.root R.NS.length R.NS.serialize None
74 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize None
76 let module R = ResJIT.Mat in
77 let module M = Runtime.Make(R) in
78 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Options.output_file
83 let () = Options.parse_cmdline()
87 Printexc.record_backtrace true;
90 if Filename.check_suffix !Options.input_file ".g.bin" ||
91 Filename.check_suffix !Options.input_file ".g"
93 let is_index = Filename.check_suffix !Options.input_file ".g.bin" in
96 time ~msg:"Loading grammar" (Grammar2.load) !Options.input_file
98 let g = time ~msg:"Parsing grammar file" Grammar2.parse !Options.input_file in
99 if !Options.save_file <> "" then
100 time ~msg:"Saving index" (Grammar2.save g) !Options.save_file;
104 (* TODO Factorise with main *)
105 Tag.init (Grammar2.tag_operations g);
107 time ~msg:"Parsing query" XPath.parse !Options.query
109 if !Options.verbose then begin
110 Printf.eprintf "Parsed query:\n%!";
111 XPath.Ast.print Format.err_formatter query;
112 Format.fprintf Format.err_formatter "\n%!"
115 time ~msg:"Compiling query" (Compile.compile) query
117 if !Options.verbose then Ata.print Format.err_formatter auto;
122 if !Options.count_only then
123 let module R = ResJIT.Make(NodeSet.Partial(NodeSet.Count)) in
124 let module M = Runtime.Make(R) in
125 (* mk_runtime run auto doc arg count print outfile *)
126 mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None
128 let module R = ResJIT.Mat in
129 let module M = Runtime.Make(R) in
130 (* mk_runtime run auto doc arg count print outfile *)
131 mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None
136 else if Filename.check_suffix !Options.input_file ".srx"
141 ~sample:!Options.sample_factor
142 ~load_text:(not !Options.disable_text_collection))
147 ~msg:"Parsing document"
152 if !Options.save_file <> ""
155 ~msg:"Writing file to disk"
161 main document !Options.query !Options.output_file;
162 if !Options.verbose then
163 Logger.print Format.err_formatter "Maximum resident set size: %s @\n" (read_procmem());
165 Profile.summary Format.err_formatter
167 | Ulexer.Loc.Exc_located ((x,y),e) ->
168 Logger.print Format.err_formatter "character %i-%i %s@\n" x y (Printexc.to_string e);
172 Logger.print Format.err_formatter "BACKTRACE: %s@\n@?" (Printexc.get_backtrace());
173 Logger.print Format.err_formatter "FATAL ERROR: %s@\n@?" (Printexc.to_string e);