Project

General

Profile

Revision 1e48ef45 src/backends/C/c_backend_common.ml

View differences:

src/backends/C/c_backend_common.ml
94 94
let pp_c_dimension fmt d =
95 95
 fprintf fmt "%a" Dimension.pp_dimension d
96 96

  
97
let is_basic_c_type t =
98
  match (Types.repr t).Types.tdesc with
99
  | Types.Tbool | Types.Treal | Types.Tint  -> true
100
  | _                                       -> false
101

  
102
let pp_basic_c_type fmt t =
103
  match (Types.repr t).Types.tdesc with
104
  | Types.Tbool           -> fprintf fmt "_Bool"
105
  | Types.Treal           -> fprintf fmt "double"
106
  | Types.Tint            -> fprintf fmt "int"
107
  | _ -> assert false (* Not a basic C type. Do not handle arrays or pointers *)
108

  
97 109
let pp_c_type var fmt t =
98 110
  let rec aux t pp_suffix =
99
  match (Types.repr t).Types.tdesc with
100
  | Types.Tclock t'       -> aux t' pp_suffix
101
  | Types.Tbool           -> fprintf fmt "_Bool %s%a" var pp_suffix ()
102
  | Types.Treal           -> fprintf fmt "double %s%a" var pp_suffix ()
103
  | Types.Tint            -> fprintf fmt "int %s%a" var pp_suffix ()
104
  | Types.Tarray (d, t')  ->
105
    let pp_suffix' fmt () = fprintf fmt "%a[%a]" pp_suffix () pp_c_dimension d in
106
    aux t' pp_suffix'
107
  | Types.Tstatic (_, t') -> fprintf fmt "const "; aux t' pp_suffix
108
  | Types.Tconst ty       -> fprintf fmt "%s %s" ty var
109
  | Types.Tarrow (_, _)   -> fprintf fmt "void (*%s)()" var
110
  | _                     -> eprintf "internal error: pp_c_type %a@." Types.print_ty t; assert false
111
    match (Types.repr t).Types.tdesc with
112
    | Types.Tclock t'       -> aux t' pp_suffix
113
    | Types.Tbool | Types.Treal | Types.Tint 
114
                            -> fprintf fmt "%a %s%a" pp_basic_c_type t var pp_suffix ()
115
    | Types.Tarray (d, t')  ->
116
      let pp_suffix' fmt () = fprintf fmt "%a[%a]" pp_suffix () pp_c_dimension d in
117
      aux t' pp_suffix'
118
    | Types.Tstatic (_, t') -> fprintf fmt "const "; aux t' pp_suffix
119
    | Types.Tconst ty       -> fprintf fmt "%s %s" ty var
120
    | Types.Tarrow (_, _)   -> fprintf fmt "void (*%s)()" var
121
    | _                     -> eprintf "internal error: pp_c_type %a@." Types.print_ty t; assert false
111 122
  in aux t (fun fmt () -> ())
112 123

  
113 124
let rec pp_c_initialize fmt t = 
......
319 330
    pp_machine_memtype_name name
320 331
    self
321 332

  
333
let print_stateless_C_prototype fmt (name, inputs, outputs) =
334
  let output = 
335
    match outputs with
336
    | [hd] -> hd
337
    | _ -> assert false
338
  in
339
  fprintf fmt "%a %s (@[<v>@[%a@]@,@])"
340
    pp_basic_c_type output.var_type
341
    name
342
    (Utils.fprintf_list ~sep:",@ " pp_c_decl_input_var) inputs
343
    
344
    
345

  
322 346
let print_import_prototype fmt (_, s, _) =
323 347
  fprintf fmt "#include \"%s.h\"@," s
324 348

  

Also available in: Unified diff