Project

General

Profile

« Previous | Next » 

Revision ea8f51ae

Added by Pierre-Loïc Garoche about 6 years ago

Basic library printers moved into backend specific printer files

View differences:

src/backends/C/c_backend_common.ml
108 108
let pp_machine_clear_name fmt id = fprintf fmt "%s_clear" id
109 109
let pp_machine_step_name fmt id = fprintf fmt "%s_step" id
110 110

  
111
let pp_basic_lib_fun i pp_val fmt vl =
112
  match i, vl with
113
  (*  | "ite", [v1; v2; v3] -> Format.fprintf fmt "(%a?(%a):(%a))" pp_val v1 pp_val v2 pp_val v3 *)
114
  | "uminus", [v] -> Format.fprintf fmt "(- %a)" pp_val v
115
  | "not", [v] -> Format.fprintf fmt "(!%a)" pp_val v
116
  | "impl", [v1; v2] -> Format.fprintf fmt "(!%a || %a)" pp_val v1 pp_val v2
117
  | "=", [v1; v2] -> Format.fprintf fmt "(%a == %a)" pp_val v1 pp_val v2
118
  | "mod", [v1; v2] -> Format.fprintf fmt "(%a %% %a)" pp_val v1 pp_val v2
119
  | "equi", [v1; v2] -> Format.fprintf fmt "(!%a == !%a)" pp_val v1 pp_val v2
120
  | "xor", [v1; v2] -> Format.fprintf fmt "(!%a != !%a)" pp_val v1 pp_val v2
121
  | _, [v1; v2] -> Format.fprintf fmt "(%a %s %a)" pp_val v1 i pp_val v2
122
  | _ -> (Format.eprintf "internal error: Basic_library.pp_c %s@." i; assert false)
123

  
124

  
111 125
let rec pp_c_dimension fmt dim =
112 126
  match dim.Dimension.dim_desc with
113 127
  | Dimension.Dident id       ->
114
    fprintf fmt "%s" id
128
     fprintf fmt "%s" id
115 129
  | Dimension.Dint i          ->
116
    fprintf fmt "%d" i
130
     fprintf fmt "%d" i
117 131
  | Dimension.Dbool b         ->
118
    fprintf fmt "%B" b
132
     fprintf fmt "%B" b
119 133
  | Dimension.Dite (i, t, e)  ->
120
    fprintf fmt "((%a)?%a:%a)"
134
     fprintf fmt "((%a)?%a:%a)"
121 135
       pp_c_dimension i pp_c_dimension t pp_c_dimension e
122
 | Dimension.Dappl (f, args) ->
123
     fprintf fmt "%a" (Basic_library.pp_c f pp_c_dimension) args
124
 | Dimension.Dlink dim' -> fprintf fmt "%a" pp_c_dimension dim'
125
 | Dimension.Dvar       -> fprintf fmt "_%s" (Utils.name_of_dimension dim.Dimension.dim_id)
126
 | Dimension.Dunivar    -> fprintf fmt "'%s" (Utils.name_of_dimension dim.Dimension.dim_id)
136
  | Dimension.Dappl (f, args) ->
137
     fprintf fmt "%a" (pp_basic_lib_fun f pp_c_dimension) args
138
  | Dimension.Dlink dim' -> fprintf fmt "%a" pp_c_dimension dim'
139
  | Dimension.Dvar       -> fprintf fmt "_%s" (Utils.name_of_dimension dim.Dimension.dim_id)
140
  | Dimension.Dunivar    -> fprintf fmt "'%s" (Utils.name_of_dimension dim.Dimension.dim_id)
127 141

  
128 142
let is_basic_c_type t =
129 143
  Types.is_int_type t || Types.is_real_type t || Types.is_bool_type t
......
190 204
    | Const_struct fl -> fprintf fmt "{%a }" (Utils.fprintf_list ~sep:", " (fun fmt (f, c) -> pp_c_const fmt c)) fl
191 205
    | Const_string _ -> assert false (* string occurs in annotations not in C *)
192 206

  
207
       
193 208
(* Prints a value expression [v], with internal function calls only.
194 209
   [pp_var] is a printer for variables (typically [pp_c_var_read]),
195 210
   but an offset suffix may be added for array variables
......
207 222
    if Types.is_array_type v.var_type && not (Types.is_real_type v.var_type && !Options.mpfr)
208 223
    then fprintf fmt "%a" pp_var v
209 224
    else fprintf fmt "%s->_reg.%a" self pp_var v
210
  | Fun (n, vl)   -> Basic_library.pp_c n (pp_c_val self pp_var) fmt vl
225
  | Fun (n, vl)   -> pp_basic_lib_fun n (pp_c_val self pp_var) fmt vl
211 226

  
212 227
(* Access to the value of a variable:
213 228
   - if it's not a scalar output, then its name is enough

Also available in: Unified diff