Project

General

Profile

« Previous | Next » 

Revision ca7ff3f7

Added by LĂ©lio Brun 7 months ago

reformatting

View differences:

src/splitting.ml
13 13
open Corelang
14 14
open Lustre_types
15 15

  
16

  
17
let rec tuple_split_expr expr = 
16
let rec tuple_split_expr expr =
18 17
  match expr.expr_desc with
19
  | Expr_const _ 
20
  | Expr_ident _ -> [expr]
21
  | Expr_tuple elist -> elist
18
  | Expr_const _ | Expr_ident _ ->
19
    [ expr ]
20
  | Expr_tuple elist ->
21
    elist
22 22
  | Expr_appl (id, args, r) ->
23
    if Basic_library.is_homomorphic_fun id 
24
    then
23
    if Basic_library.is_homomorphic_fun id then
25 24
      let args_list = List.map tuple_split_expr (expr_list_of_expr args) in
26 25
      List.map
27
	(fun arg -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_appl (id, expr_of_expr_list args.expr_loc arg, r) })
28
	(transpose_list args_list)
29
    else
30
      [expr]
26
        (fun arg ->
27
          {
28
            expr with
29
            expr_tag = Utils.new_tag ();
30
            expr_desc = Expr_appl (id, expr_of_expr_list args.expr_loc arg, r);
31
          })
32
        (transpose_list args_list)
33
    else [ expr ]
31 34
  | Expr_array el ->
32 35
    let args_list = List.map tuple_split_expr el in
33 36
    List.map
34
      (fun arg -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_array arg })
37
      (fun arg ->
38
        { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_array arg })
35 39
      (transpose_list args_list)
36 40
  | Expr_access (e1, d) ->
37 41
    List.map
38
      (fun e1 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_access (e1, d) })
42
      (fun e1 ->
43
        {
44
          expr with
45
          expr_tag = Utils.new_tag ();
46
          expr_desc = Expr_access (e1, d);
47
        })
39 48
      (tuple_split_expr e1)
40
 | Expr_power (e1, d) ->
49
  | Expr_power (e1, d) ->
41 50
    List.map
42
      (fun e1 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_power (e1, d) })
51
      (fun e1 ->
52
        {
53
          expr with
54
          expr_tag = Utils.new_tag ();
55
          expr_desc = Expr_power (e1, d);
56
        })
43 57
      (tuple_split_expr e1)
44
  | Expr_arrow (e1,e2) -> 
58
  | Expr_arrow (e1, e2) ->
45 59
    List.map2
46
      (fun e1 e2 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_arrow (e1, e2) })
47
      (tuple_split_expr e1)
48
      (tuple_split_expr e2)
60
      (fun e1 e2 ->
61
        {
62
          expr with
63
          expr_tag = Utils.new_tag ();
64
          expr_desc = Expr_arrow (e1, e2);
65
        })
66
      (tuple_split_expr e1) (tuple_split_expr e2)
49 67
  | Expr_pre e ->
50 68
    List.map
51
      (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_pre e })
69
      (fun e ->
70
        { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_pre e })
52 71
      (tuple_split_expr e)
53 72
  | Expr_fby (v, e) ->
54 73
    List.map
55
      (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_fby (v, e) })
74
      (fun e ->
75
        { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_fby (v, e) })
56 76
      (tuple_split_expr e)
57 77
  | Expr_when (e, c, l) ->
58 78
    List.map
59
      (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_when (e, c, l) })
79
      (fun e ->
80
        {
81
          expr with
82
          expr_tag = Utils.new_tag ();
83
          expr_desc = Expr_when (e, c, l);
84
        })
60 85
      (tuple_split_expr e)
61 86
  | Expr_ite (c, t, e) ->
62 87
    List.map2
63
      (fun t e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_ite (c, t, e) })
64
      (tuple_split_expr t)
65
      (tuple_split_expr e)
66
  | Expr_merge (c,hl) ->
67
    let tl, hl = List.split (List.map (fun (t, h) -> (t, tuple_split_expr h)) hl) in
88
      (fun t e ->
89
        {
90
          expr with
91
          expr_tag = Utils.new_tag ();
92
          expr_desc = Expr_ite (c, t, e);
93
        })
94
      (tuple_split_expr t) (tuple_split_expr e)
95
  | Expr_merge (c, hl) ->
96
    let tl, hl =
97
      List.split (List.map (fun (t, h) -> t, tuple_split_expr h) hl)
98
    in
68 99
    List.map
69
      (fun hl -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_merge (c, List.combine tl hl) })
100
      (fun hl ->
101
        {
102
          expr with
103
          expr_tag = Utils.new_tag ();
104
          expr_desc = Expr_merge (c, List.combine tl hl);
105
        })
70 106
      (transpose_list hl)
71 107

  
72 108
let tuple_split_eq eq =
73 109
  let split_rhs = tuple_split_expr eq.eq_rhs in
74
  if List.length split_rhs = 1
75
  then
76
    [eq]
110
  if List.length split_rhs = 1 then [ eq ]
77 111
  else
78
    List.map2
79
      (fun lhs rhs -> mkeq eq.eq_loc ([lhs], rhs))
80
      eq.eq_lhs
81
      split_rhs
112
    List.map2 (fun lhs rhs -> mkeq eq.eq_loc ([ lhs ], rhs)) eq.eq_lhs split_rhs
82 113

  
83 114
let tuple_split_eq_list eqs =
84
 List.fold_right (fun eq -> (@) (tuple_split_eq eq)) eqs []
85

  
115
  List.fold_right (fun eq -> ( @ ) (tuple_split_eq eq)) eqs []
86 116

  
87 117
(* Local Variables: *)
88 118
(* compile-command:"make -C .." *)

Also available in: Unified diff