Page 1 of 1

Simplest C compiler to retarget

Posted: Sat Jul 19, 2008 11:02 pm
by iammisc
I have written a virtual machine and I would like to be able to run C on this machine just for fun. The thing is, I don't have a C compiler. Now, I know that there are some compilers meant for this stuff(lcc for example), but the thing is that my virtual machine doesn't have a fixed number of registers but rather it has an arbitrary per-subroutine register number and it also has a quite high-level bytecode. What would be the simplest compiler to use for this? Should I even use a standard compiler or should I attempt to write my own(I have some experience with compiler design)? Have you successfully retargeted a compiler?

AFAICT, all the retargetable C compilers make certain assumptions about their backends, which generally means that backends only produce the most low-level code. However, since my bytecode is really high-level, I do not know if any compiler would be able to handle it.

What do you think?

Re: Simplest C compiler to retarget

Posted: Fri Aug 08, 2008 5:43 am
by DeletedAccount
If you are happy with a subset of C , then give small C a try :) . But it is easier to write a pascal compiler by hand than a full blown c complier ( implementing sets can be a bit difficult :) ) ,ie try a modified version of pascal . The pascal grammar is available from the Writh's book , u can use a simpler variation of the grammar to write a pretty simple pascal compiler


Regards
Evil Sandeep

Re: Simplest C compiler to retarget

Posted: Fri Aug 08, 2008 6:12 am
by AndrewAPrice
I've spent several weeks on this issue for my console since it has a different architecture to most. I'd recommend VBCC since it even comes with a template generic backend you can start with.

Re: Simplest C compiler to retarget

Posted: Fri Aug 08, 2008 7:18 am
by DeletedAccount
Take a look at PLY as well , compilers can be easily prototyped with ply . Thou shall rely heavily on the visitor pattern

Regards
Saint Lucifer