Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to target LLVM from a compiler written in F#?

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?

like image 988
Rei Miyasaka Avatar asked Jan 27 '13 04:01

Rei Miyasaka


People also ask

Is LLVM written in C++?

LLVM is written in C++ and is designed for compile-time, link-time, run-time, and "idle-time" optimization.

What is LLVM target?

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).

Does LLVM compile to machine code?

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.


2 Answers

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.

like image 196
Jack P. Avatar answered Sep 18 '22 13:09

Jack P.


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#.

like image 24
Nestor Demeure Avatar answered Sep 18 '22 13:09

Nestor Demeure