Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It’s possible I missed this from the article, since I’m not actually following along, but why do I need to create the custom C++ adapter? The article mentions both ll bc formats, but I don’t see how they are used?

If I wanted to target LLVM, why wouldn’t I emit ll or bc files?



What do you mean by C++ adapter? All the c++ in this post is building the LL files in memory, which can them be persisted to disk or wherever.


Ah I didn’t understand that aspect. So we write the parser in ocaml, then serialize it to protobuf, then consume that from C++ so we can call LLVM’s API to write the expected file format? That still seems needlessly complicated. Is the file format simply too arcane?especially given [0].

[0] https://news.ycombinator.com/item?id=25540637


I see, in this case the author's compiler was written in c++, but you can use ocaml instead to build the IR. There is even a version of their great tutorial series using ocaml you can check out. All the concepts he outlines are the same, just convert the c++ bits to the corresponding ocaml version of the IRBuilder. Then you can go from your language to llvm IR all in ocaml.

https://llvm.org/docs/tutorial/OCamlLangImpl1.html


Ah, I understand now. Thanks for helping!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: