Revision 51768260
Added by Xavier Thirioux about 8 years ago
src/c_backend.ml | ||
---|---|---|
130 | 130 |
as it is the case for generics |
131 | 131 |
*) |
132 | 132 |
let pp_c_decl_input_var fmt id = |
133 |
if !Options.ansi && Types.is_array_type id.var_type
|
|
133 |
if !Options.ansi && Types.is_address_type id.var_type
|
|
134 | 134 |
then pp_c_type (sprintf "(*%s)" id.var_id) fmt (Types.array_base_type id.var_type) |
135 | 135 |
else pp_c_type id.var_id fmt id.var_type |
136 | 136 |
|
137 | 137 |
(* Declaration of an output variable: |
138 | 138 |
- if its type is scalar, then pass its address |
139 |
- if its type is array/matrix/etc, then declare it as a mere pointer, |
|
139 |
- if its type is array/matrix/struct/etc, then declare it as a mere pointer,
|
|
140 | 140 |
in order to cope with unknown/parametric array dimensions, |
141 | 141 |
as it is the case for generics |
142 | 142 |
*) |
143 | 143 |
let pp_c_decl_output_var fmt id = |
144 |
if (not !Options.ansi) && Types.is_array_type id.var_type
|
|
144 |
if (not !Options.ansi) && Types.is_address_type id.var_type
|
|
145 | 145 |
then pp_c_type id.var_id fmt id.var_type |
146 | 146 |
else pp_c_type (sprintf "(*%s)" id.var_id) fmt (Types.array_base_type id.var_type) |
147 | 147 |
|
... | ... | |
175 | 175 |
- moreover, cast arrays variables into their original array type. |
176 | 176 |
*) |
177 | 177 |
let pp_c_var_read m fmt id = |
178 |
if Types.is_array_type id.var_type
|
|
178 |
if Types.is_address_type id.var_type
|
|
179 | 179 |
then |
180 | 180 |
fprintf fmt "%s" id.var_id |
181 | 181 |
else |
... | ... | |
189 | 189 |
despite its scalar Lustre type) |
190 | 190 |
*) |
191 | 191 |
let pp_c_var_write m fmt id = |
192 |
if Types.is_array_type id.var_type
|
|
192 |
if Types.is_address_type id.var_type
|
|
193 | 193 |
then |
194 | 194 |
fprintf fmt "%s" id.var_id |
195 | 195 |
else |
... | ... | |
861 | 861 |
let print_main_header fmt = |
862 | 862 |
fprintf fmt "#include <stdio.h>@.#include <unistd.h>@.#include \"%s/include/lustrec/io_frontend.h\"@." Version.prefix |
863 | 863 |
|
864 |
let rec pp_c_struct_type_field filename cpt var fmt (label, tdesc) =
|
|
865 |
fprintf fmt "%a %a" (pp_c_type_decl filename cpt var) tdesc pp_print_string label
|
|
864 |
let rec pp_c_struct_type_field filename cpt fmt (label, tdesc) = |
|
865 |
fprintf fmt "%a;" (pp_c_type_decl filename cpt label) tdesc
|
|
866 | 866 |
and pp_c_type_decl filename cpt var fmt tdecl = |
867 | 867 |
match tdecl with |
868 | 868 |
| Tydec_any -> assert false |
... | ... | |
881 | 881 |
| Tydec_struct fl -> |
882 | 882 |
begin |
883 | 883 |
incr cpt; |
884 |
fprintf fmt "struct _struct_%s_%d { %a } %s" filename !cpt (Utils.fprintf_list ~sep:"; " (pp_c_struct_type_field filename cpt var)) fl var
|
|
884 |
fprintf fmt "struct _struct_%s_%d { %a } %s" filename !cpt (Utils.fprintf_list ~sep:" " (pp_c_struct_type_field filename cpt)) fl var
|
|
885 | 885 |
end |
886 | 886 |
|
887 | 887 |
let print_type_definitions fmt filename = |
Also available in: Unified diff
work in progress for struct types...