172 |
172 |
- if it's not a scalar output, then its name is enough
|
173 |
173 |
- otherwise, dereference it (it has been declared as a pointer,
|
174 |
174 |
despite its scalar Lustre type)
|
175 |
|
- moreover, cast arrays variables into their original array type.
|
|
175 |
- moreover, dereference memory array variables.
|
176 |
176 |
*)
|
177 |
177 |
let pp_c_var_read m fmt id =
|
178 |
178 |
if Types.is_address_type id.var_type
|
179 |
179 |
then
|
180 |
|
fprintf fmt "%s" id.var_id
|
|
180 |
if is_memory m id
|
|
181 |
then fprintf fmt "(*%s)" id.var_id
|
|
182 |
else fprintf fmt "%s" id.var_id
|
181 |
183 |
else
|
182 |
|
if List.exists (fun o -> o.var_id = id.var_id) m.mstep.step_outputs (* id is output *)
|
|
184 |
if is_output m id
|
183 |
185 |
then fprintf fmt "*%s" id.var_id
|
184 |
186 |
else fprintf fmt "%s" id.var_id
|
185 |
187 |
|
... | ... | |
193 |
195 |
then
|
194 |
196 |
fprintf fmt "%s" id.var_id
|
195 |
197 |
else
|
196 |
|
if List.exists (fun o -> o.var_id = id.var_id) m.mstep.step_outputs (* id is output *)
|
|
198 |
if is_output m id
|
197 |
199 |
then
|
198 |
200 |
fprintf fmt "%s" id.var_id
|
199 |
201 |
else
|
... | ... | |
227 |
229 |
| Power (v, n) -> assert false
|
228 |
230 |
| LocalVar v -> pp_var fmt v
|
229 |
231 |
| StateVar v ->
|
|
232 |
(* array memory vars are represented by an indirection to a local var with the right type,
|
|
233 |
in order to avoid casting everywhere. *)
|
230 |
234 |
if Types.is_array_type v.var_type
|
231 |
|
then fprintf fmt "*%a" pp_var v
|
|
235 |
then fprintf fmt "%a" pp_var v
|
232 |
236 |
else fprintf fmt "%s->_reg.%a" self pp_var v
|
233 |
237 |
| Fun (n, vl) -> Basic_library.pp_c n (pp_c_val self pp_var) fmt vl
|
234 |
238 |
|