Jbuilder and ppx: see generated code

Hi everyone.

Could someone tell me how I can see the generated code when I use jbuilder and PPX? And in general (with ocamlc/ocamlopt), which arguments could I use to see the generated code?

Thanks.

Danny.

2 Likes

The -dsource argument for ocamlc/ocamlopt shows you the generated code by the PPX like:

type t = int [@@deriving show]

and

$ ocamlfind ocamlc -dsource -linkall -linkpkg -package ppx_deriving,ppx_deriving.show,ppx_deriving.runtime main.ml
type t = int[@@deriving show]
let rec (pp : Format.formatter -> t -> Ppx_deriving_runtime.unit) =
  ((let open! Ppx_deriving_runtime in fun fmt  -> Format.fprintf fmt "%d")
  [@ocaml.warning "-A"])

and show : t -> Ppx_deriving_runtime.string =
  fun x  -> Format.asprintf "%a" pp x

But I don’t know for jbuilder - which you can use my advise in the _build directory.

3 Likes

Look in _build/log for the command that invokes ppx.exe on the source file you are interested in. If you remove the --dump-ast option, the output file will be human-readable instead of binary.

1 Like

Mixing @jjb and @dinosaure solutions works. Thanks.

It could be interesting to have something in jbuilder directly to do the job.

2 Likes