Project

General

Profile

Download (3.16 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

    
17
let rec tuple_split_expr expr = 
18
  match expr.expr_desc with
19
  | Expr_const _ 
20
  | Expr_ident _ -> [expr]
21
  | Expr_tuple elist -> elist
22
  | Expr_appl (id, args, r) ->
23
    if Basic_library.is_homomorphic_fun id 
24
    then
25
      let args_list = List.map tuple_split_expr (expr_list_of_expr args) in
26
      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]
31
  | Expr_array el ->
32
    let args_list = List.map tuple_split_expr el in
33
    List.map
34
      (fun arg -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_array arg })
35
      (transpose_list args_list)
36
  | Expr_access (e1, d) ->
37
    List.map
38
      (fun e1 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_access (e1, d) })
39
      (tuple_split_expr e1)
40
 | Expr_power (e1, d) ->
41
    List.map
42
      (fun e1 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_power (e1, d) })
43
      (tuple_split_expr e1)
44
  | Expr_arrow (e1,e2) -> 
45
    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)
49
  | Expr_pre e ->
50
    List.map
51
      (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_pre e })
52
      (tuple_split_expr e)
53
  | Expr_fby (v, e) ->
54
    List.map
55
      (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_fby (v, e) })
56
      (tuple_split_expr e)
57
  | Expr_when (e, c, l) ->
58
    List.map
59
      (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_when (e, c, l) })
60
      (tuple_split_expr e)
61
  | Expr_ite (c, t, e) ->
62
    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
68
    List.map
69
      (fun hl -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_merge (c, List.combine tl hl) })
70
      (transpose_list hl)
71

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

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

    
86

    
87
(* Local Variables: *)
88
(* compile-command:"make -C .." *)
89
(* End: *)
(56-56/63)