Skip to main content
Log in

Formal compiler construction in a logical framework

  • Published:
Higher-Order and Symbolic Computation

Abstract

The task of designing and implementing a compiler can be a difficult and error-prone process. In this paper, we present a new approach based on the use of higher-order abstract syntax and term rewriting in a logical framework. All program transformations, from parsing to code generation, are cleanly isolated and specified as term rewrites. This has several advantages. The correctness of the compiler depends solely on a small set of rewrite rules that are written in the language of formal mathematics. In addition, the logical framework guarantees the preservation of scoping, and it automates many frequently-occurring tasks including substitution and rewriting strategies. As we show, compiler development in a logical framework can be easier than in a general-purpose language like ML, in part because of automation, and also because the framework provides extensive support for examination, validation, and debugging of the compiler transformations. The paper is organized around a case study, using the MetaPRL logical framework to compile an ML-like language to Intel x86 assembly. We also present a scoped formalization of x86 assembly in which all registers are immutable.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Appel, A.W.: Compiling with continuations. Cambridge University Press (1992)

  2. Boyle, J., Resler, R., Winter, K.: Do you trust your compiler? Applying formal methods to constructing high-assurance compilers. In: High-Assurance Systems Engineering Workshop. Washington, DC (1997)

  3. Chaitin, G.J., Auslander, M.A., Chandra, A.K., Cocke, J., Hopkins, M.E., Markstein, P.W.: Register allocation via coloring. Computer Languages 6(1), 47&57 (1981)

    Article  Google Scholar 

  4. Cousineau, G., Curien, P.L., Mauny, M.: The categorical abstract machine. The Science of Programming 8(2), 173&202 (1987)

    Article  MATH  MathSciNet  Google Scholar 

  5. Danvy, O., Filinski, A.: Representing control: A study of the CPS transformation. Mathematical Structures in Computer Science 2(4), 361&391 (1992)

    Article  MATH  MathSciNet  Google Scholar 

  6. Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. In: Proceedings ACM SIGPLAN 1993 Conf. on Programming Language Design and Implementation, PLDI′93, Albuquerque, NM, USA, vol. 28, no. 6, pp. 237&247 1993, ACM Press, New York

  7. Granicz A., Hickey, J.: Phobos: A front-end approach to extensible compilers. In: 36th Hawaii International Conference on System Sciences. IEEE (2002)

  8. Gray, N., Hickey, J., Nogin, A., Ţăpuş, C.: Building extensible compilers in a formal framework. A formal framework user’s perspective. In: Slind, K. (ed.), Emerging Trends. Proceedings of the 17th International Conference on Theorem Proving in Higher Order Logics (TPHOLs 2004), pp. 57&70. University of Utah (2004)

  9. Gordon, M., Milner, R., Wadsworth, C.: Edinburgh LCF: A mechanized logic of computation, vol.78 of Lecture Notes in Computer Science. Springer-Verlag, NY (1979)

    Google Scholar 

  10. Hickey, J.J etal.: Mojave Research Project Home Page. http://mojave.caltech.edu/

  11. Hickey J.J: The MetaPRL Logical Programming Environment. PhD thesis, Cornell University, Ithaca, NY (2001)

  12. Hickey, J., Nogin, A.: Extensible hierarchical tactic construction in a logical framework. In: Slind, K., Bunker, A., Gopalakrishnan, G., (eds.), Proceedings of the 17th International Conference on Theorem Proving in Higher Order Logics (TPHOLs 2004), vol. 3223 of Lecture Notes in Computer Science, Springer-Verlag, pp. 136&151 (2004)

  13. Hickey, J., Nogin, A., Constable, R.L., Aydemir, B.E., Barzilay, E., Bryukhov Y., Eaton, R., Granicz A., Kopylov, A., Kreitz, C., Krupski, V.N., Lorigo, L., Schmitt, S., Witty, C., Yu, X.: MetaPRL—A modular logical environment. In: Basin, D., Wolff, B. (eds.), Proceedings of the 16th International Conference on Theorem Proving in Higher Order Logics (TPHOLs 2003), vol. 2758 of Lecture Notes in Computer Science, Springer-Verlag, pp. 287&303 (2003)

  14. Hickey, J., Nogin, A., Gray, N.: Programming language experimentation using proof assistants. Compiler development as a case study. To be submitted to Journal of Functional Programming (in preparation) (2005)

  15. Hickey, J.J., Nogin, A., Kopylov, A., etal.: MetaPRL Home Page. http://metaprl.org/

  16. Hannan, J., Pfenning, F.: Compiler verification in LF. In: Proceedings of the 7th Symposium on Logic in Computer Science. IEEE Computer Society Press (1992)

  17. Hickey, J., Smith, J.D., Aydemir, B., Gray, N., Granicz, A., Ţăpuş, C.: Process migration and transactions using a novel intermediate language. Technical Report caltechCSTR:2002.007, California Institute of Technology, Computer Science (2002)

  18. Johnson, S.C.: Yacc—yet another compiler compiler. Computer Science Technical Report32, AT&T Bell Laboratories (1975)

  19. Lee, P.: Realistic compiler generation. MIT Press (1989)

  20. Leroy, X.: The Objective Caml system release 1.07. INRIA, France (1997)

    Google Scholar 

  21. Liang, C.C.: Compiler construction in higher order logic programming. In: Practical Aspects of Declarative Languages, vol. 2257 of Lecture Notes in Computer Science, pp. 47&63 (2002)

  22. Morrisett, J.G., Walker, D., Crary, K., Glew, N.: From system F to typed assembly language. Principles of Programming Languages (1998)

  23. Necula, G.C.: Translation validation for an optimizing compiler. ACM SIG-PLAN Notices 35(5), 83&94 (2000)

    Article  Google Scholar 

  24. Nogin, A., Hickey J.: Sequent schema for derived rules. In: Carreño, V.A., Muñoz, C.A., Tahar, S. (eds.), Proceedings of the 15th International Conference on Theorem Proving in Higher Order Logics (TPHOLs 2002), vol. 2410 of Lecture Notes in Computer Science, Springer-Verlag, pp. 281&297 (2002)

  25. Nogin, A., Kopylov, A., Yu, X., Hickey, J.: A computational approach to reflective meta-reasoning about languages with bindings. In: MERLIN ′05: Proceedings of the 3rd ACM SIGPLAN workshop on Mechanized reasoning about languages with variable binding, ACM, Press, pp. 2&12. (2005) An extended version is available as http://resolver.caltech.edu/CaltechCSTR:2005.003 California Institute of Technology technical report CaltechCSTR:2005.003

  26. Necula, G.C., Lee, P.: The design and implementation of a certifying compiler. In: Proceedings of the 1998 ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), pp. 333&344 (1998)

  27. Pfenning, F., Elliott, C.: Higher-order abstract syntax. In: Proceedings of the ACM SIGPLAN ′88 Conference on Programming Language Design and Implementation (PLDI), vol. 23(7) of SIGPLAN Notices, Atlanta, Georgia, pp. 199&208 (1988). ACM, Press

  28. Pitts, A.M., Gabbay, M.: A metalanguage for programming with bound names modulo renaming. In: Backhouse, R., Oliveira, J.N. (eds.), Mathematics of Program Construction, vol.1837 of Lecture Notes in Computer Science, Springer-Verlag, Heidelberg, pp. 230&255 (2000)

    Google Scholar 

  29. Pnueli, A., Siegel, M., Singerman, E.: Translation validation. Lecture Notes in Computer Science 1384, 151&166 (1998)

    Article  Google Scholar 

  30. Tarditi, D.: Design and Implementation of Code Optimizations for a Type-Directed Compiler for Standard ML. PhD thesis, Carnegie Mellon University, Pittsburgh, PA, USA (1997)

  31. Ullman, J.D.: Elements of ML programming. Prentice Hall (1998)

  32. Vanden Brand, M. Heering, J., Klint, P., Olivier, P.A.: Compiling language definitions: The ASF+SDF compiler. ACM Transactions of Programming Language Systems 24(4), 334&368 (2002)

    Article  Google Scholar 

  33. Winter, V.L.: Program transformation in HATS. In: Proceedings of the Software Transformation Systems Workshop (1999)

  34. Weis, P., Leroy, X.: Le langage Caml, 2nd edn, Dunod, Paris 1999 (In French)

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Jason Hickey.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Hickey, J., Nogin, A. Formal compiler construction in a logical framework. Higher-Order Symb Comput 19, 197–230 (2006). https://doi.org/10.1007/s10990-006-8746-6

Download citation

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10990-006-8746-6

Keywords

Navigation