Project

General

Profile

« Previous | Next » 

Revision ca7ff3f7

Added by LĂ©lio Brun 7 months ago

reformatting

View differences:

src/backends/C/c_backend.ml
11 11

  
12 12
open Utils.Format
13 13
open C_backend_mauve
14

  
14 15
(******************************************************************************)
15 16
(*                        Translation function                                *)
16 17
(******************************************************************************)
17
(* USELESS
18
let makefile_opt print basename dependencies makefile_fmt machines =
19
  (* If a main node is identified, generate a main target for it *)
20
  match !Options.main_node with
21
  | "" ->  ()
22
  | main_node -> (
23
    match Machine_code.get_machine_opt main_node machines with
24
    | None -> Format.eprintf "Unable to find a main node named %s@.@?" main_node; ()
25
    | Some _ -> print basename !Options.main_node dependencies makefile_fmt
26
  )
27
*)
28

  
29
let c_or_cpp f =
30
  if !Options.cpp then f ^ ".cpp" else f ^ ".c" (* Could be changed *)
18
(* USELESS let makefile_opt print basename dependencies makefile_fmt machines =
19
   (* If a main node is identified, generate a main target for it *) match
20
   !Options.main_node with | "" -> () | main_node -> ( match
21
   Machine_code.get_machine_opt main_node machines with | None -> Format.eprintf
22
   "Unable to find a main node named %s@.@?" main_node; () | Some _ -> print
23
   basename !Options.main_node dependencies makefile_fmt ) *)
24

  
25
let c_or_cpp f = if !Options.cpp then f ^ ".cpp" else f ^ ".c"
26
(* Could be changed *)
31 27

  
32 28
let with_main_node machines node f =
33 29
  if node <> "" then
......
42 38
      f m
43 39

  
44 40
let gen_files
45
    (print_alloc_header, print_lib_c, print_main_c, print_makefile, preprocess (* , print_cmake *))
46
    basename prog machines dependencies =
41
    ( print_alloc_header,
42
      print_lib_c,
43
      print_main_c,
44
      print_makefile,
45
      preprocess
46
    (* , print_cmake *) ) basename prog machines dependencies =
47 47
  let destname = !Options.dest_dir ^ "/" ^ basename in
48
  
48

  
49 49
  let machines, spec = preprocess machines in
50 50

  
51 51
  (* Generating H alloc file *)
52
  let alloc_header_file = destname ^ "_alloc.h" in (* Could be changed *)
52
  let alloc_header_file = destname ^ "_alloc.h" in
53
  (* Could be changed *)
53 54
  with_out_file alloc_header_file (fun header_fmt ->
54 55
      print_alloc_header header_fmt basename prog machines dependencies spec);
55 56

  
......
79 80
          print_mauve_fsm source_mauve_fmt m));
80 81

  
81 82
  (* Generating Makefile *)
82
  (* Makefiles:
83
     - for the moment two cases
84
     1. Classical Makefile, only when provided with a main node
85
     May contain additional framac eacsl targets
86
     2. Cmake : 2 files
87
         - lustrec-basename.cmake describing all variables
88
         - the main CMakeLists.txt activating the first file
89
     - Later option 1 should be removed
90
  *)
83
  (* Makefiles: - for the moment two cases 1. Classical Makefile, only when
84
     provided with a main node May contain additional framac eacsl targets 2.
85
     Cmake : 2 files - lustrec-basename.cmake describing all variables - the
86
     main CMakeLists.txt activating the first file - Later option 1 should be
87
     removed *)
91 88
  (* Case 1 *)
92 89
  if main_node <> "" then
93
    let makefile_file = destname ^ ".makefile" in (* Could be changed *)
90
    let makefile_file = destname ^ ".makefile" in
91
    (* Could be changed *)
94 92
    with_out_file makefile_file (fun makefile_fmt ->
95 93
        print_makefile basename main_node dependencies makefile_fmt)
96 94

  
97
  (* (\* Case 2 *\) *)
98
  (* let cmake_file = "lustrec-" ^ basename ^ ".cmake" in *)
99
  (* let cmake_file_full_path = !Options.dest_dir ^ "/" ^ cmake_file in *)
100
  (* let cmake_out = open_out cmake_file_full_path in *)
101
  (* let cmake_fmt = formatter_of_out_channel cmake_out in *)
102
  (* (\* Generating Makefile *\) *)
103
  (* print_cmake basename main_node dependencies makefile_fmt; *)
104
    
105
  (*   close_out makefile_out *)
106
  
