Project

General

Profile

Revision 86ae18b7 src/backends/C/c_backend.ml

View differences:

src/backends/C/c_backend.ml
27 27

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

  
33
  let print_header, print_lib_c, print_main_c, print_makefile = funs in
32 34

  
33 35
  (* Generating H file *)
34 36
  let alloc_header_file = destname ^ "_alloc.h" in (* Could be changed *)
......
36 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;
39
  
41

  
40 42
  (* Generating Lib C file *)
41 43
  let source_lib_file = destname ^ ".c" in (* Could be changed *)
42 44
  let source_lib_out = open_out source_lib_file in
......
44 46
  print_lib_c source_lib_fmt basename prog machines dependencies;
45 47
  close_out source_lib_out;
46 48

  
47
  (match !Options.main_node with
48
  | "" ->  () (* No main node: we do not generate main *)
49
  match !Options.main_node with
50
  | "" ->  () (* No main node: we do not generate main nor makefile *)
49 51
  | main_node -> (
50 52
    match Machine_code.get_machine_opt main_node machines with
51 53
    | None -> begin
......
54 56
      raise (Corelang.Error (Location.dummy_loc, LustreSpec.Main_not_found))
55 57
    end
56 58
    | Some m -> begin
57
      let source_main_file = destname ^ "_main.c" in (* Could be changed *)
58 59
      let source_main_out = open_out source_main_file in
59 60
      let source_main_fmt = formatter_of_out_channel source_main_out in
61
      let makefile_out = open_out makefile_file in
62
      let makefile_fmt = formatter_of_out_channel makefile_out in
60 63

  
61 64
      (* Generating Main C file *)
62 65
      print_main_c source_main_fmt m basename prog machines dependencies;
63 66

  
64
      close_out source_main_out;
67
      (* Generating Makefile *)
68
      print_makefile basename main_node dependencies makefile_fmt;
69

  
70
     close_out source_main_out;
71
     close_out makefile_out
72

  
65 73
    end
66
  ));
67

  
68

  
69
  (* Makefiles:
70
     - for the moment two cases
71
     1. Classical Makefile, only when provided with a main node
72
     May contain additional framac eacsl targets
73
     2. Cmake : 2 files
74
         - lustrec-basename.cmake describing all variables
75
         - the main CMakeLists.txt activating the first file
76
     - Later option 1 should be removed
77
  *)
78
  (* Case 1 *)
79
  (match !Options.main_node with
80
  | "" ->  () (* No main node: we do not generate main *)
81
  | main_node -> (
82
    let makefile_file = destname ^ ".makefile" in (* Could be changed *)
83
    let makefile_out = open_out makefile_file in
84
    let makefile_fmt = formatter_of_out_channel makefile_out in
85
    
86
    (* Generating Makefile *)
87
    print_makefile basename main_node dependencies makefile_fmt;
88
    
89
    close_out makefile_out
90
  ));
91
  
92
  (* Case 2 *)
93
  let cmake_file = "lustrec-" ^ basename ^ ".cmake" in
94
  let cmake_file_full_path = !Options.dest_dir ^ "/" ^ cmake_file in
95
  let cmake_out = open_out cmake_file_full_path in
96
  let cmake_fmt = formatter_of_out_channel cmake_out in
97
  (* Generating Makefile *)
98
  print_cmake basename main_node dependencies makefile_fmt;
99
    
100
    close_out makefile_out
101
  
74
  )
102 75

  
103 76
let translate_to_c basename prog machines dependencies =
104 77
  match !Options.spec with
......
112 85
    let module Source = C_backend_src.Main (SourceMod) in
113 86
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
114 87
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
115
    let module CMakefile = C_backend_cmake.Main (MakefileMod) in
116
    
117
    let funs = 
118
      Header.print_alloc_header, 
119
      Source.print_lib_c, 
120
      SourceMain.print_main_c, 
121
      Makefile.print_makefile,
122
      CMakefile.print_makefile
88

  
89
    let funs =
90
      Header.print_alloc_header,
91
      Source.print_lib_c,
92
      SourceMain.print_main_c,
93
      Makefile.print_makefile
123 94
    in
124
    gen_files funs basename prog machines dependencies 
95
    gen_files funs basename prog machines dependencies
125 96

  
126 97
  end
127 98
  | "acsl" -> begin
......
135 106
    let module Source = C_backend_src.Main (SourceMod) in
136 107
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
137 108
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
138
    let module CMakefile = C_backend_cmake.Main (MakefileMod) in
139
    
140
    let funs = 
141
      Header.print_alloc_header, 
109

  
110
    let funs =
111
      Header.print_alloc_header,
142 112
      Source.print_lib_c,
143 113
      SourceMain.print_main_c,
144
      Makefile.print_makefile,
145
      CMakefile.print_makefile 
114
      Makefile.print_makefile
146 115
    in
147
    gen_files funs basename prog machines dependencies 
116
    gen_files funs basename prog machines dependencies
148 117

  
149 118
  end
150 119
  | "c" -> begin

Also available in: Unified diff