LLVMSharp guidance needed
Hey, I've wrote a simple parser and lexer for my toy language and rn I'm trying to use LLVMSharp to compile it but I can't find any good documentation or tutorials that would explain it. If there is anyone willing to help me out (for free or for small price) then let me know!
16 Replies
If you post specifically what you've tried and what's not working we might be more helpful. I've used llvm before but not through c#.
So i don't really know where to start with implementing llvm
I have AST generation working and stuff
But i am stuck there
So now you need to take your AST and convert it into llvm IR correct
Yes
So LLVM has a tutorial for this language called kaleidoscope. You can find it here https://llvm.org/docs/tutorial/
I'd suggest reading all of that (maybe follow along with c++ maybe not)
And then read through the llvmsharp kaleidoscope here: https://github.com/dotnet/LLVMSharp/tree/main/samples/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM
GitHub
LLVMSharp/samples/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM at...
LLVM bindings for .NET Standard written in C# using ClangSharp - LLVMSharp/samples/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM at main · dotnet/LLVMSharp
That'll give you a good start on llvm
and then your particular wrapper
Oh yeah, I've read it already. I guess I'll have to read it again a few times
So I'll understand it
Start small don't try and compile your language
It's too much for a first llvm program
Try writing a function that returns it's arg. Then a func that returns it's arg + 1. etc etc
Then try some control flow
Test each little step along the way
If you have a specific question I can prob help but that's some general advice
Thanks
I'll play with it
LLVM can print it's IR
That's super helpful. I'd figure out how to do that in llvmsharp too
It's fairly readable
Mind if add you to friends so i can dm you later?
Sure
I actually have completed some basic arithmetic stuff
And printed it out
But yeah, need to experiment with it more
Okay so you're on your way (:
Yup, thanks