How to get chunks generated by the Elixir compiler?

I need to be able to get the Erlang AST which the Elixir compiler generates. So my question is:

Is it possible to get the Elixir compiler to generate the abstract_code chunk? I see that it generates the debug_info chunk which does contain the abstract code but that is not in a form directly usable by other tools, like those in the :beam_lib module. Or maybe there is an Elixir tool which can do this for me?

4 Likes

Well, I have worked out how to get the chunks. Now I just need to work out how to get the generated Erlang code out from the :debug_info chunk. It seems like the function which does it, well maybe does it, is :elixir_erl which isn’t documented using docs.

2 Likes

:beam_lib.chunk(mod, [:abstract_code]) will give you the Erlang version, even for Elixir, as there is a public contract those chunks are expected to fulfill: otp/lib/stdlib/src/beam_lib.erl at 3257c5c5850299669026b72f71e2b1eae74f1a50 · erlang/otp · GitHub

4 Likes

Sorry, yes I had missed that. Thanks.

2 Likes