Clean Translation of an Imperative Reversible Programming Language Holger Bock Axelsen DIKU, Dept. of Computer Science, University of Copenhagen funkstar@diku.dk Abstract. We describe the translation techniques used for the code generation in a compiler from the high-level reversible imperative pro- gramming language Janus to the low-level reversible assembly language PISA. Our translation is both semantics preserving (correct), in that target programs compute exactly the same functions as their source pro- grams (cleanly, with no extraneous garbage output), and efficient, in that target programs conserve the complexities of source programs. In par- ticular, target programs only require a constant amount of temporary garbage space. The given translation methods are generic, and should be applicable to any (imperative) reversible source language described with reversible flowcharts and reversible updates. To our knowledge, this is the first com- piler between reversible languages where the source and target languages were independently developed; the first exhibiting both correctness and efficiency; and just the second compiler for reversible languages overall. 1 Introduction Reversible computing is the study of computation models that exhibit both for- ward and backward determinism [2]. Historically, reversible computing originates in the physics of computation: Irreversible computations (for example, seen in our inability to recover the input to a nand-gate from its output, or the previous value of a variable or register after most assignments) can be shown to have a physical effect on the machines that execute them, in the form of heat dissipation and power consumption [7]. For reversible computations these physical conse- quences are no longer implied, and it should therefore be possible to lower the power consumption of computing machinery by using reversible components [5]. Lowering power demands is increasingly important as microprocessor technology bottoms out at the atomic level. To obtain maximal benefit from reversibility a reversible computer should be reversible at every abstraction layer, so reversible hardware [16,13] demands reversible software. However, reversible programming languages are rare and un- derdeveloped. This is unfortunate, given that reversible programming finds use in many diverse areas of computer science. As an example, in quantum comput- ing [14] programs are necessarily reversible (modulo measurements, which are destructive.) Other application include bidirectional model transformation [10], J. Knoop (Ed.): CC 2011, LNCS 6601, pp. 144–163, 2011. c Springer-Verlag Berlin Heidelberg 2011