4 module M = Map.Make(struct type t = int let compare = compare end)
6 type info = { sat : StateSet.t;
10 let info = Hashtbl.create 2017
11 let final = Hashtbl.create 2017
16 let buff = Buffer.create 20
17 let fmt = formatter_of_buffer buff
20 let trace ?(msg="") nid r t d =
21 if r > !max_round then max_round := r;
22 let m = try Hashtbl.find info nid with Not_found -> M.empty in
23 let () = pp_print_flush fmt () in
25 "node: %i<br/>%s<br/>todo: %a<br/>sat: %a<br/>_______________________<br/>"
26 nid msg StateSet.print t StateSet.print d
28 let () = pp_print_flush fmt () in
29 let msg = Buffer.contents buff in
30 let () = Buffer.clear buff in
31 let old_inf = try M.find r m with Not_found -> [] in
32 let m' = M.add r ({ sat = d; todo = t; msg = msg }::old_inf) m in
33 Hashtbl.replace info nid m'
35 let finalize_node n r b =
36 Hashtbl.replace final n (b,r)
39 type t = StateSet.t list
41 List.fold_left (fun acc set ->
42 HASHINT2(acc, (set.StateSet.id :> int))) 17 l
46 List.for_all2 (==) l1 l2
50 module CTable = Hashtbl.Make (K)
52 let ctable = CTable.create 20
57 and g = (h lsr 8) land 0xff
58 and b = (h lsr 16) land 0xff
68 let s = "rgb(" ^ (string_of_int r) ^ ","
69 ^ (string_of_int g) ^ ","
70 ^ (string_of_int b) ^ ")"
72 CTable.add ctable x s;
77 let av = (r + g + b) / 3 in
78 if av > 128 then "rgb(0,0,0)"
79 else "rgb(255,255,255)"
81 let get_conf sel l i =
82 List.fold_left (fun (accb,accl) a ->
83 accb || StateSet.intersect a.(i) sel,
84 a.(i) :: accl) (false,[]) l
86 let gen_trace (type s) = fun auto sat_arrays t tree ->
87 let module T = (val (t) : Tree.S with type t = s) in
88 let root = T.root tree in
89 let sel = Ata.get_selecting_states auto in
90 let rec loop output node parent prevsib x y =
91 if node != T.nil then begin
92 let node_id = T.preorder tree node in
93 let marked, conf = get_conf sel sat_arrays node_id in
94 let scolor, tcolor = color conf, text_color conf in
95 let tag = QName.to_string (T.tag tree node) in
96 let lbox = (String.length tag + 2) * 10 in
97 let s_node = "node" ^ (string_of_int node_id) in
98 let first = T.first_child tree node in
99 let next = T.next_sibling tree node in
101 "<rect id=\"%s\" onclick=\"activate(\'%s\');\" x=\"%i\" y=\"%i\"\
102 width=\"%i\" height=\"22\" style=\"fill:%s;stroke:rgb(0,0,0)%s\">%!"
109 then ";stroke-width:4"
110 else ";stroke-width:2;stroke-dasharray:2,2");
111 fprintf output "<metadata id='%s_fs'>node%i</metadata><metadata id='%s_ns'>node%i</metadata><metadata id='%s_par'>node%i</metadata><metadata id='%s_ps'>node%i</metadata></rect>\n%!"
112 s_node (T.preorder tree first) s_node (T.preorder tree next)
113 s_node (T.preorder tree parent) s_node (T.preorder tree prevsib)
115 fprintf output "<text x=\"%i\" y=\"%i\" style=\"fill:%s;font-size:17;\
116 font-family:typewriter;\" onclick=\"activate(\'%s\');\" >%s</text>\n"
120 let maxw1, maxy1 = loop output first node T.nil x (y + 40) in
121 let x_next = max (x+lbox) (maxw1+10) in
122 if node != root then begin
123 if prevsib == T.nil then
124 fprintf output "<line x1=\"%i\" y1=\"%i\" x2=\"%i\" y2=\"%i\"\
125 style=\"stroke:rgb(0,0,0);stroke-width:2\"/>\n"
126 (x + lbox / 2) (y-18) (x + lbox / 2) (y);
127 if next != T.nil then
128 fprintf output "<line x1=\"%i\" y1=\"%i\" x2=\"%i\" y2=\"%i\"\
129 style=\"stroke:rgb(0,0,0);stroke-width:2\"/>\n"
130 (x + lbox) (y+11) x_next (y+11);
132 let maxw2, maxy2 = loop output next parent node x_next y in
133 maxw2, max maxy1 maxy2
137 ignore (Sys.command "mkdir -p tests/trace");
138 let ohtml_ = open_out "tests/trace/trace.html" in
139 let ohtml = formatter_of_out_channel ohtml_ in
140 fprintf ohtml "<html>\n\
141 <head><title></title>\n\
142 <meta http-equiv='content-type' content='text/html;charset=utf-8'/>\n\
148 <div id='automata' >%a</div>\n\
149 <div id='data' > </div>\n\
150 <script type='text/javascript'>\n\
151 var data = new Array();\n\
155 (List.length sat_arrays);
156 List.iteri (fun i _ ->
157 fprintf ohtml "data[%i] = new Array();\n" i) sat_arrays;
158 for node_id = 0 to (Array.length (List.hd sat_arrays)) - 1 do
159 let _,_ = List.fold_left (fun (pass, diff_set) a ->
160 let cur_set = a.(node_id) in
161 fprintf ohtml "data[%i]['node%i'] = \"new states %a<br/>full states = %a\";\n"
162 pass node_id StateSet.print (StateSet.diff cur_set diff_set) StateSet.print cur_set;
163 (pass+1, StateSet.union diff_set cur_set))
164 (0, StateSet.empty) (List.rev sat_arrays)
167 fprintf ohtml "%s\n" Trace_js.content;
171 <svg id='svgimg' width='' height='' preserveAspectRatio='XMidYMid slice' xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n";
172 let maxw, maxh = loop ohtml (T.root tree) T.nil T.nil 50 50 in
173 fprintf ohtml "</svg>\n</div><script type='text/javascript'>\n\
174 window.onload = function () {\n\
175 var svg = document.getElementById('svgimg');\n\
176 svg.setAttribute('width', %i);\n\
177 svg.setAttribute('height', %i);\n\
178 activate('node0');\n\
180 </script></body></html>\n%!"
182 pp_print_flush ohtml ();