r/Compilers • • 2d 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

1 Upvotes

10 comments sorted by

4

u/codechutney 2d ago

heyyy , learning the same would , wanna discuss about the same ?

-1

u/naharashu 2d ago

?

1

u/codechutney 1d ago

about learning compilers ? dm me , I'm not able to dm u 

10

u/shrimpster00 2d ago

Like most things, if you want to do something particularly technical, you just have to read the docs.

1

u/-Memnarch- 2d 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 2d ago

For example structs, vectors(dynamic arrays somehow) as native type

6

u/Kywim 2d ago

Try declaring those in C/C++, and using Godbolt (compiler explorer) to check the IR. You can use Clang options to get IR at various stages. That can help you understand how these types are codegenned.

The LLVM discourse is also a great place to ask precise questions

2

u/-Memnarch- 2d 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 1d 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 1d 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.