Search code examples
compiler-constructionllvmjuliacrystal-lang

How difficult would it be to add a generic code-gen backend to Julia?


How difficult would it be to add a generic code-gen backend to Julia in the vein of go and chez-schemei.e. without the LLVM.

Would LLVM be a better way to do it - given that rust and crystal are also almost entirely self hosted and they can leverage the LLVM to emit binaries, even cross compile.

For a background, I've asked a question specifically about code-gen in case of various LLVM front-ends here What are the issues faced while implementing a self-hosted language on LLVM?


Solution

  • rustc links and uses LLVM, both via the LLVM C API and via an extended wrapper in C++, exposed as a C ABI. I don't know about crystal, but some languages do target textual or bytecode LLVM IR directly, which has some potential advantages, but also performance and compatibility issues.

    As far as "how difficult": NaN, I guess? The most straightforward approach would be to start with Julia's type-inferred lowered form, which is already close to SSA. Someone with a good compiler background could probably write an un-optimized (spilling, no code motion, etc.), one-architecture template assembler in a short time (~months). Someone with no compiler background would probably need a fair amount of study to properly formulate the question.