Project

General

Profile

Revision 9603460e src/main_lustre_compiler.ml

View differences:

src/main_lustre_compiler.ml
32 32

  
33 33
(* compile a .lusi header file *)
34 34
let compile_header basename extension =
35
   let header_name = basename ^ extension in
36
   let lusic_ext = extension ^ "c" in
37
   begin
38
     Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v>");
39
     let header = parse_header true header_name in
40
     ignore (check_top_decls header);
41
     create_dest_dir ();
42
     Log.report ~level:1 (fun fmt -> fprintf fmt ".. generating compiled header file %sc@," header_name);
43
     Lusic.write_lusic true header basename lusic_ext;
44
     Lusic.print_lusic_to_h basename lusic_ext;
45
     Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ @]@.")
46
   end
35
  let destname = !Options.dest_dir ^ "/" ^ basename in
36
  let header_name = basename ^ extension in
37
  let lusic_ext = extension ^ "c" in
38
  begin
39
    Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v>");
40
    let header = parse_header true header_name in
41
    ignore (check_top_decls header);
42
    create_dest_dir ();
43
    Log.report ~level:1 (fun fmt -> fprintf fmt ".. generating compiled header file %sc@," header_name);
44
    Lusic.write_lusic true header destname lusic_ext;
45
    Lusic.print_lusic_to_h destname lusic_ext;
46
    Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ @]@.")
47
  end
47 48

  
48 49
(* check whether a source file has a compiled header,
49 50
   if not, generate the compiled header *)
50 51
let compile_source_to_header prog computed_types_env computed_clocks_env basename extension =
51
  let basename' = !Options.dest_dir ^ "/" ^ basename in
52
  let destname = !Options.dest_dir ^ "/" ^ basename in
52 53
  let lusic_ext = extension ^ "c" in
53
  let header_name = basename' ^ lusic_ext in
54
  let header_name = destname ^ lusic_ext in
54 55
  begin
55 56
    if not (Sys.file_exists header_name) then
56 57
      begin
57 58
	Log.report ~level:1 (fun fmt -> fprintf fmt ".. generating compiled header file %s@," header_name);
58
	Lusic.write_lusic false (Lusic.extract_header basename prog) basename lusic_ext;
59
	Lusic.print_lusic_to_h basename lusic_ext
59
	Lusic.write_lusic false (Lusic.extract_header basename prog) destname lusic_ext;
60
	Lusic.print_lusic_to_h destname lusic_ext
60 61
      end
61 62
    else
62
      let lusic = Lusic.read_lusic basename lusic_ext in
63
      let lusic = Lusic.read_lusic destname lusic_ext in
63 64
      if not lusic.Lusic.from_lusi then
64 65
	begin
65 66
	  Log.report ~level:1 (fun fmt -> fprintf fmt ".. generating compiled header file %s@," header_name);
66
       	  Lusic.write_lusic false (Lusic.extract_header basename prog) basename lusic_ext;
67
       	  Lusic.write_lusic false (Lusic.extract_header basename prog) destname lusic_ext;
67 68
(*List.iter (fun top_decl -> Format.eprintf "lusic: %a@." Printers.pp_decl top_decl) lusic.Lusic.contents;*)
68
	  Lusic.print_lusic_to_h basename lusic_ext
69
	  Lusic.print_lusic_to_h destname lusic_ext
69 70
	end
70 71
      else
71 72
	begin
......
290 291
let anonymous filename =
291 292
  let ok_ext, ext = List.fold_left (fun (ok, ext) ext' -> if not ok && Filename.check_suffix filename ext' then true, ext' else ok, ext) (false, "") extensions in
292 293
  if ok_ext then
293
    let basename = Filename.chop_suffix filename ext in
294
    let basename = Filename.chop_suffix (Filename.basename filename) ext in
294 295
    compile basename ext
295 296
  else
296 297
    raise (Arg.Bad ("Can only compile *.lusi, *.lus or *.ec files"))

Also available in: Unified diff