This work deals with the implementation of a retargetable compiler for a specific programming language that can be systematically reconfigured to generate code for a variety of distinct target computers. In pursuing this goal, a model is proposed and in particular the following three aspects arising from the model are presented:
(1) Designing a target machine description language which allows the specification of instruction set semantics.
(2) Developing an algorithm for code generation in a compiler.
(3) Developing algorithms for constructing code generators from the machine description.
It can be viewed as an extension of Graham-Glanville``s scheme[G&G78]. All formal properties established by Glanville hold on our implementation. Furthermore, we modified the algorithms to produce a correct transition table from a target machine description. The major contributions of our technique are as follows:
(1) We have derived a simple algorithm handling the looping problems[O&P84]. The LALR (1) properties and the conflict resolution methods make it possible to derive the algorithm.
(2) The target machine description language is substantially enlarged to describe the behavior of a code generator. To do this, we used the semantic escape characters which control the process of code emission.
(3) The LALR(1) technique is used to make an initial transition table. Moreover, the formula for computing lookahead sets can be obtained in a more efficient form the characteristics of an instruction grammar.
We have implemented a code generator constructor system by modifying our parser generating system[PAR81]. with this code generator constructor system, the code generators for the pascal subset on two computers are implemented.