Cj: a tiny no-deps JIT in C for x86-64 and ARM64
Posted by hellerve@reddit | programming | View on Reddit | 0 comments
Hey y’all!
About 7 years ago, I had this idea to write a JIT with an autogenerated backend for x86 based on the ISA specs. I sketched something out and then just kinda let it sit. I picked it up again a few weeks ago and made a complete-ish backend for both x86 and ARM64. It has no dependencies, the backends are completely autogenerated (by horrible, horrible JS scripts), and I built a small abstraciton layer for things like functions prologues etc.
It’s super duper early and will probably break on your machine, but it’s good enough to compile some cool examples (look at the examples directory, my personal favorite is the minimal language implementation).
It doesn’t have anything except basically a fancy JIT assembler with some helpers as of yet. No register allocator, a lot of ABI details will still have to be figured out manually (though of course feel free to add anything to the abstraction layer that’s generally useful and submit a PR!).
I honestly don’t know where I’m going with this next. I kind of stumbled into the project, and am not sure whether I’ll consider it as “exercise completed” or whether I should pursue it more. Time will tell.
Feedback, questions, and bug reports very welcome—especially on the codegen helpers, additional examples or cool things you come up with, or backend rough edges.
P.S.: I also wrote a small announcement blog post on it that you can find here (https://blog.veitheller.de/cj:_Making_a_minimal,_complete_JI...), but it honestly doesn’t add all that much interesting info that you can’t find in the repo