Looking for lightweight backend options for my custom programming language project

I’m working on building a compiler using Rust and have already implemented the lexer, parser, and semantic analysis parts. Currently I have a basic x86-64 assembly backend but it’s becoming difficult to maintain and add new language features to it.

LLVM feels like overkill for this educational project since it’s quite heavyweight and complex for what I need. I also looked into QBE but found the codebase difficult to follow and understand.

Are there any other lightweight or medium-sized compiler backends that would be suitable for learning purposes? I’m mainly interested in something that’s easier to work with than writing raw assembly but not as complex as LLVM.

Try WebAssembly as your intermediate target. The spec’s well-documented and way simpler than native assembly, but still powerful enough for most language features. Tools like wasmtime give you solid runtime support, and you can compile WASM to native later if you need to. Another option is to generate C code as your backend. It’s not as elegant as direct code generation, but you get to use existing optimizing compilers which handle platform-specific issues automatically. This approach allows you to learn how to build a complete compiler pipeline without getting stuck in assembly.

cranelift is a great option! it’s way simpler than llvm and still packs a punch. plus, it’s maintained by facebook for wasmtime, so you kno it’s reliable. docs ain’t perfect, but they ain’t bad either!

Oh interesting! What specific features are making the assembly backend tricky? Have you thought about targeting c instead of assembly? Might be way easier to debug and extend than dealing with raw x86 instructions.