Add grammar loading and indexing.
[SXSI/xpathcomp.git] / src / main.ml
index cb7585f..bfbdff9 100644 (file)
@@ -13,10 +13,10 @@ 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.max_overhead = 1000000;
-                  Gc.space_overhead = 100;
+  Gc.minor_heap_size = 32*1024*1024;
+  Gc.major_heap_increment = 8*1024*1024; 
+  Gc.max_overhead = 1000000;
+  Gc.space_overhead = 100;
               }
 
 let mk_runtime run auto doc arg count print outfile =
@@ -91,11 +91,40 @@ let () = Options.parse_cmdline()
 ;;
 
 let document =
-  if Filename.check_suffix !Options.input_file ".g.bin" then
+  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
-      ignore(g);
-      Unix.sleep 10; (* Leave monitoring process the time to read the HWM *)
+      (* 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
+       (* 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"