anyone experience in retargeting compilers?

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
Post Reply
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

anyone experience in retargeting compilers?

Post 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.
Last edited by AndrewAPrice on Sat Jul 12, 2008 11:24 pm, edited 2 times in total.
My OS is Perception.
User avatar
babylon2233
Member
Member
Posts: 66
Joined: Fri May 23, 2008 5:30 pm
Location: Malaysia

Re: anyone experience in porting compilers?

Post 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).
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: anyone experience in porting compilers?

Post 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 :(
My OS is Perception.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: anyone experience in porting compilers?

Post 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. ;)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: anyone experience in porting compilers?

Post 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.
My OS is Perception.
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: anyone experience in retargeting compilers?

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