Page 1 of 1

anyone experience in retargeting compilers?

Posted: Wed Jul 09, 2008 1:03 am
by AndrewAPrice
From the beginning I wanted to retarget a C (or C++) compiler to my console's architecture (see http://forum.osdev.org/viewtopic.php?f=11&t=17045), and I started work on a GCC backend (back when I was overwhelmed with free time) but it ended up being a major undertaking. Right now (unlike before) I really don't have the time (this + group game for final project + Rapid Application Development class + other stuff in my life), so I gave up on porting a compiler used that time to write my own high-level assembler instead and to work on other projects.

While high-level assembly is fast (easy to optimise code), I still don't find it as comfortable as working with a higher level language like C.

I've looked in to a few different retargetable C compilers including; GCC, Amsterdam Compiler Kit, PCC, TenDRA, SDCC, but each require a lot of reading to understand the compiler's internals and there is a lot of undocumented guess-work involved (e.g. compilers not supporting overlapping registers).

Anyway, I'm inviting anyone who wants to try to retarget a C or C++ compiler to my console. I know other people will have a lot more experience and knowledge in this area than I do in this area.

I have a high-level and low-level assembler, an emulator (there is a tiny bit of Windows-specific code in the emulator), and all technical documentation for reference.

Thanks.

Re: anyone experience in porting compilers?

Posted: Thu Jul 10, 2008 2:40 am
by babylon2233
I'm not sure about this but I think lcc is maybe what you looking for.

http://www.cs.princeton.edu/software/lcc/

It successfully port to Magic-1(homebrew cpu).

Re: anyone experience in porting compilers?

Posted: Sat Jul 12, 2008 1:20 am
by AndrewAPrice
Thanks, I'm looking at LCC right now. There are still a few things I don't understand which aren't covered by the interface guide. For example, consider the following definition:

Code: Select all

stmt: LEI4(reg,mrc1)  "cmp %0,%1\njle %a\n"  4
What is %a (I've also seen %c), what does mrc stand for, and what is that 4 for? I'm assuming 4 is the number of bytes the instruction takes up, but I'm not sure.

Edit:The official user manual, A Retargetable C Compiler: Design and Implementation, which I assume covers it, isn't free :(

Re: anyone experience in porting compilers?

Posted: Sat Jul 12, 2008 8:55 am
by Brynet-Inc
If those are from the "magic-1" target, I think those are what he calls his registers. ;)

Anyway, I found this guide on retargeting lcc for the PDP-11, it might give you... advice.

(Additional linkage)
http://homebrewcpu.com/retargeting_lcc.htm

EDIT: s/retarding/retargeting, @Inflater, you're not funny. ;)

Re: anyone experience in porting compilers?

Posted: Sat Jul 12, 2008 8:19 pm
by AndrewAPrice
Thanks, I've already been referring to those guides though. The thing that has put me off is when they say "(see lcc book for more details)". The author shows how he implemented a PDP-11 backend and goes in to detail about why he did what he did, but it left me struggling when I came across architectural differences. I've used other (heavily undocumented) architectures for reference and all the architectures implement things he did not and vice versa.

I've moved back to PCC because there is more (freely available) completely documentation.

Re: anyone experience in retargeting compilers?

Posted: Sun Jul 13, 2008 12:35 am
by DeletedAccount
If you want something quick , you may take a look at the public domain small C Compiler , it can be a little difficult read due to archaic K & R style. But it is easy to port it . change the x86 insturctions to one that of your target machine . I have written a small compiler development article for the os dev magazine , you may check it out . The Small C compiler works exactly the same way i have written in the article . Also the compiler only supports a subset of C not the entire C language ,still it should be easy to port it .
Regards
Sandeep Mathew