Hui Yan Cheah <hych...@gmail.com> writes: > We are working on a new project which requires a retargetting a > compiler to a small cpu on FPGA. > The cpu is hand-coded and it supports only a limited number of instruction > sets. > > My questions are: > > 1. Since I have very limited experience with compilers (this is my > first compiler project), is it wise to begin with gcc? I have > googled-up smaller compilers like pcc, lcc and small-c and they seem > like very good candidates. However, I would like to listen to the > opinions of programmers who have worked with gcc or retargetted gcc.
That's a tough question to answer. gcc is well designed for targeting new processors and that part of gcc is well documented. There are also many existing examples to look at. On the other hand, gcc is a large and powerful C compiler and it can take a fair amount of work to get optimal code out of it. And if something goes wrong in your port, such that you have to understand the gcc code to figure out what is happening, it can take some time to figure out how gcc works well enough to debug it. I don't have any experience with the other compilers you mention, so I really don't know how hard it would be to retarget them. > 2. How much is the effort in retargetting compilers? I heard it took > months but it all depends on the level of experience of the > programmer. So if an experienced programmer took 2 month, it might > have taken a beginner 6 months or so. That sounds about right, if you replace "experienced programmer" with "experienced GCC developer" and replace "beginner" with "experienced programmer with no GCC experience." I would estimate that a person whose first serious programming task is retargeting gcc would take more than six months. You can't port a compiler without a deep understanding of how computers work, and developing that understanding takes time. Of course, that is the general case. A lot depends on the target CPU. If the CPU has * a limited number of instructions, but providing all math instructions * orthogonal registers with no dedicated registers except perhaps PC * no unusual instructions * 8-bit bytes * simple call instruction * simple indirect call instruction * simple indirect jump instruction * simple register plus offset addressing * an existing assembler with standard ELF syntax then a GCC port is pretty simple, and an experienced GCC programmer could probably do it in two or three weeks. Unfortunately I have never yet seen such a CPU in real hardware, and the difficulties arise in the ways in which the real CPU departs from that ideal. Finally, there are companies and individual contractors which specialize in porting gcc to new hardware, and they would be happy to take this burden from your hands, for a fee. I have no idea how much that fee is these days. Ian