4 ms·
LLVM is seriously one of the coolest projects going on right now. On a whim, I decided to see if I could compile LLVM IR to .NET, and it took maybe a grand tota
by daeken 8y ago
LLVM is seriously one of the coolest projects going on right now. On a whim, I decided to see if I could compile LLVM IR to .NET, and it took maybe a grand total of 12 hours to get it all working. I've done a lot of compiler work in the past, but nothing is so universally nice as LLVM.
- mehrdadn 8y agoOut of curiosity, did this involve actually using the LLVM code itself much? Or do you mean you wrote your own interpreter for the IR that it emits?
- flamedoge 8y agoI think easiest way is just to write a backend that emits .NET IR since infra is already there.
- daeken 8y agoThere are four ways I considered for implementing this: write an LLVM backend that spits out .NET binaries; write an LLVM backend that spits out C# or CIL assembly; read the LLVM bytecode from .NET and then generate code from there; use the LLVM API to generate some intermediary then handle the compilation from .NET. I tried #3 first, but landed on #4 in the interest of time. It's not the cleanest approach -- that'd be either using the LLVM API from .NET or implementing a proper backend (assuming there's some decent implementation of a .NET binary writer, since that's a mess) -- but it's stupid simple and effective.
- lostmsu 8y agoThere is one, actually: https://github.com/UbiquityDotNET/Llvm.NET https://github.com/UbiquityDotNET/Llvm.NET
- daeken 8y agoI have a piece of code in C++ that uses the LLVM API to walk over a bytecode file generated by clang, which generates my own more easily parsed format. Then my C# takes over from there. So it has quite a lot of LLVM code, but it technically doesn't need to, in theory.
- mehrdadn 8y agoI see, okay thanks!
- lostmsu 8y agoOpen source?
- daeken 8y agohttps://github.com/daeken/Nettens https://github.com/daeken/Nettens It's crazy early stage -- literally my project this weekend -- but it's a start. My goal is to compile Skia; maybe in a month or two.