Project

General

Profile

Download (3.51 KB) Statistics
| Branch: | Tag: | Revision:
1 a2d97a3e ploc
(********************************************************************)
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 22fe1c93 ploc
12
open Utils
13
open Corelang
14 8446bf03 ploc
open Lustre_types
15 22fe1c93 ploc
16 ca7ff3f7 Lélio Brun
let rec tuple_split_expr expr =
17 22fe1c93 ploc
  match expr.expr_desc with
18 ca7ff3f7 Lélio Brun
  | Expr_const _ | Expr_ident _ ->
19
    [ expr ]
20
  | Expr_tuple elist ->
21
    elist
22 22fe1c93 ploc
  | Expr_appl (id, args, r) ->
23 ca7ff3f7 Lélio Brun
    if Basic_library.is_homomorphic_fun id then
24 22fe1c93 ploc
      let args_list = List.map tuple_split_expr (expr_list_of_expr args) in
25
      List.map
26 ca7ff3f7 Lélio Brun
        (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 22fe1c93 ploc
  | Expr_array el ->
35
    let args_list = List.map tuple_split_expr el in
36
    List.map
37 ca7ff3f7 Lélio Brun
      (fun arg ->
38
        { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_array arg })
39 22fe1c93 ploc
      (transpose_list args_list)
40
  | Expr_access (e1, d) ->
41
    List.map
42 ca7ff3f7 Lélio Brun
      (fun e1 ->
43
        {
44
          expr with
45
          expr_tag = Utils.new_tag ();
46
          expr_desc = Expr_access (e1, d);
47
        })
48 22fe1c93 ploc
      (tuple_split_expr e1)
49 ca7ff3f7 Lélio Brun
  | Expr_power (e1, d) ->
50 22fe1c93 ploc
    List.map
51 ca7ff3f7 Lélio Brun
      (fun e1 ->
52
        {
53
          expr with
54
          expr_tag = Utils.new_tag ();
55
          expr_desc = Expr_power (e1, d);
56
        })
57 22fe1c93 ploc
      (tuple_split_expr e1)
58 ca7ff3f7 Lélio Brun
  | Expr_arrow (e1, e2) ->
59 22fe1c93 ploc
    List.map2
60 ca7ff3f7 Lélio Brun
      (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 22fe1c93 ploc
  | Expr_pre e ->
68
    List.map
69 ca7ff3f7 Lélio Brun
      (fun e ->
70
        { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_pre e })
71 22fe1c93 ploc
      (tuple_split_expr e)
72
  | Expr_fby (v, e) ->
73
    List.map
74 ca7ff3f7 Lélio Brun
      (fun e ->
75
        { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_fby (v, e) })
76 22fe1c93 ploc
      (tuple_split_expr e)
77
  | Expr_when (e, c, l) ->
78
    List.map
79 ca7ff3f7 Lélio Brun
      (fun e ->
80
        {
81
          expr with
82
          expr_tag = Utils.new_tag ();
83
          expr_desc = Expr_when (e, c, l);
84
        })
85 22fe1c93 ploc
      (tuple_split_expr e)
86
  | Expr_ite (c, t, e) ->
87
    List.map2
88 ca7ff3f7 Lélio Brun
      (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 22fe1c93 ploc
    List.map
100 ca7ff3f7 Lélio Brun
      (fun hl ->
101
        {
102
          expr with
103
          expr_tag = Utils.new_tag ();
104
          expr_desc = Expr_merge (c, List.combine tl hl);
105
        })
106 22fe1c93 ploc
      (transpose_list hl)
107
108 ca7e8027 Lélio Brun
let tuple_split_eq eq =
109 22fe1c93 ploc
  let split_rhs = tuple_split_expr eq.eq_rhs in
110 ca7ff3f7 Lélio Brun
  if List.length split_rhs = 1 then [ eq ]
111 22fe1c93 ploc
  else
112 ca7ff3f7 Lélio Brun
    List.map2 (fun lhs rhs -> mkeq eq.eq_loc ([ lhs ], rhs)) eq.eq_lhs split_rhs
113 22fe1c93 ploc
114
let tuple_split_eq_list eqs =
115 ca7ff3f7 Lélio Brun
  List.fold_right (fun eq -> ( @ ) (tuple_split_eq eq)) eqs []
116 22fe1c93 ploc
117
(* Local Variables: *)
118
(* compile-command:"make -C .." *)
119
(* End: *)