2010-06-15 10:49:03 +02:00
|
|
|
open C
|
2010-07-23 19:45:19 +02:00
|
|
|
open Idents
|
2010-06-15 10:49:03 +02:00
|
|
|
open Names
|
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
let rec subst_stm map stm = match stm with
|
|
|
|
| Csexpr e -> Csexpr (subst_exp map e)
|
|
|
|
| Cskip -> Cskip
|
|
|
|
| Creturn e -> Creturn (subst_exp map e)
|
|
|
|
| Csblock cblock ->
|
|
|
|
Csblock (subst_block map cblock)
|
|
|
|
| Caffect (lhs, e) ->
|
|
|
|
Caffect(subst_lhs map lhs, subst_exp map e)
|
|
|
|
| Cif (e, truel, falsel) ->
|
2010-06-29 11:18:50 +02:00
|
|
|
Cif (subst_exp map e, subst_stm_list map truel,
|
2010-06-27 17:24:31 +02:00
|
|
|
subst_stm_list map falsel)
|
|
|
|
| Cswitch (e, l) ->
|
|
|
|
Cswitch (subst_exp map e
|
2010-06-29 11:18:50 +02:00
|
|
|
, List.map (fun (s, sl) -> s, subst_stm_list map sl) l)
|
2010-06-27 17:24:31 +02:00
|
|
|
| Cwhile (e, l) ->
|
|
|
|
Cwhile (subst_exp map e, subst_stm_list map l)
|
|
|
|
| Cfor (x, i1, i2, l) ->
|
|
|
|
Cfor (x, i1, i2, subst_stm_list map l)
|
2010-06-15 10:49:03 +02:00
|
|
|
|
|
|
|
and subst_stm_list map =
|
2010-06-26 16:53:25 +02:00
|
|
|
List.map (subst_stm map)
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2010-06-26 16:53:25 +02:00
|
|
|
and subst_lhs map lhs =
|
2010-06-15 10:49:03 +02:00
|
|
|
match lhs with
|
2010-06-26 16:53:25 +02:00
|
|
|
| Cvar n ->
|
2010-06-27 17:24:31 +02:00
|
|
|
if NamesEnv.mem n map then NamesEnv.find n map else lhs
|
2010-06-15 10:49:03 +02:00
|
|
|
| Cfield (lhs, s) -> Cfield (subst_lhs map lhs, s)
|
|
|
|
| Carray (lhs, n) -> Carray (subst_lhs map lhs, n)
|
|
|
|
| Cderef lhs -> Cderef (subst_lhs map lhs)
|
|
|
|
|
|
|
|
and subst_exp map = function
|
|
|
|
| Cuop (op, e) -> Cuop (op, subst_exp map e)
|
|
|
|
| Cbop (s, l, r) -> Cbop (s, subst_exp map l, subst_exp map r)
|
|
|
|
| Cfun_call (s, el) -> Cfun_call (s, subst_exp_list map el)
|
|
|
|
| Cconst x -> Cconst x
|
|
|
|
| Clhs lhs -> Clhs (subst_lhs map lhs)
|
|
|
|
| Caddrof lhs -> Caddrof (subst_lhs map lhs)
|
|
|
|
| Cstructlit (s, el) -> Cstructlit (s, subst_exp_list map el)
|
|
|
|
| Carraylit el -> Carraylit (subst_exp_list map el)
|
|
|
|
|
|
|
|
and subst_exp_list map =
|
|
|
|
List.map (subst_exp map)
|
|
|
|
|
|
|
|
and subst_block map b =
|
2010-06-18 10:55:16 +02:00
|
|
|
{ b with block_body = subst_stm_list map b.block_body }
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2010-07-09 09:31:12 +02:00
|
|
|
let assoc_map_for_fun md =
|
|
|
|
match md.Obc.m_outputs with
|
2010-06-15 10:49:03 +02:00
|
|
|
| [] -> NamesEnv.empty
|
|
|
|
| out ->
|
|
|
|
let fill_field map vd =
|
2010-06-27 17:24:31 +02:00
|
|
|
NamesEnv.add (name vd.Obc.v_ident)
|
2010-06-30 17:30:24 +02:00
|
|
|
(Cfield (Cderef (Cvar "out"), name vd.Obc.v_ident)) map
|
2010-06-29 11:18:50 +02:00
|
|
|
in
|
|
|
|
List.fold_left fill_field NamesEnv.empty out
|
2010-06-15 10:49:03 +02:00
|
|
|
|