Solid Sands
Download as PDF
Developing a C compiler for a new (or old) target processor is one of the greatest and most rewarding software engineering projects imaginable. It is also challenging and daunting. This is where SuperTest’s new Code Generator Trainer suite comes in.
The assumption is that you are not writing this compiler from scratch. You will be using an existing compiler development platform, either open source or proprietary, that already has a front-end, optimizations and a more or less retargetable code generator. Your task is to write a code generator for the new target processor.
SuperTest’s Code Generation Trainer suite (CGtrainer) is going to make this project run smooth, efficiently and with a lot of fun on top of that.
We are actually most interested in the parts of the library implementation that are not executed as a result of the test run. They indicate our test suite is incomplete. For every line of code that is not executed, we add a new test if possible. In Figure 1, the segment to the right is almost completely covered. The segment to the left is from a similar function that has a very similar implementation. It is not covered at all, while the tests for the left and the right segment are closely matching. What is going on here? More about that later.
Each level addresses a specific capability of the code generator. Level 0 is there to set up the minimal interface that is needed to run the tests. The next levels introduce simple integer arithmetic, conversions, pointers, addressing modes for structures, register allocation, control flow and calling conventions. Beyond that are levels dealing with characters and shorts, long long arithmetic and varargs.
Each level is constructed to build upon the groundwork of the previous levels. In this way, code generator development progresses one logical step at a time. And when the time comes to refactor some of your earlier work, you can be confident that CGtrainer has your back.
By the time you pass the final boss level, your compiler is ready to take on SuperTest’s big guns: the conformance suites that validate the front-end, optimization correctness and more nitty gritty details of code generation. There will be more work to do: add more features, improve efficiency, etc. You can be sure that this work builds on the solid foundations laid out by SuperTest’s CGtrainer.
Home / Knowledge / Whitepaper / CG Trainer – for Code Generator Development