Page 1 of 1

Retargeting compilers

Posted: Fri Sep 14, 2012 2:46 pm
by Zondartul
Short story: How would I retarget a C/C++ compiler (any will do, but GCC to take the whole cake), to compile machine code that would run on a completely new CPU architecture?

Thing is, I like designing microprocessors, and I can make a (relatively) complete, albeit possibly inefficient, 8-bit one. I have complete understanding of it's instruction set and what can or cannot be done with the registers.

But how would I get an existing compiler to make code for it?

I tried looking for materials online about retargetting GCC, but it only confused me further. Apparently I need to make a "machine description" file (.md), and the code generator could handle it from there, but I have no idea how. Maybe I just suck at reading.

Any help on getting me started?

Thanks in advance.

Re: Retargeting compilers

Posted: Sun Sep 16, 2012 1:40 pm
by JamesM
dozniak wrote:Take LLVM, look at their targets implementation, write some tablegen templates. Then implement some lowering passes, but if you architecture is anywhere near standard, you will most probably just adopt the existing ones.
I'd suggest you don't even go there. LLVM does not and does not intend to support any architecture with a bitwidth of less than 32 bytes. An 8-bit microcontroller would be a pain in the arse to develop an LLVM backend for.