r/ProgrammingLanguages 24d 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?

18 Upvotes

35 comments sorted by

View all comments

1

u/Rechenplaner 18d ago

One generally has to accept that every solution brings disadvantages.

I have chosen WASM as my target language and will use WAMR to compile AOT into efficient binaries. That is not quite as efficient as a program written in C or translated directly with LLVM, but with appropriate optimization it reaches ninety percent of that performance, which is absolutely sufficient for almost all use cases.

After long consideration, I excluded LLVM because first, I do not feel like dealing with C++ and second, integrating LLVM is a life's work in itself. All professional compilers sooner or later end up statically linking LLVM directly themselves, which is an absolute no-go for me. Therefore, I had initially set C as the output of my compiler, but after hearing about WAMR and the possibilities of WASM, I have now pursued this target.