Project

General

Profile

Revision 55537f48

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
src/machine_code.ml
496 496
  assert (ISet.is_empty m0);
497 497
  assert (init0 = []);
498 498
  assert (Utils.IMap.is_empty j0);
499
  let m, init, j, locals, s = translate_eqs nd (m0, init0, j0, locals0, s0) sorted_eqs in
499
  let m, init, j, locals, s = translate_eqs nd (m0, init0, j0, locals0, []) sorted_eqs in
500 500
  let mmap = Utils.IMap.fold (fun i n res -> (i, n)::res) j [] in
501 501
  {
502 502
    mname = nd;
src/optimize_machine.ml
16 16
open Machine_code 
17 17
open Dimension
18 18

  
19
(* Some optimizations may yield denormalized values. Similar to normalize_expr *)
20
(*
21
let normalize_value v =
22
  let rec norm_cst offset cst =
23
    match cst, offset with
24
    | Const_int   _   , _
25
    | Const_real  _   , _ 
26
    | Const_float _   , _          -> cst
27
    | Const_array args, Index i::q -> if Dimension.is_dimension_const 
28
    | Const_tag of label
29
    | Const_string of string (* used only for annotations *)
30
    | Const_struct of (label * constant) list
31
  let rec norm_value offset v =
32
    match v with
33
    | Cst _ 
34
    | LocalVar _
35
    | StateVar _ -> v
36
    | Fun (id, args) -> Fun (id, List.map normalize_value args)
37
    | Array args -> Array List.map normalize_value args
38
    | Access of value_t * value_t
39
    | Power of value_t * value_t
40
  in norm [] v
41
*)
19

  
42 20
let pp_elim fmt elim =
43 21
  begin
44 22
    Format.fprintf fmt "{ /* elim table: */@.";

Also available in: Unified diff