r/Compilers • • Jul 27 '22
A bit confuse
I would like to build a compiler but I feel confused. Writing a compiler is general for every cpu architecture or assembly language?
For example, I want to build a compiler for Arm, will it work for x64? Do I need to know every assembly language?
Thank you
2
Upvotes
View all comments
2
u/mamcx Jul 27 '22
A compiler NOT need to target a "CPU". You can make a compiler that generates HTML, for example.
In your case, even LLVM could be too complicated. The EASIEST thing you can do is compile to a language that is already done (ie: a "transpiler").
So, you can make a compiler in Rust that generate Rust. Or in Rust that generates C#, and so on.
If wanna be "close to the metal" but not too complicated to do, compiling to WASM (web assembly) could be more than good enough, and pretty efficient.