Project

General

Profile

Download (3.51 KB) Statistics
| Branch: | Tag: | Revision:
1
(********************************************************************)
2
(*                                                                  *)
3
(*  The LustreC compiler toolset   /  The LustreC Development Team  *)
4
(*  Copyright 2012 -    --   ONERA - CNRS - INPT                    *)
5
(*                                                                  *)
6
(*  LustreC is free software, distributed WITHOUT ANY WARRANTY      *)
7
(*  under the terms of the GNU Lesser General Public License        *)
8
(*  version 2.1.                                                    *)
9
(*                                                                  *)
10
(********************************************************************)
11

    
12
open Utils
13
open Corelang
14
open Lustre_types
15

    
16
let rec tuple_split_expr expr =
17
  match expr.expr_desc with
18
  | Expr_const _ | Expr_ident _ ->
19
    [ expr ]
20
  | Expr_tuple elist ->
21
    elist
22
  | Expr_appl (id, args, r) ->
23
    if Basic_library.is_homomorphic_fun id then
24
      let args_list = List.map tuple_split_expr (expr_list_of_expr args) in
25
      List.map
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 ]
34
  | Expr_array el ->
35
    let args_list = List.map tuple_split_expr el in
36
    List.map
37
      (fun arg ->
38
        { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_array arg })
39
      (transpose_list args_list)
40
  | Expr_access (e1, d) ->
41
    List.map
42
      (fun e1 ->
43
        {
44
          expr with
45
          expr_tag = Utils.new_tag ();
46
          expr_desc = Expr_access (e1, d);
47
        })
48
      (tuple_split_expr e1)
49
  | Expr_power (e1, d) ->
50
    List.map
51
      (fun e1 ->
52
        {
53
          expr with
54
          expr_tag = Utils.new_tag ();
55
          expr_desc = Expr_power (e1, d);
56
        })
57
      (tuple_split_expr e1)
58
  | Expr_arrow (e1, e2) ->
59
    List.map2
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)
67
  | Expr_pre e ->
68
    List.map
69
      (fun e ->
70
        { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_pre e })
71
      (tuple_split_expr e)
72
  | Expr_fby (v, e) ->
73
    List.map
74
      (fun e ->
75
        { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_fby (v, e) })
76
      (tuple_split_expr e)
77
  | Expr_when (e, c, l) ->
78
    List.map
79
      (fun e ->
80
        {
81
          expr with
82
          expr_tag = Utils.new_tag ();
83
          expr_desc = Expr_when (e, c, l);
84
        })
85
      (tuple_split_expr e)
86
  | Expr_ite (c, t, e) ->
87
    List.map2
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
99
    List.map
100
      (fun hl ->
101
        {
102
          expr with
103
          expr_tag = Utils.new_tag ();
104
          expr_desc = Expr_merge (c, List.combine tl hl);
105
        })
106
      (transpose_list hl)
107

    
108
let tuple_split_eq eq =
109
  let split_rhs = tuple_split_expr eq.eq_rhs in
110
  if List.length split_rhs = 1 then [ eq ]
111
  else
112
    List.map2 (fun lhs rhs -> mkeq eq.eq_loc ([ lhs ], rhs)) eq.eq_lhs split_rhs
113

    
114
let tuple_split_eq_list eqs =
115
  List.fold_right (fun eq -> ( @ ) (tuple_split_eq eq)) eqs []
116

    
117
(* Local Variables: *)
118
(* compile-command:"make -C .." *)
119
(* End: *)
(59-59/66)