lustrec / src / splitting.ml @ c3d8313d
History | View | Annotate | Download (3.18 KB)
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 | 01c7d5e1 | ploc | open LustreSpec |
15 | 22fe1c93 | ploc | open Format |
16 | |||
17 | |||
18 | let rec tuple_split_expr expr = |
||
19 | match expr.expr_desc with |
||
20 | | Expr_const _ |
||
21 | | Expr_ident _ -> [expr] |
||
22 | | Expr_tuple elist -> elist |
||
23 | | Expr_appl (id, args, r) -> |
||
24 | 04a63d25 | xthirioux | if Basic_library.is_homomorphic_fun id |
25 | 22fe1c93 | ploc | then |
26 | let args_list = List.map tuple_split_expr (expr_list_of_expr args) in |
||
27 | List.map |
||
28 | (fun arg -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_appl (id, expr_of_expr_list args.expr_loc arg, r) }) |
||
29 | (transpose_list args_list) |
||
30 | else |
||
31 | [expr] |
||
32 | | Expr_array el -> |
||
33 | let args_list = List.map tuple_split_expr el in |
||
34 | List.map |
||
35 | (fun arg -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_array arg }) |
||
36 | (transpose_list args_list) |
||
37 | | Expr_access (e1, d) -> |
||
38 | List.map |
||
39 | (fun e1 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_access (e1, d) }) |
||
40 | (tuple_split_expr e1) |
||
41 | | Expr_power (e1, d) -> |
||
42 | List.map |
||
43 | (fun e1 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_power (e1, d) }) |
||
44 | (tuple_split_expr e1) |
||
45 | | Expr_arrow (e1,e2) -> |
||
46 | List.map2 |
||
47 | (fun e1 e2 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_arrow (e1, e2) }) |
||
48 | (tuple_split_expr e1) |
||
49 | (tuple_split_expr e2) |
||
50 | | Expr_pre e -> |
||
51 | List.map |
||
52 | (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_pre e }) |
||
53 | (tuple_split_expr e) |
||
54 | | Expr_fby (v, e) -> |
||
55 | List.map |
||
56 | (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_fby (v, e) }) |
||
57 | (tuple_split_expr e) |
||
58 | | Expr_when (e, c, l) -> |
||
59 | List.map |
||
60 | (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_when (e, c, l) }) |
||
61 | (tuple_split_expr e) |
||
62 | | Expr_ite (c, t, e) -> |
||
63 | List.map2 |
||
64 | (fun t e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_ite (c, t, e) }) |
||
65 | (tuple_split_expr t) |
||
66 | (tuple_split_expr e) |
||
67 | | Expr_merge (c,hl) -> |
||
68 | let tl, hl = List.split (List.map (fun (t, h) -> (t, tuple_split_expr h)) hl) in |
||
69 | List.map |
||
70 | (fun hl -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_merge (c, List.combine tl hl) }) |
||
71 | (transpose_list hl) |
||
72 | |||
73 | let rec tuple_split_eq eq = |
||
74 | let split_rhs = tuple_split_expr eq.eq_rhs in |
||
75 | if List.length split_rhs = 1 |
||
76 | then |
||
77 | [eq] |
||
78 | else |
||
79 | List.map2 |
||
80 | (fun lhs rhs -> mkeq eq.eq_loc ([lhs], rhs)) |
||
81 | eq.eq_lhs |
||
82 | split_rhs |
||
83 | |||
84 | let tuple_split_eq_list eqs = |
||
85 | List.fold_right (fun eq -> (@) (tuple_split_eq eq)) eqs [] |
||
86 | |||
87 | |||
88 | (* Local Variables: *) |
||
89 | (* compile-command:"make -C .." *) |
||
90 | (* End: *) |