I'm part way through writing a toy language in F#. I want to target LLVM, but it looks like I'll have to do some work to make that happen.
It looks like I might be able to do some interop with the IRBuilder libraries, or I might be able to roll my own IR emitter. As far as I've searched, I couldn't find any solution that anyone else has made.
How might I do this?
LLVM is written in C++ and is designed for compile-time, link-time, run-time, and "idle-time" optimization.
The LLVM target-independent code generator is a framework that provides a suite of reusable components for translating the LLVM internal representation to the machine code for a specified target—either in assembly form (suitable for a static compiler) or in binary machine code format (usable for a JIT compiler).
This tutorial paper focuses on this process, and uses LLVM to compile programs into optimized machine code. LLVM is a language-agnostic compiler toolchain that handles program optimization and code generation. It is based on its own internal representation, called LLVM IR, which is then transformed into machine code.
I know several people who use F# + LLVM regularly, and I've seen a bunch of questions about it here on SO before: Questions tagged F# and LLVM
Anyway, take a look at the LLVM bindings for F# on Github -- that should be a good starting point.
LLVMSharp seems to be a viable solution. They have a C# tutorial to build a language on top of LLVM that should be easy to convert to F#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With