Rick Grehan
Some time ago, a fellow BYTE editor loaned me his notes and documents from a conference on how to retarget GCC, the GNU C++ compiler. After spending days poring over the materials, I emerged none the wiser, and simply more jealous of anyone who'd succeeded in building his or her own GCC compiler. Apparently, I didn't have the mental stamina required to accomplish this task.
Then I found out about the Retargetable Software Tools from Archelon (Waterloo, Ontario, Canada, (800) 387-5670). I'll say right up front that Archelon's tools build C compilers, not C++ compilers. Furthermore, the software is not cheap: The starting price is $3495. But you get a set of tools to construct a C compiler, an assembler, a linker, and a librarian for whatever target processor you wish (provided, of course, that the processor is powerful enough). The
re's also a preprocessor for the compiler's front end and a peephole optimizer for its back end.
Furthermore, the C compiler is ANSI compatible. Archelon's president, R. Preston Gurd, informed me that the company has verified the output with the Plum-Hall suite.
I spent most of my time with the kit working with the C compiler portion. That meant wading through the CIF (compiler information file). The CIF tells the compiler everything it needs to know about the architecture of the target machine, including available registers, which ones can be used for indexing, which one can be used for the stack pointer, whether there's a frame-pointer register, the format of assembly instructions, and addressing modes.
Using these tools, you end up working in two directions at once. On one end is the target processor's architecture. On the other end are the rudimentary operators that the compiler understands. Your job is to connect the two.
For example, one of the compiler's fundamental operators is SUB; it
s format is "$dest = $left - $right," which means that the SUB operator subtracts the right operand from the left operand and puts the result in a destination operand. Your job is to teach the compiler the assembly instructions it must emit to perform a SUB operation. Of course, a SUB operation can have characters, integers, long integers, or floating-point values as operands; you have to take all cases into account.
I won't kid you; this stuff is not for the squeamish. I recommend that you work through the demonstration files, trying a little reverse-engineering until you get the feel of how the commands in the CIF work. Then bring up your compiler piecemeal--don't try to do the whole thing at once. You can have it output dummy instructions for the operators you're not sure of in the beginning and then complete it all later.
My biggest complaint is that the documentation could stand more work. I appreciated all the Backus-Naur diagrams--they helped me figure out the proper syntax for a command--but m
ore examples, such as a tutorial for an 8088 C compiler, would make the process smoother.
Still, if you find yourself working with a variety of processors or custom microcontrollers and you'd like to start building a library of ANSI C compilers for yourself, Archelon's Retargetable Software Tools deserves a look. I worked with the DOS version; versions also exist for Unix System V release 4.2, HP-UX, SunOS, and Solaris 2.x.