Revision b3f91fdb
Added by Xavier Thirioux almost 8 years ago
src/normalization.ml | ||
---|---|---|
75 | 75 |
} |
76 | 76 |
in aux () |
77 | 77 |
|
78 |
(* Generate a new ident expression from a declared variable *) |
|
79 |
let mk_ident_expr v = |
|
80 |
{ expr_tag = new_tag (); |
|
81 |
expr_desc = Expr_ident v.var_id; |
|
82 |
expr_type = v.var_type; |
|
83 |
expr_clock = v.var_clock; |
|
84 |
expr_delay = Delay.new_var (); |
|
85 |
expr_annot = None; |
|
86 |
expr_loc = v.var_loc } |
|
87 |
|
|
88 | 78 |
(* Get the equation in [defs] with [expr] as rhs, if any *) |
89 | 79 |
let get_expr_alias defs expr = |
90 | 80 |
try Some (List.find (fun eq -> is_eq_expr eq.eq_rhs expr) defs) |
... | ... | |
100 | 90 |
expr_desc = Expr_ident v.var_id } |
101 | 91 |
| _ -> { expr with |
102 | 92 |
expr_tag = Utils.new_tag (); |
103 |
expr_desc = Expr_tuple (List.map mk_ident_expr locals) }
|
|
93 |
expr_desc = Expr_tuple (List.map expr_of_vdecl locals) }
|
|
104 | 94 |
|
105 | 95 |
let unfold_offsets e offsets = |
106 | 96 |
let add_offset e d = |
107 |
(*Format.eprintf "add_offset %a %a@." Dimension.pp_dimension (Types.array_type_dimension e.expr_type) Dimension.pp_dimension d;*) |
|
97 |
(*Format.eprintf "add_offset %a(%a) %a @." Printers.pp_expr e Types.print_ty e.expr_type Dimension.pp_dimension d; |
|
98 |
let res = *) |
|
108 | 99 |
{ e with |
109 | 100 |
expr_tag = Utils.new_tag (); |
110 | 101 |
expr_loc = d.Dimension.dim_loc; |
111 | 102 |
expr_type = Types.array_element_type e.expr_type; |
112 |
expr_desc = Expr_access (e, d) } in |
|
103 |
expr_desc = Expr_access (e, d) } |
|
104 |
(*in (Format.eprintf "= %a @." Printers.pp_expr res; res) *) |
|
105 |
in |
|
113 | 106 |
List.fold_left add_offset e offsets |
114 | 107 |
|
115 | 108 |
(* Create an alias for [expr], if none exists yet *) |
... | ... | |
128 | 121 |
let new_def = |
129 | 122 |
mkeq expr.expr_loc (List.map (fun v -> v.var_id) new_aliases, expr) |
130 | 123 |
in |
131 |
(* Format.eprintf "Checkign def of alias: %a -> %a@." (fprintf_list ~sep:", " (fun fmt v -> Format.pp_print_string fmt v.var_id)) new_aliases Printers.pp_expr expr; *)
|
|
124 |
(* Format.eprintf "Checking def of alias: %a -> %a@." (fprintf_list ~sep:", " (fun fmt v -> Format.pp_print_string fmt v.var_id)) new_aliases Printers.pp_expr expr; *)
|
|
132 | 125 |
(new_def::defs, new_aliases@vars), replace_expr new_aliases expr |
133 | 126 |
|
134 | 127 |
(* Create an alias for [expr], if [expr] is not already an alias (i.e. an ident) |
... | ... | |
149 | 142 |
taking propagated [offsets] into account |
150 | 143 |
in order to change expression type *) |
151 | 144 |
let mk_norm_expr offsets ref_e norm_d = |
145 |
(*Format.eprintf "mk_norm_expr %a %a @." Printers.pp_expr ref_e Printers.pp_expr { ref_e with expr_desc = norm_d};*) |
|
152 | 146 |
let drop_array_type ty = |
153 | 147 |
Types.map_tuple_type Types.array_element_type ty in |
154 | 148 |
{ ref_e with |
... | ... | |
301 | 295 |
if List.exists (fun o -> o.var_id = v) node.node_outputs |
302 | 296 |
then |
303 | 297 |
let newvar = mk_fresh_var node eq.eq_loc t c in |
304 |
let neweq = mkeq eq.eq_loc ([v], mk_ident_expr newvar) in
|
|
298 |
let neweq = mkeq eq.eq_loc ([v], expr_of_vdecl newvar) in
|
|
305 | 299 |
(neweq :: defs_q, newvar :: vars_q), newvar.var_id :: lhs_q |
306 | 300 |
else |
307 | 301 |
(defs_q, vars_q), v::lhs_q |
Also available in: Unified diff
LOTS of bug correction wrt inlining, still a work in progress...
- global constants were not accounted for
- no good avoidance of name capture when inlining
- static parameters (array sizes and clocks) not handled
- ill-typed generated expressions, when inlining array expressions