Project

General

Profile

Revision 7ecdb0aa src/optimize_prog.ml

View differences:

src/optimize_prog.ml
39 39
let node_unfold_consts consts node = 
40 40
  { node with node_eqs = List.map (eq_unfold_consts consts) node.node_eqs }
41 41

  
42

  
43

  
44 42
let prog_unfold_consts prog =
45 43
  let consts = get_consts prog in
46 44
    List.map (
......
49 47
	| _       -> decl
50 48
    ) prog 
51 49

  
50
let apply_stack expr stack =
51
 List.fold_left (fun expr (v, t) -> mkexpr expr.expr_loc (Expr_when (expr, v, t))) expr stack
52

  
53
let expr_distribute_when expr =
54
  let rec distrib stack expr =
55
    match expr.expr_desc with
56
    | Expr_const _
57
    | Expr_ident _
58
    | Expr_arrow _
59
    | Expr_fby _
60
    | Expr_pre _
61
	-> apply_stack expr stack
62
    | Expr_appl (id, _, _) when not (Stateless.check_node (node_from_name id))
63
	-> apply_stack expr stack
64
    | Expr_ite (c, t, e)
65
        -> let cid = ident_of_expr c in
66
           mkexpr expr.expr_loc
67
	     (Expr_merge (cid,
68
			  [(tag_true , distrib ((cid,tag_true )::stack) t);
69
			   (tag_false, distrib ((cid,tag_false)::stack) e)]))
70
    | Expr_array el -> { expr with expr_desc = (Expr_array (List.map (distrib stack) el)) }
71
    | Expr_access (e1, d) -> { expr with expr_desc = Expr_access (distrib stack e1, d) }
72
    | Expr_power (e1, d) -> { expr with expr_desc = Expr_power (distrib stack e1, d) }
73
    | Expr_tuple el -> { expr with expr_desc = Expr_tuple (List.map (distrib stack) el) }
74
    | Expr_when (e', i, l)-> distrib ((i, l)::stack) e'
75
    | Expr_merge (i, hl) -> { expr with expr_desc = Expr_merge (i, List.map (fun (t, h) -> (t, distrib stack h)) hl) }
76
    | Expr_appl (id, e', i') -> { expr with expr_desc = Expr_appl (id, distrib stack e', i')}
77
    | _ -> assert false
78
  in distrib [] expr
79

  
80
let eq_distribute_when eq =
81
  { eq with eq_rhs = expr_distribute_when eq.eq_rhs }
82

  
83
let node_distribute_when node =
84
  { node with node_eqs = List.map eq_distribute_when node.node_eqs }
85

  
86
let prog_distribute_when prog =
87
    List.map (
88
      fun decl -> match decl.top_decl_desc with 
89
	| Node nd -> {decl with top_decl_desc = Node (node_distribute_when nd)}
90
	| _       -> decl
91
    ) prog 
52 92
(* Local Variables: *)
53 93
(* compile-command:"make -C .." *)
54 94
(* End: *)

Also available in: Unified diff