Project

General

Profile

Revision 7ab1c5bd

View differences:

src/backends/C/c_backend_common.ml
647 647
    aux [] fmt (List.hd inputs).value_type
648 648
  end
649 649

  
650

  
651
(*** Common functions for main ***)
652

  
653
let print_put_var fmt file_suffix name var_type var_id =
654
  match (Types.unclock_type var_type).Types.tdesc with
655
  | Types.Tint -> fprintf fmt "_put_int(f_out%s, \"%s\", %s)" file_suffix name var_id
656
  | Types.Tbool -> fprintf fmt "_put_bool(f_out%s, \"%s\", %s)" file_suffix name var_id
657
  | Types.Treal when !Options.mpfr -> fprintf fmt "_put_double(f_out%s, \"%s\", mpfr_get_d(%s, %s), %i)" file_suffix name var_id (Mpfr.mpfr_rnd ()) !Options.print_prec_double
658
  | Types.Treal -> fprintf fmt "_put_double(f_out%s, \"%s\", %s, %i)" file_suffix name var_id !Options.print_prec_double
659
  | _ -> Format.eprintf "Impossible to print the _put_xx for type %a@.@?" Types.print_ty var_type; assert false
660

  
650 661
(* Local Variables: *)
651 662
(* compile-command:"make -C ../../.." *)
652 663
(* End: *)
src/backends/C/c_backend_main.ml
53 53

  
54 54
let print_put_outputs fmt m = 
55 55
  let po fmt (id, o', o) =
56
    match (Types.unclock_type o.var_type).Types.tdesc with
57
    | Types.Tint -> fprintf fmt "_put_int(f_out%i, \"%s\", %s)" id o'.var_id o.var_id
58
    | Types.Tbool -> fprintf fmt "_put_bool(f_out%i, \"%s\", %s)" id o'.var_id o.var_id
59
    | Types.Treal when !Options.mpfr -> fprintf fmt "_put_double(f_out%i, \"%s\", mpfr_get_d(%s, %s))" id o'.var_id o.var_id (Mpfr.mpfr_rnd ())
60
    | Types.Treal -> fprintf fmt "_put_double(f_out%i, \"%s\", %s)" id o'.var_id o.var_id
61
    | _ -> assert false
56
    let suff = string_of_int id in
57
    print_put_var fmt suff o'.var_id o.var_type o.var_id
62 58
  in
63 59
  Utils.List.iteri2 (fun idx v' v -> fprintf fmt "@ %a;" po ((idx+1), v', v)) m.mname.node_outputs m.mstep.step_outputs
64 60

  
......
158 154
    else "main_mem" in
159 155
  fprintf fmt "@[<v 2>int main (int argc, char *argv[]) {@ ";
160 156
  print_main_inout_declaration basename fmt m;
157
  Plugins.c_backend_main_loop_body_prefix basename mname fmt ();
161 158
  print_main_memory_allocation mname main_mem fmt m;
162 159
  if !Options.mpfr then
163 160
    begin
src/pluginType.ml
6 6
  val check_force_stateful : unit -> bool
7 7
  val refine_machine_code: LustreSpec.top_decl list ->
8 8
    Machine_code.machine_t list -> Machine_code.machine_t list
9
  val c_backend_main_loop_body_prefix : string -> string -> Format.formatter ->  unit -> unit
9 10
  val c_backend_main_loop_body_suffix : Format.formatter ->  unit -> unit
10 11
end
11 12

  
......
13 14
struct
14 15
  let check_force_stateful () = false
15 16
  let refine_machine_code prog machines = machines
17
  let c_backend_main_loop_body_prefix basename mname fmt () = ()
16 18
  let c_backend_main_loop_body_suffix fmt () = ()
17 19
end
src/plugins.ml
25 25
  ) machine_code plugins
26 26

  
27 27

  
28
let c_backend_main_loop_body_prefix basename mname fmt () = 
29
  List.iter (fun (m: (module PluginType.PluginType)) -> 
30
    let module M = (val m : PluginType.PluginType) in
31
    M.c_backend_main_loop_body_prefix basename mname fmt ()) plugins
32

  
28 33
let c_backend_main_loop_body_suffix fmt () = 
29 34
  List.iter (fun (m: (module PluginType.PluginType)) -> 
30 35
    let module M = (val m : PluginType.PluginType) in

Also available in: Unified diff