Retargeting compilers

Programming, for all ages and all languages.
Post Reply
Zondartul
Posts: 7
Joined: Sat Aug 29, 2009 3:33 pm

Retargeting compilers

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Retargeting compilers

Post 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.
Post Reply