Project

General

Profile

« Previous | Next » 

Revision bb1b5e04

Added by Pierre-Loïc Garoche over 7 years ago

Ongoing work on c backend for makefile. Does not compile yet

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
  let source_main_file = destname ^ "_main.c" in (* Could be changed *)
31
  let makefile_file = destname ^ ".makefile" in (* Could be changed *)
32 30
  
33
  let print_header, print_lib_c, print_main_c, print_makefile = funs in
31
  let print_header, print_lib_c, print_main_c, print_makefile, print_cmake = funs in
34 32

  
35 33
  (* Generating H file *)
36 34
  let alloc_header_file = destname ^ "_alloc.h" in (* Could be changed *)
......
46 44
  print_lib_c source_lib_fmt basename prog machines dependencies;
47 45
  close_out source_lib_out;
48 46

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

  
64 61
      (* Generating Main C file *)
65 62
      print_main_c source_main_fmt m basename prog machines dependencies;
66
      
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 63

  
64
      close_out source_main_out;
73 65
    end
74
  )
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
  
75 102

  
76 103
let translate_to_c basename prog machines dependencies =
77 104
  match !Options.spec with
......
85 112
    let module Source = C_backend_src.Main (SourceMod) in
86 113
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
87 114
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
88

  
115
    let module CMakefile = C_backend_cmake.Main (MakefileMod) in
116
    
89 117
    let funs = 
90 118
      Header.print_alloc_header, 
91 119
      Source.print_lib_c, 
92 120
      SourceMain.print_main_c, 
93
      Makefile.print_makefile 
121
      Makefile.print_makefile,
122
      CMakefile.print_makefile
94 123
    in
95 124
    gen_files funs basename prog machines dependencies 
96 125

  
......
106 135
    let module Source = C_backend_src.Main (SourceMod) in
107 136
    let module SourceMain = C_backend_main.Main (SourceMainMod) in
108 137
    let module Makefile = C_backend_makefile.Main (MakefileMod) in
109

  
138
    let module CMakefile = C_backend_cmake.Main (MakefileMod) in
139
    
110 140
    let funs = 
111 141
      Header.print_alloc_header, 
112 142
      Source.print_lib_c,
113 143
      SourceMain.print_main_c,
114
      Makefile.print_makefile 
144
      Makefile.print_makefile,
145
      CMakefile.print_makefile 
115 146
    in
116 147
    gen_files funs basename prog machines dependencies 
117 148

  

Also available in: Unified diff