Project

General

Profile

Revision 45c13277 src/machine_code.ml

View differences:

src/machine_code.ml
361 361
      NodeDep.filter_static_inputs (node_inputs node_f) el in 
362 362
    let o = new_instance node node_f eq.eq_rhs.expr_tag in
363 363
    let call_ck = Clocks.new_var true in
364
    Clock_calculus.unify_imported_clock (Some call_ck) eq.eq_rhs.expr_clock;
364
    Clock_calculus.unify_imported_clock (Some call_ck) eq.eq_rhs.expr_clock eq.eq_rhs.expr_loc;
365 365
    (m,
366 366
     (if Stateless.check_node node_f then si else MReset o :: si),
367 367
     Utils.IMap.add o call_f j,
......
519 519
      | None -> if m.mname.node_id = name then Some m else None)
520 520
    None machines
521 521
    
522
(* variable substitution for optimizing purposes *)
523

  
524
(* checks whether an [instr] is skip and can be removed from program *)
525
let rec instr_is_skip instr =
526
  match instr with
527
  | MLocalAssign (i, LocalVar v) when i = v -> true
528
  | MStateAssign (i, StateVar v) when i = v -> true
529
  | MBranch (g, hl) -> List.for_all (fun (_, il) -> instrs_are_skip il) hl
530
  | _               -> false
531
and instrs_are_skip instrs =
532
  List.for_all instr_is_skip instrs
533

  
534
let instr_cons instr cont =
535
 if instr_is_skip instr then cont else instr::cont
536

  
537
let rec instr_remove_skip instr cont =
538
  match instr with
539
  | MLocalAssign (i, LocalVar v) when i = v -> cont
540
  | MStateAssign (i, StateVar v) when i = v -> cont
541
  | MBranch (g, hl) -> MBranch (g, List.map (fun (h, il) -> (h, instrs_remove_skip il [])) hl) :: cont
542
  | _               -> instr::cont
543

  
544
and instrs_remove_skip instrs cont =
545
  List.fold_right instr_remove_skip instrs cont
546

  
547
let rec value_replace_var fvar value =
548
  match value with
549
  | Cst c -> value
550
  | LocalVar v -> LocalVar (fvar v)
551
  | StateVar v -> value
552
  | Fun (id, args) -> Fun (id, List.map (value_replace_var fvar) args) 
553
  | Array vl -> Array (List.map (value_replace_var fvar) vl)
554
  | Access (t, i) -> Access(value_replace_var fvar t, i)
555
  | Power (v, n) -> Power(value_replace_var fvar v, n)
556

  
557
let rec instr_replace_var fvar instr cont =
558
  match instr with
559
  | MLocalAssign (i, v) -> instr_cons (MLocalAssign (fvar i, value_replace_var fvar v)) cont
560
  | MStateAssign (i, v) -> instr_cons (MStateAssign (i, value_replace_var fvar v)) cont
561
  | MReset i            -> instr_cons instr cont
562
  | MStep (il, i, vl)   -> instr_cons (MStep (List.map fvar il, i, List.map (value_replace_var fvar) vl)) cont
563
  | MBranch (g, hl)     -> instr_cons (MBranch (value_replace_var fvar g, List.map (fun (h, il) -> (h, instrs_replace_var fvar il [])) hl)) cont
564

  
565
and instrs_replace_var fvar instrs cont =
566
  List.fold_right (instr_replace_var fvar) instrs cont
567

  
568
let step_replace_var fvar step =
569
  { step with
570
    step_checks = List.map (fun (l, v) -> (l, value_replace_var fvar v)) step.step_checks;
571
    step_locals = Utils.remove_duplicates (List.map fvar step.step_locals);
572
    step_instrs = instrs_replace_var fvar step.step_instrs [];
573
}
574

  
575
let rec machine_replace_var fvar m =
576
  { m with
577
    mstep = step_replace_var fvar m.mstep
578
  }
579

  
580
let machine_reuse_var m reuse =
581
  let fvar v =
582
    try
583
      Hashtbl.find reuse v.var_id
584
    with Not_found -> v in
585
  machine_replace_var fvar m
586

  
587
let prog_reuse_var prog node_schs =
588
  List.map 
589
    (fun m -> 
590
      machine_reuse_var m (Utils.IMap.find m.mname.node_id node_schs).Scheduling.reuse_table
591
    ) prog
592 522

  
593 523
(* Local Variables: *)
594 524
(* compile-command:"make -C .." *)

Also available in: Unified diff