Revision a1daa793 src/backends/C/c_backend_common.ml
src/backends/C/c_backend_common.ml | ||
---|---|---|
92 | 92 |
let pp_machine_reset_name fmt id = fprintf fmt "%s_reset" id |
93 | 93 |
let pp_machine_step_name fmt id = fprintf fmt "%s_step" id |
94 | 94 |
|
95 |
let pp_c_dimension fmt d = |
|
96 |
fprintf fmt "%a" Dimension.pp_dimension d |
|
95 |
let rec pp_c_dimension fmt dim = |
|
96 |
match dim.Dimension.dim_desc with |
|
97 |
| Dimension.Dident id -> |
|
98 |
fprintf fmt "%s" id |
|
99 |
| Dimension.Dint i -> |
|
100 |
fprintf fmt "%d" i |
|
101 |
| Dimension.Dbool b -> |
|
102 |
fprintf fmt "%B" b |
|
103 |
| Dimension.Dite (i, t, e) -> |
|
104 |
fprintf fmt "((%a)?%a:%a)" |
|
105 |
pp_c_dimension i pp_c_dimension t pp_c_dimension e |
|
106 |
| Dimension.Dappl (f, args) -> |
|
107 |
fprintf fmt "%a" (Basic_library.pp_c f pp_c_dimension) args |
|
108 |
| Dimension.Dlink dim' -> fprintf fmt "%a" pp_c_dimension dim' |
|
109 |
| Dimension.Dvar -> fprintf fmt "_%s" (Utils.name_of_dimension dim.Dimension.dim_id) |
|
110 |
| Dimension.Dunivar -> fprintf fmt "'%s" (Utils.name_of_dimension dim.Dimension.dim_id) |
|
97 | 111 |
|
98 | 112 |
let is_basic_c_type t = |
99 | 113 |
match (Types.repr t).Types.tdesc with |
... | ... | |
119 | 133 |
| Types.Tstatic (_, t') -> fprintf fmt "const "; aux t' pp_suffix |
120 | 134 |
| Types.Tconst ty -> fprintf fmt "%s %s" ty var |
121 | 135 |
| Types.Tarrow (_, _) -> fprintf fmt "void (*%s)()" var |
122 |
| _ -> eprintf "internal error: pp_c_type %a@." Types.print_ty t; assert false |
|
136 |
| _ -> eprintf "internal error: C_backend_common.pp_c_type %a@." Types.print_ty t; assert false
|
|
123 | 137 |
in aux t (fun fmt () -> ()) |
124 | 138 |
|
125 | 139 |
let rec pp_c_initialize fmt t = |
... | ... | |
138 | 152 |
let pp_c_tag fmt t = |
139 | 153 |
pp_print_string fmt (if t = tag_true then "1" else if t = tag_false then "0" else t) |
140 | 154 |
|
155 |
|
|
141 | 156 |
(* Prints a constant value *) |
142 | 157 |
let rec pp_c_const fmt c = |
143 | 158 |
match c with |
... | ... | |
154 | 169 |
but an offset suffix may be added for array variables |
155 | 170 |
*) |
156 | 171 |
let rec pp_c_val self pp_var fmt v = |
172 |
(*Format.eprintf "C_backend_common.pp_c_val %a@." pp_val v;*) |
|
157 | 173 |
match v with |
158 | 174 |
| Cst c -> pp_c_const fmt c |
159 | 175 |
| Array vl -> fprintf fmt "{%a}" (Utils.fprintf_list ~sep:", " (pp_c_val self pp_var)) vl |
160 | 176 |
| Access (t, i) -> fprintf fmt "%a[%a]" (pp_c_val self pp_var) t (pp_c_val self pp_var) i |
161 |
| Power (v, n) -> assert false
|
|
177 |
| Power (v, n) -> (Format.eprintf "internal error: C_backend_common.pp_c_val %a@." pp_val v; assert false)
|
|
162 | 178 |
| LocalVar v -> pp_var fmt v |
163 | 179 |
| StateVar v -> |
164 | 180 |
(* array memory vars are represented by an indirection to a local var with the right type, |
Also available in: Unified diff