Project

General

Profile

Revision da07e470 src/backends/C/c_backend_src.ml

View differences:

src/backends/C/c_backend_src.ml
104 104
  var_loops @ int_loops
105 105

  
106 106
(* Prints a one loop variable suffix for arrays *)
107
let pp_loop_var pp_value fmt lv =
107
let pp_loop_var fmt lv =
108 108
 match snd lv with
109 109
 | LVar v -> fprintf fmt "[%s]" v
110 110
 | LInt r -> fprintf fmt "[%d]" !r
111
 | LAcc i -> fprintf fmt "[%a]" (pp_c_val "" pp_value) i
111
 | LAcc i -> fprintf fmt "[%a]" pp_c_dimension (dimension_of_value i)
112 112

  
113 113
(* Prints a suffix of loop variables for arrays *)
114
let pp_suffix pp_value fmt loop_vars =
115
 Utils.fprintf_list ~sep:"" (pp_loop_var pp_value) fmt loop_vars
114
let pp_suffix fmt loop_vars =
115
 Utils.fprintf_list ~sep:"" pp_loop_var fmt loop_vars
116 116

  
117 117
(* Prints a value expression [v], with internal function calls only.
118 118
   [pp_var] is a printer for variables (typically [pp_c_var_read]),
......
146 146
   pp_value_suffix self var_type q pp_value fmt (List.nth vl !r)
147 147
 | loop_var    :: q, Array vl      ->
148 148
   let var_type = Types.array_element_type var_type in
149
   Format.fprintf fmt "(%a[]){%a }%a" (pp_c_type "") var_type (Utils.fprintf_list ~sep:", " (pp_value_suffix self var_type q pp_value)) vl (pp_suffix pp_value) [loop_var]
149
   Format.fprintf fmt "(%a[]){%a }%a" (pp_c_type "") var_type (Utils.fprintf_list ~sep:", " (pp_value_suffix self var_type q pp_value)) vl pp_suffix [loop_var]
150 150
 | _           :: q, Power (v, n)  ->
151 151
   pp_value_suffix self var_type q pp_value fmt v
152 152
 | _               , Fun (n, vl)   ->
......
154 154
 | _               , Access (v, i) ->
155 155
   let var_type = Type_predef.type_array (Dimension.mkdim_var ()) var_type in
156 156
   pp_value_suffix self var_type ((Dimension.mkdim_var (), LAcc i) :: loop_vars) pp_value fmt v
157
 | _               , LocalVar v    -> Format.fprintf fmt "%a%a" pp_value v (pp_suffix pp_value) loop_vars
157
 | _               , LocalVar v    -> Format.fprintf fmt "%a%a" pp_value v pp_suffix loop_vars
158 158
 | _               , StateVar v    ->
159 159
    (* array memory vars are represented by an indirection to a local var with the right type,
160 160
       in order to avoid casting everywhere. *)
161 161
   if Types.is_array_type v.var_type
162
   then Format.fprintf fmt "%a%a" pp_value v (pp_suffix pp_value) loop_vars
163
   else Format.fprintf fmt "%s->_reg.%a%a" self pp_value v (pp_suffix pp_value) loop_vars
162
   then Format.fprintf fmt "%a%a" pp_value v pp_suffix loop_vars
163
   else Format.fprintf fmt "%s->_reg.%a%a" self pp_value v pp_suffix loop_vars
164 164
 | _               , Cst cst       -> pp_c_const_suffix var_type fmt cst
165
 | _               , _             -> (Format.eprintf "internal error: C_backend_src.pp_value_suffix %a %a %a@." Types.print_ty var_type Machine_code.pp_val value (pp_suffix pp_value) loop_vars; assert false)
165
 | _               , _             -> (Format.eprintf "internal error: C_backend_src.pp_value_suffix %a %a %a@." Types.print_ty var_type Machine_code.pp_val value pp_suffix loop_vars; assert false)
166 166

  
167 167
(* type_directed assignment: array vs. statically sized type
168 168
   - [var_type]: type of variable to be assigned

Also available in: Unified diff