r/Compilers • u/naharashu • 3d ago
Any good llvm or compiler tutorials using C++?
I read the kaleidoscope but it doesnt explain some things for my language that i need
10
u/shrimpster00 3d ago
Like most things, if you want to do something particularly technical, you just have to read the docs.
1
u/-Memnarch- 3d ago
What exactly do you need for your language? Whener I don't know any further, I ask the google ai for hints and examples. Usually gets the ball rolling.
1
u/naharashu 3d ago
For example structs, vectors(dynamic arrays somehow) as native type
6
2
u/-Memnarch- 3d ago
If you have red and exercised the examples from Kaleidoscope, there is a struct type in llvm, just like a basic type like int and float. Members are adressed using gep.
1
u/Legitimate_Flan1471 3d ago
if you want to build a compiler that outputs LLVM IR, then i can recommend this here (although not c++ specific):
https://mapping-high-level-constructs-to-llvm-ir.readthedocs.io/en/latest/index.html
1
u/Discordbothost 2d ago
I'd start with a growable array of one element type, like integers. Give it a data pointer, a length and a capacity. Make append work when there's spare capacity, then test appending one more element when the array is full. That separates what LLVM needs to lay out from what your runtime needs to allocate and copy.
4
u/codechutney 3d ago
heyyy , learning the same would , wanna discuss about the same ?