Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / splitting.ml @ 2196a0a6

History | View | Annotate | Download (4.32 KB)

1 0cbf0839 ploc
(* ----------------------------------------------------------------------------
2
 * SchedMCore - A MultiCore Scheduling Framework
3
 * Copyright (C) 2009-2013, ONERA, Toulouse, FRANCE - LIFL, Lille, FRANCE
4
 * Copyright (C) 2012-2013, INPT, Toulouse, FRANCE
5
 *
6
 * This file is part of Prelude
7
 *
8
 * Prelude is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public License
10
 * as published by the Free Software Foundation ; either version 2 of
11
 * the License, or (at your option) any later version.
12
 *
13
 * Prelude is distributed in the hope that it will be useful, but
14
 * WITHOUT ANY WARRANTY ; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this program ; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21
 * USA
22
 *---------------------------------------------------------------------------- *)
23
24
(* This module is used for the lustre to C compiler *)
25
26
27
open Utils
28
open Corelang
29
30
open Format
31
32
33
let rec tuple_split_expr expr = 
34
  match expr.expr_desc with
35
  | Expr_const _ 
36
  | Expr_ident _ -> [expr]
37
  | Expr_tuple elist -> elist
38 96fecb0f ploc
  | Expr_appl ("=", args, r) -> ( (* Specific treatment of tuple equalities *)
39
    let args_list = List.map tuple_split_expr (expr_list_of_expr args) in
40
    let (eqs : expr list)=
41
      List.map
42
	(fun arg -> 
43
	  {expr with 
44
	    expr_tag = Utils.new_tag (); 
45
	    expr_desc = Expr_appl ("=", expr_of_expr_list args.expr_loc arg, r) 
46
	  })
47
	(transpose_list args_list)
48
    in
49
    match eqs with 
50
    | [] -> assert false 
51
    | [e] -> [e]
52
    | hd::tl -> 
53
      let res = List.fold_left (fun accu eq ->
54
	mkpredef_call args.expr_loc "&&" [accu; eq]
55
      ) hd tl
56
      in
57
      [res]
58
  )
59 0cbf0839 ploc
  | Expr_appl (id, args, r) ->
60
    if Basic_library.is_internal_fun id
61
    then
62
      let args_list = List.map tuple_split_expr (expr_list_of_expr args) in
63
      List.map
64
	(fun arg -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_appl (id, expr_of_expr_list args.expr_loc arg, r) })
65
	(transpose_list args_list)
66
    else
67
      [expr]
68
  | Expr_array el ->
69
    let args_list = List.map tuple_split_expr el in
70
    List.map
71
      (fun arg -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_array arg })
72
      (transpose_list args_list)
73
  | Expr_access (e1, d) ->
74
    List.map
75
      (fun e1 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_access (e1, d) })
76
      (tuple_split_expr e1)
77 96fecb0f ploc
  | Expr_power (e1, d) ->
78 0cbf0839 ploc
    List.map
79
      (fun e1 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_power (e1, d) })
80
      (tuple_split_expr e1)
81
  | Expr_arrow (e1,e2) -> 
82
    List.map2
83
      (fun e1 e2 -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_arrow (e1, e2) })
84
      (tuple_split_expr e1)
85
      (tuple_split_expr e2)
86
  | Expr_pre e ->
87
    List.map
88
      (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_pre e })
89
      (tuple_split_expr e)
90
  | Expr_fby (v, e) ->
91
    List.map
92
      (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_fby (v, e) })
93
      (tuple_split_expr e)
94
  | Expr_when (e, c, l) ->
95
    List.map
96
      (fun e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_when (e, c, l) })
97
      (tuple_split_expr e)
98
  | Expr_ite (c, t, e) ->
99
    List.map2
100
      (fun t e -> { expr with expr_tag = Utils.new_tag (); expr_desc = Expr_ite (c, t, e) })
101
      (tuple_split_expr t)
102
      (tuple_split_expr e)
103
  | Expr_merge (c,hl) ->
104
    let tl, hl = List.split (List.map (fun (t, h) -> (t, tuple_split_expr h)) hl) in
105
    List.map
106
      (fun hl -> {expr with expr_tag = Utils.new_tag (); expr_desc = Expr_merge (c, List.combine tl hl) })
107
      (transpose_list hl)
108
  | Expr_uclock _
109
  | Expr_dclock _ 
110
  | Expr_phclock _ -> assert false (* Not handled yet *)
111
112
let rec tuple_split_eq eq =
113
  let split_rhs = tuple_split_expr eq.eq_rhs in
114 96fecb0f ploc
  match split_rhs with
115
  | [rhs] -> [{eq with eq_rhs = rhs }]
116
  | _ -> 
117
    try 
118
      List.map2
119
	(fun lhs rhs -> mkeq eq.eq_loc ([lhs], rhs))
120
	eq.eq_lhs
121
	split_rhs
122
    with Invalid_argument _ -> assert false
123 0cbf0839 ploc
124
let tuple_split_eq_list eqs =
125
 List.fold_right (fun eq -> (@) (tuple_split_eq eq)) eqs []
126
127
128
(* Local Variables: *)
129
(* compile-command:"make -C .." *)
130
(* End: *)