C
C#2y ago
Theos

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
n8ta
n8ta2y ago
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#.
Theos
Theos2y ago
So i don't really know where to start with implementing llvm I have AST generation working and stuff But i am stuck there
n8ta
n8ta2y ago
So now you need to take your AST and convert it into llvm IR correct
Theos
Theos2y ago
Yes
n8ta
n8ta2y ago
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)
n8ta
n8ta2y ago
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
n8ta
n8ta2y ago
That'll give you a good start on llvm and then your particular wrapper
Theos
Theos2y ago
Oh yeah, I've read it already. I guess I'll have to read it again a few times So I'll understand it
n8ta
n8ta2y ago
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
Theos
Theos2y ago
Thanks I'll play with it
n8ta
n8ta2y ago
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
Theos
Theos2y ago
Mind if add you to friends so i can dm you later?
n8ta
n8ta2y ago
Sure
Theos
Theos2y ago
I actually have completed some basic arithmetic stuff And printed it out But yeah, need to experiment with it more
n8ta
n8ta2y ago
Okay so you're on your way (:
Theos
Theos2y ago
Yup, thanks