Revision a38c681e src/machine_code.ml
src/machine_code.ml  

271  271 
let join_guards_list insts = 
272  272 
List.fold_right join_guards insts [] 
273  273  
274 
let find_eq x eqs = 

275 
let rec aux accu eqs = 

276 
match eqs with 

277 
 [] > 

278 
begin 

279 
Format.eprintf "Looking for variable %a in the following equations@.%a@." 

280 
Format.pp_print_string x 

281 
Printers.pp_node_eqs eqs; 

282 
assert false 

283 
end 

284 
 hd::tl > 

285 
if List.mem x hd.eq_lhs then hd, accu@tl else aux (hd::accu) tl 

286 
in 

287 
aux [] eqs 

288  
289  274 
(* specialize predefined (polymorphic) operators 
290  275 
wrt their instances, so that the C semantics 
291  276 
is preserved *) 
...  ...  
430  415 
assert false 
431  416 
end 
432  417  
418 
let find_eq xl eqs = 

419 
let rec aux accu eqs = 

420 
match eqs with 

421 
 [] > 

422 
begin 

423 
Format.eprintf "Looking for variables %a in the following equations@.%a@." 

424 
(Utils.fprintf_list ~sep:" , " (fun fmt v > Format.fprintf fmt "%s" v)) xl 

425 
Printers.pp_node_eqs eqs; 

426 
assert false 

427 
end 

428 
 hd::tl > 

429 
if List.exists (fun x > List.mem x hd.eq_lhs) xl then hd, accu@tl else aux (hd::accu) tl 

430 
in 

431 
aux [] eqs 

432  
433 
(* Sort the set of equations of node [nd] according 

434 
to the computed schedule [sch] 

435 
*) 

436 
let sort_equations_from_schedule nd sch = 

437 
let split_eqs = Splitting.tuple_split_eq_list nd.node_eqs in 

438 
let eqs_rev, remainder = 

439 
List.fold_left 

440 
(fun (accu, node_eqs_remainder) vl > 

441 
if List.exists (fun eq > List.exists (fun v > List.mem v eq.eq_lhs) vl) accu 

442 
then 

443 
(accu, node_eqs_remainder) 

444 
else 

445 
let eq_v, remainder = find_eq vl node_eqs_remainder in 

446 
eq_v::accu, remainder 

447 
) 

448 
([], split_eqs) 

449 
sch 

450 
in 

451 
if List.length remainder > 0 then ( 

452 
Format.eprintf "Equations not used are@.%a@.Full equation set is:@.%a@.@?" 

453 
Printers.pp_node_eqs remainder 

454 
Printers.pp_node_eqs nd.node_eqs; 

455 
assert false); 

456 
List.rev eqs_rev 

457  
433  458 
let translate_eqs node args eqs = 
434  459 
List.fold_right (fun eq args > translate_eq node args eq) eqs args;; 
435  460  
436  461 
let translate_decl nd sch = 
437  462 
(*Log.report ~level:1 (fun fmt > Printers.pp_node fmt nd);*) 
438 
let split_eqs = Splitting.tuple_split_eq_list nd.node_eqs in 

463  
464 
(* 

439  465 
let eqs_rev, remainder = 
440  466 
List.fold_left 
441  467 
(fun (accu, node_eqs_remainder) v > 
...  ...  
455  481 
([], split_eqs) 
456  482 
sch 
457  483 
in 
458 
if List.length remainder > 0 then ( 

459 
Format.eprintf "Equations not used are@.%a@.Full equation set is:@.%a@.@?" 

460 
Printers.pp_node_eqs remainder 

461 
Printers.pp_node_eqs nd.node_eqs; 

462 
assert false ) 

463 
; 

484 
*) 

485 
let sorted_eqs = sort_equations_from_schedule nd sch in 

464  486  
465  487 
let init_args = ISet.empty, [], Utils.IMap.empty, List.fold_right (fun l > ISet.add l) nd.node_locals ISet.empty, [] in 
466  488 
(* memories, init instructions, node calls, local variables (including memories), step instrs *) 
467 
let m, init, j, locals, s = translate_eqs nd init_args (List.rev eqs_rev) in


489 
let m, init, j, locals, s = translate_eqs nd init_args sorted_eqs in


468  490 
let mmap = Utils.IMap.fold (fun i n res > (i, n)::res) j [] in 
469  491 
{ 
470  492 
mname = nd; 
Also available in: Unified diff