Lecture 17: CS4200-B: Code Generation Mechanics, Summary, Further Study

Eelco Visser
Lecture | PDF
January 14, 2022

Code Generation Mechanics

In the third part of the lecture, we take a broader look at mechanics for code generation, the properties we would like compilers to adhere to, and to what extend existing mechanisms support the verification of those properties out of the box.

  • Code generation by string manipulation
    • Stratego does support string templates, which can be useful to do quick code generation
  • Code generation by term transformation
    • This is what we do in this course. A
  • Guaranteeing syntactic correct target code
    • By means of type checking terms against signature; coming up for Stratego [SLE 2020]
  • Program transformation with concrete object syntax
    • Quoting concrete syntax, while transforming the underlying abstract syntax; see [GPCE 2002, OOPSLA 2004, SCP 2010]
  • Hygienic transformations (avoiding name capture)
    • Hygienic macros in Scheme/Racket ensure capture avoidance in binding constructs introduced by macros
    • The namefix approach guarantees capture avoidance by checking after the fact
    • We are working on avoiding capture in rename refactoring based on scope graphs
  • Guaranteeing type correct target code
    • In intrinsically-typed interpreters/compilers, the type safety of the transformation is guaranteed by construction; see [POPL 2018, 2021] for explorations of this approach in Agda
  • Preservation of dynamic semantics
    • The CompCert certified compiler proves that its code generation preserves the semantics of the source language in target programs; a challenge is how to realize such certified compilation with minimal effort

We only briefly touch on these topics. See the references for further information.



In the second part of the lecture we summarize the course and look at further study of compilers and programming languages. In particular, we list current research challenges in the language workbench group at TU Delft, and we list further courses to take in the master program.