File: gen-compiler_specifics

package info (click to toggle)
ppxlib 0.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 1,284 kB
  • sloc: ml: 17,184; sh: 149; makefile: 36; python: 36
file content (49 lines) | stat: -rw-r--r-- 1,364 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(* -*- tuareg -*- *)

open Printf

let with_file path ~f =
  let oc = open_out_bin path in
  let pr fmt = fprintf oc (fmt ^^ "\n") in
  f pr;
  close_out oc

let () =
  let ver = Scanf.sscanf Sys.argv.(1) "%u.%u" (fun a b -> a, b) in
  with_file Sys.argv.(2) ~f:(fun pr -> (* location_helper *)
    if ver < (4, 06) then
      pr {|
let deprecated loc s =
  Ocaml_common.Location.prerr_warning loc (Ocaml_common.Warnings.Deprecated s)
|};
    if ver < (4, 08) then begin
      pr {|
let print_error ppf loc = Ocaml_common.Location.print_error ppf loc
let error_of_printer ~loc x y = Ocaml_common.Location.error_of_printer loc x y
|};
    end else begin
      pr {|
let print_error ppf loc = Format.fprintf ppf "%%aError:" Ocaml_common.Location.print_loc loc
let error_of_printer ~loc x y = Ocaml_common.Location.error_of_printer ~loc x y
|};
    end);
  with_file Sys.argv.(3) ~f:(fun pr -> (* clflags_helper *)
    if ver < (4, 08) then begin
      pr {|
let is_unsafe () = !Ocaml_common.Clflags.fast[@ocaml.warning "-3"]
|};
    end else begin
      pr {|
let is_unsafe () = !Ocaml_common.Clflags.unsafe[@ocaml.warning "-3"]
|};
    end);
  with_file Sys.argv.(4) ~f:(fun pr -> (* misc_helper *)
    if ver < (4, 10) then begin
      pr {|
let may = Import.Misc.may
|};
    end else begin
      pr {|
let may f = function Some v -> f v | None -> ()
|};
    end)