# Collecting preprocessor output

**URL:** https://discuss.ocaml.org/t/collecting-preprocessor-output/3575
**Category:** Ecosystem
**Tags:** dune
**Created:** [March 27, 2019, 12:33pm UTC](https://discuss.ocaml.org/t/collecting-preprocessor-output/3575 "2019-03-27T12:33:35Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![chrismamo1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chrismamo1/32/1502_2.png) [@chrismamo1](https://discuss.ocaml.org/u/chrismamo1)
#### Post date: [March 27, 2019, 12:33pm UTC](https://discuss.ocaml.org/t/collecting-preprocessor-output/3575/1 "2019-03-27T12:33:35Z")

</div>

I’m currently developing a PPX with Dune as my buildsystem. I have a simple test, but as my PPX grows I’d like to frequently check on the raw ocaml output. How would I do this? I don’t think I can do the trick mentioned in the manual (page 34 on [https://buildmedia.readthedocs.org/media/pdf/jbuilder/latest/jbuilder.pdf](https://buildmedia.readthedocs.org/media/pdf/jbuilder/latest/jbuilder.pdf) ) because my PPX is invoked with a `(preprocess (pps blah))` line.

---

<div class="post-metadata">

### Author: ![emillon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/emillon/32/1206_2.png) [@emillon](https://discuss.ocaml.org/u/emillon)
#### Post date: [March 27, 2019, 2:02pm UTC](https://discuss.ocaml.org/t/collecting-preprocessor-output/3575/2 "2019-03-27T14:02:51Z")

</div>

Hi Chris!

If you’d like to check the output of your ppx, it is available in the `*.pp.ml` files in the `_build` directory. Unfortunately it’s in a binary format, but you can parse and print it using the following mini-program (to be linked with `compiler-libs.bytecomp`):

```ocaml
let dump in_path =
  let ast = Pparse.read_ast Structure in_path in
  Format.printf "%a\n" Pprintast.structure ast

```

This is probably something that we can support better in dune, please [open an issue](https://github.com/ocaml/dune/issues/new) if you have some ideas 🙂

---

<div class="post-metadata">

### Author: ![ejgallego](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ejgallego/32/239_2.png) [@ejgallego](https://discuss.ocaml.org/u/ejgallego)
#### Post date: [March 27, 2019, 3:27pm UTC](https://discuss.ocaml.org/t/collecting-preprocessor-output/3575/3 "2019-03-27T15:27:03Z")

</div>

@emillon is that also the case when using `(staged_pps ...)`?

---

<div class="post-metadata">

### Author: ![emillon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/emillon/32/1206_2.png) [@emillon](https://discuss.ocaml.org/u/emillon)
#### Post date: [March 27, 2019, 3:55pm UTC](https://discuss.ocaml.org/t/collecting-preprocessor-output/3575/4 "2019-03-27T15:55:36Z")

</div>

I don’t remember all the details of how `(staged_pps)` is implemented (maybe there’s an extra AST file), but if there’s a binary `.pp.ml` file you can read it using the above technique.

---

<div class="post-metadata">

### Author: ![jeremiedimino](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jeremiedimino/32/699_2.png) [@jeremiedimino](https://discuss.ocaml.org/u/jeremiedimino)
#### Post date: [March 27, 2019, 4:25pm UTC](https://discuss.ocaml.org/t/collecting-preprocessor-output/3575/5 "2019-03-27T16:25:46Z")

</div>

`staged_pps` is implemented using the `-ppx` argument of the compiler. It is difficult to share the preprocessing step when using `staged_pps`. The best one can do when using `staged_pps` is the following: grep for the exact compilation command in `_build/log`, copy&paste it in the terminal and add `-dsource`

---

<div class="post-metadata">

### Author: ![ejgallego](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ejgallego/32/239_2.png) [@ejgallego](https://discuss.ocaml.org/u/ejgallego)
#### Post date: [March 27, 2019, 4:32pm UTC](https://discuss.ocaml.org/t/collecting-preprocessor-output/3575/6 "2019-03-27T16:32:02Z")

</div>

Thanks @jeremiedimino, that’s extremely useful, I had forgotten about `-dsource`. Would it be useful to add a rule for a `pp.ml` target in this case, so debugging would be easier?

[Such target should only be built when specifically request tho, not sure how easy it is to do that]

---

<div class="post-metadata">

### Author: ![chrismamo1](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chrismamo1/32/1502_2.png) [@chrismamo1](https://discuss.ocaml.org/u/chrismamo1)
#### Post date: [April 4, 2019, 9:27am UTC](https://discuss.ocaml.org/t/collecting-preprocessor-output/3575/7 "2019-04-04T09:27:49Z")

</div>

Thank you very much!
