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.
Similar content being viewed by others
References
Appel, A.W.: Compiling with continuations. Cambridge University Press (1992)
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)
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)
Cousineau, G., Curien, P.L., Mauny, M.: The categorical abstract machine. The Science of Programming 8(2), 173&202 (1987)
Danvy, O., Filinski, A.: Representing control: A study of the CPS transformation. Mathematical Structures in Computer Science 2(4), 361&391 (1992)
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
Granicz A., Hickey, J.: Phobos: A front-end approach to extensible compilers. In: 36th Hawaii International Conference on System Sciences. IEEE (2002)
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)
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)
Hickey, J.J etal.: Mojave Research Project Home Page. http://mojave.caltech.edu/
Hickey J.J: The MetaPRL Logical Programming Environment. PhD thesis, Cornell University, Ithaca, NY (2001)
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)
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)
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)
Hickey, J.J., Nogin, A., Kopylov, A., etal.: MetaPRL Home Page. http://metaprl.org/
Hannan, J., Pfenning, F.: Compiler verification in LF. In: Proceedings of the 7th Symposium on Logic in Computer Science. IEEE Computer Society Press (1992)
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)
Johnson, S.C.: Yacc—yet another compiler compiler. Computer Science Technical Report32, AT&T Bell Laboratories (1975)
Lee, P.: Realistic compiler generation. MIT Press (1989)
Leroy, X.: The Objective Caml system release 1.07. INRIA, France (1997)
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)
Morrisett, J.G., Walker, D., Crary, K., Glew, N.: From system F to typed assembly language. Principles of Programming Languages (1998)
Necula, G.C.: Translation validation for an optimizing compiler. ACM SIG-PLAN Notices 35(5), 83&94 (2000)
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)
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
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)
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
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)
Pnueli, A., Siegel, M., Singerman, E.: Translation validation. Lecture Notes in Computer Science 1384, 151&166 (1998)
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)
Ullman, J.D.: Elements of ML programming. Prentice Hall (1998)
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)
Winter, V.L.: Program transformation in HATS. In: Proceedings of the Software Transformation Systems Workshop (1999)
Weis, P., Leroy, X.: Le langage Caml, 2nd edn, Dunod, Paris 1999 (In French)
Author information
Authors and Affiliations
Corresponding author
Rights 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
Issue Date:
DOI: https://doi.org/10.1007/s10990-006-8746-6