X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2FresJIT.ml;fp=src%2FresJIT.ml;h=64c96246116946d6f786b81bbed58b43e3a63e3b;hb=d8e8a2b5c08a980a440d9fc9f3ea27af7711b524;hp=df08d9c3b2daaaefbf371ae9720d4b0ca2a19849;hpb=a3cacfe74ac30fee5fe3afd6b7fa98dea774aad6;p=SXSI%2Fxpathcomp.git diff --git a/src/resJIT.ml b/src/resJIT.ml index df08d9c..64c9624 100644 --- a/src/resJIT.ml +++ b/src/resJIT.ml @@ -197,6 +197,12 @@ let () = at_exit (fun () -> Printf.eprintf "Dummy affectations %i/%i\n%!" !_empt DEFINE SET(a, b) = (a) <- (b) +DEFINE PRINT_TEMPLATE(ns) = + let pr fmt (state, count) = + fprintf fmt "%a: %i" State.print state (ns.length count) + in + Pretty.print_array ~sep:", " pr fmt (Array.mapi (fun x y -> (x,y)) s) + DEFINE EXEC_INSTR_TEMPLATE(ns) = fun slot1 slot2 t inst acc -> match inst with | SELF _ -> ns.snoc acc t @@ -265,6 +271,34 @@ DEFINE EXEC_CODE_TEMPLATE(ns) = fun slot slot1 slot2 t dst code -> slot.(dst) <- !acc +DEFINE EXEC_REC_TEMPLATE = + (match code with + | Nil -> () + | Cons(dst, opcode, code1) -> + TRACE("res-jit", 3, __ " %a := %a\n%!" + State.print dst print_opcode opcode; + ); + exec_code slot slot1 slot2 t dst opcode; + begin + match code1 with + | Nil -> () + | Cons(dst, opcode, code1) -> + TRACE("res-jit", 3, __ " %a := %a\n%!" + State.print dst print_opcode opcode; + ); + exec_code slot slot1 slot2 t dst opcode; + exec slot slot1 slot2 t code1 + + end) + +DEFINE EXEC_TEMPLATE = + (TRACE("res-jit", 3, __ "Node %i:\n" (Node.to_int t)); + TRACE("res-jit", 3, __ " LEFT : %a\n" pr_slot slot1); + TRACE("res-jit", 3, __ " RIGHT : %a\n" pr_slot slot2); + exec slot slot1 slot2 t code; + TRACE("res-jit", 3, __ " RES : %a\n\n%!" pr_slot slot)) + + module type S = sig module NS : NodeSet.S @@ -276,51 +310,17 @@ module type S = val is_open : t -> bool end - - module Count = struct module NS = NodeSet.Count type t = NodeSet.Count.t array - let print fmt s = - let pr fmt (state, count) = - fprintf fmt "%a: %i" State.print state (NS.length count) - in - Pretty.print_array ~sep:", " pr fmt (Array.mapi (fun x y -> (x,y)) s) - + let print fmt s = PRINT_TEMPLATE(NS) let exec_instr = EXEC_INSTR_TEMPLATE(NodeSet.Count) let exec_code = EXEC_CODE_TEMPLATE(NodeSet.Count) - (* inline by hand for efficiency reason *) - let rec exec slot slot1 slot2 t code = - match code with - | Nil -> () - | Cons(dst, opcode, code1) -> - TRACE("res-jit", 3, __ " %a := %a\n%!" - State.print dst print_opcode opcode; - ); - exec_code slot slot1 slot2 t dst opcode; - begin - match code1 with - | Nil -> () - | Cons(dst, opcode, code1) -> - TRACE("res-jit", 3, __ " %a := %a\n%!" - State.print dst print_opcode opcode; - ); - exec_code slot slot1 slot2 t dst opcode; - exec slot slot1 slot2 t code1 - end - - let exec slot slot1 slot2 t code = - TRACE("res-jit", 3, __ "Node %i:\n" (Node.to_int t)); - TRACE("res-jit", 3, __ " LEFT : %a\n" pr_slot slot1); - TRACE("res-jit", 3, __ " RIGHT : %a\n" pr_slot slot2); - exec slot slot1 slot2 t code; - TRACE("res-jit", 3, __ " RES : %a\n\n%!" pr_slot slot) - - + let rec exec slot slot1 slot2 t code = EXEC_REC_TEMPLATE + let exec slot slot1 slot2 t code = EXEC_TEMPLATE let var _ x = x let close _ x = x - let is_open _ = false end @@ -328,28 +328,11 @@ module Mat = struct module NS = NodeSet.Mat type t = NodeSet.Mat.t array - let print fmt s = - let pr fmt (state, count) = - fprintf fmt "%a: %i" State.print state (NS.length count) - in - Pretty.print_array ~sep:", " pr fmt (Array.mapi (fun x y -> (x,y)) s) - + let print fmt s = PRINT_TEMPLATE(NS) let exec_instr = EXEC_INSTR_TEMPLATE(NodeSet.Mat) let exec_code = EXEC_CODE_TEMPLATE(NodeSet.Mat) - (* inline by hand for efficiency reason *) - let rec exec slot slot1 slot2 t code = - match code with - | Nil -> () - | Cons(dst, code, code1) -> - exec_code slot slot1 slot2 t dst code; - begin - match code1 with - | Nil -> () - | Cons(dst', code', code1') -> - exec_code slot slot1 slot2 t dst' code'; - exec slot slot1 slot2 t code1' - end - + let rec exec slot slot1 slot2 t code = EXEC_REC_TEMPLATE + let exec slot slot1 slot2 t code = EXEC_TEMPLATE let var _ x = x let close _ x = x let is_open _ = false @@ -361,42 +344,11 @@ module Make(U : NodeSet.S) = struct module NS = U type t = U.t array - let print fmt s = - let pr fmt (state, count) = - fprintf fmt "%a: %i" State.print state (NS.length count) - in - Pretty.print_array ~sep:", " pr fmt (Array.mapi (fun x y -> (x,y)) s) - + let print fmt s = PRINT_TEMPLATE(NS) let exec_instr = EXEC_INSTR_TEMPLATE(U) let exec_code = EXEC_CODE_TEMPLATE(U) - (* inline by hand for efficiency reason *) - let rec exec slot slot1 slot2 t code = - match code with - | Nil -> () - | Cons(dst, opcode, code1) -> - TRACE("res-jit", 3, __ " %a := %a\n%!" - State.print dst print_opcode opcode; - ); - exec_code slot slot1 slot2 t dst opcode; - begin - match code1 with - | Nil -> () - | Cons(dst, opcode, code1) -> - TRACE("res-jit", 3, __ " %a := %a\n%!" - State.print dst print_opcode opcode; - ); - exec_code slot slot1 slot2 t dst opcode; - exec slot slot1 slot2 t code1 - end - - let exec slot slot1 slot2 t code = - TRACE("res-jit", 3, __ "Node %i:\n" (Node.to_int t)); - TRACE("res-jit", 3, __ " LEFT : %a\n" pr_slot slot1); - TRACE("res-jit", 3, __ " RIGHT : %a\n" pr_slot slot2); - exec slot slot1 slot2 t code; - TRACE("res-jit", 3, __ " RES : %a\n\n%!" pr_slot slot) - - + let rec exec slot slot1 slot2 t code = EXEC_REC_TEMPLATE + let exec slot slot1 slot2 t code = EXEC_TEMPLATE let var i t = Array.mapi (fun j _ -> NS.var (i,j)) t let close h t =