95
(* (\* Case 2 *\) *)
96
(* let cmake_file = "lustrec-" ^ basename ^ ".cmake" in *)
97
(* let cmake_file_full_path = !Options.dest_dir ^ "/" ^ cmake_file in *)
98
(* let cmake_out = open_out cmake_file_full_path in *)
99
(* let cmake_fmt = formatter_of_out_channel cmake_out in *)
100
(* (\* Generating Makefile *\) *)
101
(* print_cmake basename main_node dependencies makefile_fmt; *)
102

  
103
(* close_out makefile_out *)
104

  
107 105
let print_c_header basename =
108
  let header_m = match !Options.spec with
106
  let header_m =
107
    match !Options.spec with
109 108
    | "no" ->
110
      C_backend_header.(module EmptyMod : MODIFIERS_HDR)
111

  
109
      C_backend_header.((module EmptyMod : MODIFIERS_HDR))
112 110
    | "acsl" ->
113
      C_backend_header.(module C_backend_spec.HdrMod : MODIFIERS_HDR)
114

  
115
    | "c" -> assert false        (* not implemented yet *)
116

  
117
    | _ -> assert false
111
      C_backend_header.((module C_backend_spec.HdrMod : MODIFIERS_HDR))
112
    | "c" ->
113
      assert false (* not implemented yet *)
114
    | _ ->
115
      assert false
118 116
  in
119
  let module Header = C_backend_header.Main (val header_m) in
117
  let module Header = C_backend_header.Main ((val header_m)) in
120 118
  let destname = !Options.dest_dir ^ "/" ^ basename in
121 119
  (* Generating H file *)
122 120
  let lusic = Lusic.read_lusic destname ".lusic" in
......
129 127
  let header_m, source_m, source_main_m, makefile_m, preprocess =
130 128
    match !Options.spec with
131 129
    | "no" ->
132
      C_backend_header.(module EmptyMod : MODIFIERS_HDR),
133
      C_backend_src.(module EmptyMod : MODIFIERS_SRC),
134
      C_backend_main.(module EmptyMod : MODIFIERS_MAINSRC),
135
      C_backend_makefile.(module EmptyMod : MODIFIERS_MKF),
136
      fun m -> m, []
137

  
130
      ( C_backend_header.((module EmptyMod : MODIFIERS_HDR)),
131
        C_backend_src.((module EmptyMod : MODIFIERS_SRC)),
132
        C_backend_main.((module EmptyMod : MODIFIERS_MAINSRC)),
133
        C_backend_makefile.((module EmptyMod : MODIFIERS_MKF)),
134
        fun m -> m, [] )
138 135
    | "acsl" ->
139 136
      let open C_backend_spec in
140
      C_backend_header.(module HdrMod : MODIFIERS_HDR),
141
      C_backend_src.(module SrcMod : MODIFIERS_SRC),
142
      C_backend_main.(module EmptyMod : MODIFIERS_MAINSRC),
143
      C_backend_makefile.(module MakefileMod : MODIFIERS_MKF),
144
      preprocess_acsl
145

  
146
    | "c" -> assert false        (* not implemented yet *)
147

  
148
    | _ -> assert false
137
      ( C_backend_header.((module HdrMod : MODIFIERS_HDR)),
138
        C_backend_src.((module SrcMod : MODIFIERS_SRC)),
139
        C_backend_main.((module EmptyMod : MODIFIERS_MAINSRC)),
140
        C_backend_makefile.((module MakefileMod : MODIFIERS_MKF)),
141
        preprocess_acsl )
142
    | "c" ->
143
      assert false (* not implemented yet *)
144
    | _ ->
145
      assert false
149 146
  in
150
  let module Header = C_backend_header.Main (val header_m) in
151
  let module Source = C_backend_src.Main (val source_m) in
152
  let module SourceMain = C_backend_main.Main (val source_main_m) in
153
  let module Makefile = C_backend_makefile.Main (val makefile_m) in
147
  let module Header = C_backend_header.Main ((val header_m)) in
148
  let module Source = C_backend_src.Main ((val source_m)) in
149
  let module SourceMain = C_backend_main.Main ((val source_main_m)) in
150
  let module Makefile = C_backend_makefile.Main ((val makefile_m)) in
154 151
  (* let module CMakefile = C_backend_cmake.Main (MakefileMod) in *)
155 152
  let funs =
156
    Header.print_alloc_header,
157
    Source.print_lib_c,
158
    SourceMain.print_main_c,
159
    Makefile.print_makefile,
160
    preprocess
153
    ( Header.print_alloc_header,
154
      Source.print_lib_c,
155
      SourceMain.print_main_c,
156
      Makefile.print_makefile,
157
      preprocess )
161 158
    (* CMakefile.print_makefile *)
162 159
  in
163 160
  if generate_c_header then print_c_header basename;
164 161
  gen_files funs basename prog machines dependencies
165 162

  
166

  
167 163
(* Local Variables: *)
168 164
(* compile-command:"make -C ../../.." *)
169 165
(* End: *)

Also available in: Unified diff