Project

General

Profile

Revision 3b2bd83d src/backends/C/c_backend.ml

View differences:

src/backends/C/c_backend.ml
25 25
  )
26 26
*)
27 27

  
28
let gen_files funs basename prog machines dependencies header_file source_lib_file source_main_file makefile_file machines =
29

  
30
  let header_out = open_out header_file in
31
  let header_fmt = formatter_of_out_channel header_out in
32
  let source_lib_out = open_out source_lib_file in
33
  let source_lib_fmt = formatter_of_out_channel source_lib_out in
34

  
28
let gen_files funs basename prog machines dependencies =
29
  let destname = !Options.dest_dir ^ "/" ^ basename in
30
  let source_main_file = destname ^ "_main.c" in (* Could be changed *)
31
  let makefile_file = destname ^ ".makefile" in (* Could be changed *)
32
  
35 33
  let print_header, print_lib_c, print_main_c, print_makefile = funs in
34

  
36 35
  (* Generating H file *)
36
  let alloc_header_file = destname ^ "_alloc.h" in (* Could be changed *)
37
  let header_out = open_out alloc_header_file in
38
  let header_fmt = formatter_of_out_channel header_out in
37 39
  print_header header_fmt basename prog machines dependencies;
38
 
40
  close_out header_out;
41
  
39 42
  (* Generating Lib C file *)
43
  let source_lib_file = destname ^ ".c" in (* Could be changed *)
44
  let source_lib_out = open_out source_lib_file in
45
  let source_lib_fmt = formatter_of_out_channel source_lib_out in
40 46
  print_lib_c source_lib_fmt basename prog machines dependencies;
41
 
42
  close_out header_out;
43 47
  close_out source_lib_out;
44 48

  
45 49
  match !Options.main_node with
46
  | "" ->  () (* No main node: we do not genenrate main nor makefile *)
50
  | "" ->  () (* No main node: we do not generate main nor makefile *)
47 51
  | main_node -> (
48 52
    match Machine_code.get_machine_opt main_node machines with
49
    | None -> Format.eprintf "Unable to find a main node named %s@.@?" main_node; assert false
53
    | None -> begin
54
      Global.main_node := main_node;
55
      Format.eprintf "Code generation error: %a@." Corelang.pp_error LustreSpec.Main_not_found;
56
      raise (Corelang.Error (Location.dummy_loc, LustreSpec.Main_not_found))
57
    end
50 58
    | Some m -> begin
51 59
      let source_main_out = open_out source_main_file in
52 60
      let source_main_fmt = formatter_of_out_channel source_main_out in
......
57 65
      print_main_c source_main_fmt m basename prog machines dependencies;
58 66
      
59 67
      (* Generating Makefile *)
60
     print_makefile basename main_node dependencies makefile_fmt;
68
      print_makefile basename main_node dependencies makefile_fmt;
61 69

  
62 70
     close_out source_main_out;
63 71
     close_out makefile_out
......
65 73
    end
66 74
  )
67 75

  
68
let translate_to_c header source_lib source_main makefile basename prog machines dependencies =
76
let translate_to_c basename prog machines dependencies =
69 77
  match !Options.spec with
70 78
  | "no" -> begin
71 79
    let module HeaderMod = C_backend_header.EmptyMod in
......
84 92
      SourceMain.print_main_c, 
85 93
      Makefile.print_makefile 
86 94
    in
87
    gen_files 
88
      funs basename prog machines dependencies 
89
      header source_lib source_main makefile machines
95
    gen_files funs basename prog machines dependencies 
90 96

  
91 97
  end
92 98
  | "acsl" -> begin
......
107 113
      SourceMain.print_main_c,
108 114
      Makefile.print_makefile 
109 115
    in
110
    gen_files
111
      funs basename prog machines dependencies
112
      header source_lib source_main makefile machines
116
    gen_files funs basename prog machines dependencies 
113 117

  
114 118
  end
115 119
  | "c" -> begin

Also available in: Unified diff