# The differences between Cmm parser and pretty printer

**URL:** <https://discourse.haskell.org/t/the-differences-between-cmm-parser-and-pretty-printer/12673>\
**Category:** Uncategorized\
**Created:** [August 11, 2025, 12:56am UTC](https://discourse.haskell.org/t/the-differences-between-cmm-parser-and-pretty-printer/12673 "2025-08-11T00:56:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GunpowderGuy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/gunpowderguy/32/4164_2.png) [@GunpowderGuy](https://discourse.haskell.org/u/GunpowderGuy)\
**Post date:** [August 11, 2025, 12:56am UTC](https://discourse.haskell.org/t/the-differences-between-cmm-parser-and-pretty-printer/12673/1 "2025-08-11T00:56:14Z")

</div>

Hello back

One of the goals of my GSoC cmm project is to make cmm roundtripable. That is , be able to serialize/pretty print the cmm data structure ( the one GHC uses for code generation ) into a file and be able to parse/deserialize said file back into a haskell data structure. This is currently not possible because Cmm cant be pretty printed and parsed from textual files. But those two tools use incompatible formats

Initially Csaba Hruska ( my mentor ) and i figured out the least invasive way to accomplish this, would be to rewrite the pretty printer so it produces code compatible with the parser. But we now think this is a bad idea. The parser implements a “high level syntax” which ammount to features not found in the cmm data structure. But even the low level syntax is not an accurate depiction of the AST.

I would like to share some of the documentation i have been writing, so you can see for yourselfs

> <https://github.com/GunpowderGuy/cmm-documentation/blob/master/Exploded_view.md>

---

<div class="post-metadata">

**Author:** ![AndreasPK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/andreaspk/32/2654_2.png) [@AndreasPK](https://discourse.haskell.org/u/AndreasPK)\
**Post date:** [August 11, 2025, 12:36pm UTC](https://discourse.haskell.org/t/the-differences-between-cmm-parser-and-pretty-printer/12673/2 "2025-08-11T12:36:26Z")

</div>

For those interested there was also discussion on the ghc-devs mailing list in these two threads:

> **[Proposal: Roundtrip serialization of Cmm (parser-compatible pretty-printer...](https://mail.haskell.org/pipermail/ghc-devs/2025-July/022054.html)**

> **[Proposal: Roundtrip serialization of Cmm (parser-compatible pretty-printer...](https://mail.haskell.org/pipermail/ghc-devs/2025-August/022069.html)**

---

<div class="post-metadata">

**Author:** ![GunpowderGuy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/gunpowderguy/32/4164_2.png) [@GunpowderGuy](https://discourse.haskell.org/u/GunpowderGuy)\
**Post date:** [August 11, 2025, 4:49pm UTC](https://discourse.haskell.org/t/the-differences-between-cmm-parser-and-pretty-printer/12673/3 "2025-08-11T16:49:07Z")

</div>

Thanks. forgot to link those. There is also a third mailing list thread ( there is more than one because i messed up the format )

> **[Fwd: Proposal: Roundtrip serialization of Cmm (parser-compatible...](https://mail.haskell.org/pipermail/ghc-devs/2025-July/022059.html)**

and a couple of ( mildly ) related threads :

> [@Why Doesn't Haskell Have a 'Serde'-Like Library for Multi-Format Serialization?](https://discourse.haskell.org/t/why-doesnt-haskell-have-a-serde-like-library-for-multi-format-serialization/12593):
>
> Hello Haskell developers, Coming from a Rust background, I’ve been wondering why Haskell doesn’t seem to have a library similar to Rust’s [Serde](https://serde.rs/), which provides automatic serialization and deserialization to and from multiple data formats such as JSON, CBOR, and XML. In Haskell, serialization seems fragmented across various libraries: aeson handles JSON, cborg handles CBOR, Other formats like XML their own specialized libraries (if any). This became more relevant to me after looking…

> **[\#23989: Encoding intermediate representations as S expressions · Issues ·...](https://gitlab.haskell.org/ghc/ghc/-/issues/23989)**
>
> Over dinner @rae and I discussed various things that GHC and OCaml respectively do well. One of the...

---

<div class="post-metadata">

**Author:** ![GunpowderGuy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/gunpowderguy/32/4164_2.png) [@GunpowderGuy](https://discourse.haskell.org/u/GunpowderGuy)\
**Post date:** [August 15, 2025, 5:25pm UTC](https://discourse.haskell.org/t/the-differences-between-cmm-parser-and-pretty-printer/12673/4 "2025-08-15T17:25:19Z")

</div>

I would like some feedback on the style of documentation i am writing

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [August 15, 2025, 6:02pm UTC](https://discourse.haskell.org/t/the-differences-between-cmm-parser-and-pretty-printer/12673/5 "2025-08-15T18:02:39Z")

</div>

I find it hard to see the structure of the documentation itself. Perhaps an introduction with an overview of the contents could help?

---

<div class="post-metadata">

**Author:** ![GunpowderGuy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/gunpowderguy/32/4164_2.png) [@GunpowderGuy](https://discourse.haskell.org/u/GunpowderGuy)\
**Post date:** [August 18, 2025, 5:22am UTC](https://discourse.haskell.org/t/the-differences-between-cmm-parser-and-pretty-printer/12673/6 "2025-08-18T05:22:37Z")

</div>

My dyslexic ass forgot to improve the redaction. It should be better now , but i could try another cleaning pass
