Formal Compiler Construction in a Logical Framework

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.

[1]  Xin Yu,et al.  MetaPRL - A Modular Logical Environment , 2003, TPHOLs.

[2]  Michael J. C. Gordon,et al.  Edinburgh LCF: A mechanised logic of computation , 1979 .

[3]  Andrew W. Appel,et al.  Compiling with Continuations , 1991 .

[4]  John Cocke,et al.  Register Allocation Via Coloring , 1981, Comput. Lang..

[5]  James M. Boyle,et al.  Do you trust your compiler? Applying formal methods to constructing high-assurance compilers , 1997, Proceedings 1997 High-Assurance Engineering Workshop.

[6]  John Cocke,et al.  A methodology for the real world , 1981 .

[7]  Jason Hickey,et al.  Sequent Schema for Derived Rules , 2002, TPHOLs.

[8]  George C. Necula,et al.  The design and implementation of a certifying compiler , 1998, PLDI.

[9]  John Hannan,et al.  Compiler verification in LF , 1992, [1992] Proceedings of the Seventh Annual IEEE Symposium on Logic in Computer Science.

[10]  Paul Klint,et al.  Compiling language definitions: the ASF+SDF compiler , 2000, TOPL.

[11]  David Tarditi,et al.  Design and Implementation of Code Optimizations for a Type-Directed Compiler for Standard ML. , 1996 .

[12]  Jason Hickey,et al.  Building Extensible Compilers in a Formal Framework ? A Formal Framework User ’ s Perspective , 2004 .

[13]  Murray Hill,et al.  Yacc: Yet Another Compiler-Compiler , 1978 .

[14]  Xin Yu,et al.  A computational approach to reflective meta-reasoning about languages with bindings , 2005, MERLIN '05.

[15]  Robin Milner,et al.  Edinburgh lcf: a mechanized logic of computation , 1978 .

[16]  Peter Lee Realistic compiler generation , 1989, Foundations of Computing Series.

[17]  Amir Pnueli,et al.  Translation Validation , 1998, TACAS.

[18]  Jason Hickey,et al.  Extensible Hierarchical Tactic Construction in a Logical Framework , 2004, TPHOLs.

[19]  Jason Hickey,et al.  Phobos: a front-end approach to extensible compilers , 2003, 36th Annual Hawaii International Conference on System Sciences, 2003. Proceedings of the.

[20]  Olivier Danvy,et al.  Representing Control: a Study of the CPS Transformation , 1992, Mathematical Structures in Computer Science.

[21]  Jeffrey D. Ullman Elements of ML programming , 1994 .

[22]  Victor L. Winter Program Transformation in HATS , 1999 .

[23]  Damien Doligez,et al.  The Objective Caml system release 2.04 , 2002 .

[24]  J. Hickey The MetaPRL Logical Programming Environment , 2000 .

[25]  Andrew M. Pitts,et al.  A Metalanguage for Programming with Bound Names Modulo Renaming , 2000, MPC.

[26]  Amr Sabry,et al.  The essence of compiling with continuations , 1993, PLDI '93.

[27]  Chuck Liang,et al.  Compiler Construction in Higher Order Logic Programming , 2002, PADL.

[28]  Frank Pfenning,et al.  Higher-order abstract syntax , 1988, PLDI '88.

[29]  Xavier Leroy,et al.  Le langage Caml , 1993 .

[30]  George C. Necula,et al.  Translation validation for an optimizing compiler , 2000, PLDI '00.

[31]  Jason Hickey,et al.  Process Migration and Transactions Using a Novel Intermediate Language , 2002 .

[32]  Pierre-Louis Curien,et al.  The Categorical Abstract Machine , 1987, Sci. Comput. Program..