Project

General

Profile

Revision 44bea83a src/machine_code.ml

View differences:

src/machine_code.ml
524 524
and instrs_are_skip instrs =
525 525
  List.for_all instr_is_skip instrs
526 526

  
527
let instr_cons instr cont =
528
 if instr_is_skip instr then cont else instr::cont
529

  
527 530
let rec instr_remove_skip instr cont =
528 531
  match instr with
529 532
  | MLocalAssign (i, LocalVar v) when i = v -> cont
......
544 547
  | Access (t, i) -> Access(value_replace_var fvar t, i)
545 548
  | Power (v, n) -> Power(value_replace_var fvar v, n)
546 549

  
547
let rec instr_replace_var fvar instr =
550
let rec instr_replace_var fvar instr cont =
548 551
  match instr with
549
  | MLocalAssign (i, v) -> MLocalAssign (fvar i, value_replace_var fvar v)
550
  | MStateAssign (i, v) -> MStateAssign (i, value_replace_var fvar v)
551
  | MReset i            -> instr
552
  | MStep (il, i, vl)   -> MStep (List.map fvar il, i, List.map (value_replace_var fvar) vl)
553
  | MBranch (g, hl)     -> MBranch (value_replace_var fvar g, List.map (fun (h, il) -> (h, instrs_replace_var fvar il)) hl)
552
  | MLocalAssign (i, v) -> instr_cons (MLocalAssign (fvar i, value_replace_var fvar v)) cont
553
  | MStateAssign (i, v) -> instr_cons (MStateAssign (i, value_replace_var fvar v)) cont
554
  | MReset i            -> instr_cons instr cont
555
  | MStep (il, i, vl)   -> instr_cons (MStep (List.map fvar il, i, List.map (value_replace_var fvar) vl)) cont
556
  | MBranch (g, hl)     -> instr_cons (MBranch (value_replace_var fvar g, List.map (fun (h, il) -> (h, instrs_replace_var fvar il [])) hl)) cont
554 557

  
555
and instrs_replace_var fvar instrs =
556
  List.map (instr_replace_var fvar) instrs
558
and instrs_replace_var fvar instrs cont =
559
  List.fold_right (instr_replace_var fvar) instrs cont
557 560

  
558 561
let step_replace_var fvar step =
559 562
  { step with
560 563
    step_checks = List.map (fun (l, v) -> (l, value_replace_var fvar v)) step.step_checks;
561 564
    step_locals = Utils.remove_duplicates (List.map fvar step.step_locals);
562
    step_instrs = instrs_replace_var fvar step.step_instrs;
565
    step_instrs = instrs_replace_var fvar step.step_instrs [];
563 566
}
564 567

  
565 568
let rec machine_replace_var fvar m =
......
568 571
  }
569 572

  
570 573
let machine_reuse_var m reuse =
571
  let reuse_vdecl = Hashtbl.create 23 in
572
  begin
573
    Hashtbl.iter (fun v v' -> Hashtbl.add reuse_vdecl (get_node_var v m.mname) (get_node_var v' m.mname)) reuse;
574
    let fvar v =
575
      try
576
	Hashtbl.find reuse_vdecl v
577
      with Not_found -> v in
578
    machine_replace_var fvar m
579
  end
574
  let fvar v =
575
    try
576
      Hashtbl.find reuse v.var_id
577
    with Not_found -> v in
578
  machine_replace_var fvar m
580 579

  
581 580
let prog_reuse_var prog node_schs =
582 581
  List.map 

Also available in: Unified diff