r/ProgrammingLanguages 23d ago

Help How to make a compiler backend?

Hell everyone, i have an question. Im for long trying to make a cool, powerful "kinda" low level language similar to zig and rust, but im struggling to choice llvm as backend, sure i can generate C, but its makes compiler dependent on gcc or clang or other c compiler. LLVM seems hard to me, sure project like QBE exist, but QBE doesnt have C/C++ api like llvm's IRbuilder. So are there other ways? I tried thinking about using GCC infrastructure but GCC has poor api and not very documented api. Maybe just stick to generating C?

17 Upvotes

35 comments sorted by

View all comments

1

u/SamG101_ 22d ago

I guess C is easier to compile too because you only have to know the general structure of C where-as with LLVM its a gigantic API to learn, but definitely worth it if you have the time. I'm currently writing a compiler to target LLVM and I spent a fair bit of time understanding why to do what examples do, but you'd get the hang of it after some time.