X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fmain.ml;h=42c88221948cf4694cf59d399dc4f7f62c2f380e;hb=3e6b06512ddd85717555d6e3545f712746abfe82;hp=bfbdff93014e50bdc55938e34c98ff469678d67f;hpb=1975eef2d0933da3c01faec1cd14bc8fbf6bf146;p=SXSI%2Fxpathcomp.git diff --git a/src/main.ml b/src/main.ml index bfbdff9..42c8822 100644 --- a/src/main.ml +++ b/src/main.ml @@ -14,7 +14,7 @@ let () = init_timer();; let default_gc = Gc.get() let tuned_gc = { default_gc with Gc.minor_heap_size = 32*1024*1024; - Gc.major_heap_increment = 8*1024*1024; + Gc.major_heap_increment = 8*1024*1024; Gc.max_overhead = 1000000; Gc.space_overhead = 100; } @@ -89,88 +89,98 @@ let main v query_string output = let () = Options.parse_cmdline() ;; +let _ = + try + Printexc.record_backtrace true; -let document = - if Filename.check_suffix !Options.input_file ".g" then - let g = Grammar2.parse !Options.input_file in - let () = Grammar2.save g "/tmp/test.g" in - let g = Grammar2.load "/tmp/test.g" in - ignore g; - exit 3 - - else if Filename.check_suffix !Options.input_file ".g.bin" then - let g = time ~msg:"Loading grammar" (Grammar.load !Options.input_file) true in - begin + let document = + if Filename.check_suffix !Options.input_file ".g.bin" || + Filename.check_suffix !Options.input_file ".g" + then + let is_index = Filename.check_suffix !Options.input_file ".g.bin" in + let g = + if is_index then + time ~msg:"Loading grammar" (Grammar2.load) !Options.input_file + else + let g = time ~msg:"Parsing grammar file" Grammar2.parse !Options.input_file in + if !Options.save_file <> "" then + time ~msg:"Saving index" (Grammar2.save g) !Options.save_file; + g + in + begin (* Todo Factorise with main *) - Tag.init (Grammar.tag_operations g); - let query = - time ~msg:"Parsing query" XPath.parse !Options.query - in - if !Options.verbose then begin - Printf.eprintf "Parsed query:\n%!"; - XPath.Ast.print Format.err_formatter query; - Format.fprintf Format.err_formatter "\n%!" - end; - let auto, bu_info = - time ~msg:"Compiling query" (Compile.compile) query - in - if !Options.verbose then Ata.print Format.err_formatter auto; - Gc.full_major(); - Gc.compact(); - Gc.set (tuned_gc); - let runtime = - let module R = ResJIT.Count in - let module M = Runtime.Make(R) in + Tag.init (Grammar2.tag_operations g); + let query = + time ~msg:"Parsing query" XPath.parse !Options.query + in + if !Options.verbose then begin + Printf.eprintf "Parsed query:\n%!"; + XPath.Ast.print Format.err_formatter query; + Format.fprintf Format.err_formatter "\n%!" + end; + let auto, bu_info = + time ~msg:"Compiling query" (Compile.compile) query + in + if !Options.verbose then Ata.print Format.err_formatter auto; + Gc.full_major(); + Gc.compact(); + Gc.set (tuned_gc); + let runtime = + if !Options.count_only then + let module R = ResJIT.Make(NodeSet.Partial(NodeSet.Count)) in + let module M = Runtime.Make(R) in (* mk_runtime run auto doc arg count print outfile *) - mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None - in - runtime (); - exit 0 - end - else if Filename.check_suffix !Options.input_file ".srx" - then - time - ~msg:"Loading file" - (Tree.load - ~sample:!Options.sample_factor - ~load_text:true) - !Options.input_file - else - let v = - time - ~msg:"Parsing document" - (Tree.parse_xml_uri) - !Options.input_file - in - let () = - if !Options.save_file <> "" + mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None + else + let module R = ResJIT.Mat in + let module M = Runtime.Make(R) in + (* mk_runtime run auto doc arg count print outfile *) + mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None + in + runtime (); + exit 0 + end + else if Filename.check_suffix !Options.input_file ".srx" then time - ~msg:"Writing file to disk" - (Tree.save v) - !Options.save_file; + ~msg:"Loading file" + (Tree.load + ~sample:!Options.sample_factor + ~load_text:true) + !Options.input_file + else + let v = + time + ~msg:"Parsing document" + (Tree.parse_xml_uri) + !Options.input_file + in + let () = + if !Options.save_file <> "" + then + time + ~msg:"Writing file to disk" + (Tree.save v) + !Options.save_file; + in + v in - v -in - try - (*Printexc.record_backtrace true; *) main document !Options.query !Options.output_file; if !Options.verbose then Printf.eprintf "Maximum resident set size: %s\n" (read_procmem()); Gc.full_major(); Profile.summary Format.err_formatter with - | Ulexer.Loc.Exc_located ((x,y),e) -> - Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e); - exit 1 - - | e -> - output_string stderr "\n"; - flush stderr; - Printexc.print_backtrace stderr; - Printf.eprintf "FATAL ERROR: %s\n%!" (Printexc.to_string e); - output_string stderr "\n"; - flush stderr; -(* Ptset.Int.stats(); *) - exit 2 + | Ulexer.Loc.Exc_located ((x,y),e) -> + Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e); + exit 1 + + | e -> + output_string stderr "\n"; + flush stderr; + Printexc.print_backtrace stderr; + Printf.eprintf "FATAL ERROR: %s\n%!" (Printexc.to_string e); + output_string stderr "\n"; + flush stderr; + exit 2