An implementation of retargetable code generators in prolog

  • Annie Despland
  • Monique Mazaud
  • Raymond Rakotozafy
Logic Programming In Compiler Writing
Part of the Lecture Notes in Computer Science book series (LNCS, volume 348)


A major problem in deriving a compiler from a formal definition is the production of correct and efficient object code. In this context, we propose a solution to the problem of code generator generation.

Our approach is based on a target machine description where the basic concepts used (storage classes, access modes, access classes and instructions) are hierarchically described by tree-patterns. These tree-patterns are written in an abstract tree language which is also used to write the program intermediate representation (input to the code generator). The code generation process is based on access mode template-driven rewritings in which the program intermediate representation is progressively transformed. The result is that each program instruction is reduced to a sequence of elementary machine instructions, each of them representing an instance of an instruction template. A data base of clauses is derived automatically from the target machine description. It is used by the kernel of the rewriting system implemented in Prolog.

First, this paper presents a way of structuring formal specifications of target machines in order to decrease the size of the description. We propose to get complete specification components by instances of parameterized specifications. As a consequence, legibility which is an important requirement of large specifications is improved.

Second a theoretical support of the intermediate rewritings based on abstract data types is given.

Third the code generation algorithm is presented and illustrated.

Finally an implementation in Prolog of a code generator based on our appoach is developped.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [BGM 87]
    Bidoit M., Gaudel M. C., Mauboussin A.: "How to make algebraic specifications more understandable ? an experiment with the PLUSS specification language", Rapport LRI No 343, Université d'Orsay, France 1987.Google Scholar
  2. [Cat 77]
    Cattell R. G. G.: "A Survey and Critique of some Models of Code Generation", Carnegie-Mellon University, Computer Sciences Department, Technical Report, CMU-CS-115, 1977.Google Scholar
  3. [Cat 80]
    Cattell R. G. G.: "Automatic Derivation of Code Generators from Machine Description", ACM Transactions on Programming Languages and Systems, Vol. 2, No.2 p173–199, April 1980.Google Scholar
  4. [DMR 87]
    Despland A., Mazaud M., Rakotozafy R.: "Code generator generation based on template-driven target term rewriting", LNCS no 256 p 105–120, Proceedings of Rewriting Techniques and Applications, Bordeaux, France, May 1987.Google Scholar
  5. [Des 82]
    Deschamp Ph.: "PERLUETTE: a compiler producing system using abstract data types", Proceedings of International Symposium on Programming, Turin, April 1982.Google Scholar
  6. [Gan Gie 82]
    Ganzinger H, Giegerich R.: "A truly Generative Semantics-Directed Compiler Generator", Proceedings of the SIGPLAN 82 Symposium on Compiler Construction, ACM SIGPLAN no 17, 6, June 1982.Google Scholar
  7. [GDM 84]
    Gaudel M. C., Deschamp Ph., Mazaud M.: "Compiler Construction From High Level Specification", Automatic Program Construction Techniques, Macmillan Inc, 1984.Google Scholar
  8. [GF 82]
    Ganapathi M., Fischer C. N.: "Description-Driven Code Generation Using attributed Grammars", Conference of the Nineth Annual ACM Symposium on Programming Languages, Albuquerque New-Mexico, p 108–109, January 25–27, 1982.Google Scholar
  9. [GG 78]
    Graham S. L, Glanville R. S.: "A New Method for Compiler Code Generation", Conference Record of the Fifth Annual ACM Symposium on Principles of Programming Languages, p 231–240, January 1978.Google Scholar
  10. [GH 84]
    Graham S. L., Henry R. R. & Al. "Experiment with a Graham-Glanville Style Code generator", Proceedings of the SIGPLAN 84, Symposium on Compiler Construction, ACM Not. 19, 6, June 1984.Google Scholar
  11. [Gie 85]
    Giegerich R.: "Logic specification of Code Generation Techniques", LNCS no 217, p 96–111, Programs as data objects, Copenhague October 17–19, 1985.Google Scholar
  12. [Mad 83]
    Madelaine E.: "Système d'aide à la preuve de compilateurs", Thèse de 3ème cycle, Université de Paris VII, Septembre 1983.Google Scholar
  13. [MRS 86]
    Mazaud M., Rakotozafy R., Szumachowski-Despland A.: "Code generator generation based on template-driven target term rewriting", Rapport de recherche INRIA RR-582, 1986.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1989

Authors and Affiliations

  • Annie Despland
    • 1
  • Monique Mazaud
    • 2
  • Raymond Rakotozafy
    • 1
  1. 1.L.I.F.O. Université d'OrléansOrléans CEDEX2France
  2. 2.I.N.R.I.A. Domaine de VoluceauLe Chesnay CEDEXFrance

Personalised recommendations