Skip to main content

A Symmetric Approach to Compilation and Decompilation

  • Chapter
  • First Online:
The Essence of Computation

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 2566))

Abstract

Just as an interpreter for a source language can be turned into a compiler from the source language to a target language, we observe that an interpreter for a target language can be turned into a compiler from the target language to a source language. In both cases, the key issue is the choice of whether to perform an evaluation or to emit code that represents this evaluation.

We substantiate this observation with two source interpreters and two target interpreters. We first consider a source language of arithmetic expressions and a target language for a stack machine, and then the λ- calculus and the SECD-machine language. In each case, we prove that the target-to-source compiler is a left inverse of the source-to-target compiler, i.e., that it is a decompiler.

In the context of partial evaluation, the binding-time shift of going from a source interpreter to a compiler is classically referred to as a Futamura projection. By symmetry, it seems logical to refer to the binding-time shift of going from a target interpreter to a compiler as a Futamura embedding.

Basic Research in Computer Science (www.brics.dk), funded by the Danish National Research Foundation.

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

Access this chapter

eBook
USD 16.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Harold Abelson and Gerald Jay Sussman with Julie Sussman. Structure and Interpretation of Computer Programs. The MIT Press, Cambridge, Massachusetts, 1985.

    Google Scholar 

  2. Sergei M. Abramov and Robert Glück. The universal resolving algorithm: inverse computation in a functional language. In Roland Backhouse and José N. Oliveira, editors, Mathematics of Program Construction. Proceedings, volume 1837 of Lecture Notes in Computer Science, pages 187–212. Springer-Verlag, 2000.

    Chapter  Google Scholar 

  3. Sergei M. Abramov, Robert Glück, and Yury Klimov. Faster answers and improved termination in inverse computation of non-flat languages. Technical report, Program Systems Institut, Russian Academy of Sciences, Pereslavl-Zalessky, March 2002 2002.

    Google Scholar 

  4. Mads Sig Ager, Olivier Danvy, and Mayer Goldberg. A symmetric approach to compilation and decompilation (extended version). Technical Report BRICS RS-02-37, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Denmark, August 2002.

    Google Scholar 

  5. Thorsten Altenkirch, Peter Dybjer, Martin Hofmann, and Philip Scott. Normalization by evaluation for typed lambda calculus with coproducts. In Joseph Halpern, editor, Proceedings of the Sixteenth Annual IEEE Symposium on Logic in Computer Science, pages 203–210, Boston, Massachusetts, June 2001. IEEE Computer Society Press.

    Google Scholar 

  6. Roland Carl Backhouse, Patrik Jansson, Johan Jeuring, and Lambert G. L. T. Meertens. Generic programming: an introduction. In S.Doaitse Swierstra, Pedro Rangel Henriques, and José N. Oliveira, editors, Advanced functional programming, Third International School, number 1608 in Lecture Notes in Computer Science, pages 28–115, Braga, Portugal, September 1998. Springer-Verlag.

    Google Scholar 

  7. Guntis Barzdins. Mixed computation and compiler basis. In Dines Bjørner, Andrei P. Ershov, and Neil D. Jones, editors, Partial Evaluation and Mixed Computation, pages 15–26. North-Holland, 1988.

    Google Scholar 

  8. Alan Bawden. Quasiquotation in Lisp. In Olivier Danvy, editor, Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, Technical report BRICS-NS-99-1, University of Aarhus, pages 4–12, San Antonio, Texas, January 1999. Available online at http://www.brics.dk/~pepm99/programme.html.

  9. Ulrich Berger, Matthias Eberl, and Helmut Schwichtenberg. Normalization by evaluation. In Bernhard Möller and John V. Tucker, editors, Prospects for hardware foundations (NADA), number 1546 in Lecture Notes in Computer Science, pages 117–137. Springer-Verlag, 1998.

    Chapter  Google Scholar 

  10. M. N. Bert and L. Petrone. Decompiling context-free languages from their Polishlike representations. Calcolo, XIX(1):35–57, March 1982.

    Article  MathSciNet  Google Scholar 

  11. Anders Bondorf. Compiling laziness by partial evaluation. In Simon L. Peyton Jones, Guy Hutton, and Carsten K. Holst, editors, Functional Programming, Glasgow 1990, Workshops in Computing, pages 9–22, Glasgow, Scotland, 1990. Springer-Verlag.

    Google Scholar 

  12. Jonathan Bowen. From programs to object code and back again using logic programming: Compilation and decompilation. Journal of Software Maintenance: Research and Practice, 5(4):205–234, 1994.

    Article  MathSciNet  Google Scholar 

  13. Peter J. Brown. Re-creation of source code from reverse Polish. Software-Practice and Experience, 2:275–278, 1972.

    Article  MATH  Google Scholar 

  14. Peter J. Brown. More on the re-creation of source code from reverse Polish. Software-Practice and Experience, 7(8):545–551, 1977.

    Article  MATH  Google Scholar 

  15. Kevin A. Buettner. Fast decompilation of compiled Prolog clauses. In Ehud Y. Shapiro, editor, Proceedings of the third international conference on logic programming, number 225 in Lecture Notes in Computer Science, pages 663–670, London, United Kingdom, July 1986. Springer-Verlag.

    Google Scholar 

  16. Rod M. Burstall and Peter J. Landin. Programs and their proofs: An algebraic approach. In B. Meltzer and D. Michie, editors, Machine Intelligence, volume 4, pages 17–43. Edinburgh University Press, 1969.

    Google Scholar 

  17. Cristina Cifuentes. Reverse Compilation Techniques. PhD thesis, Faculty of Information Technology, Queensland University of Technology, Brisbane, Australia, July 1994.

    Google Scholar 

  18. Charles Consel and Olivier Danvy. Static and dynamic semantics processing. In Robert (Corky) Cartwright, editor, Proceedings of the Eighteenth Annual ACM Symposium on Principles of Programming Languages, pages 14–24, Orlando, Florida, January 1991. ACM Press.

    Google Scholar 

  19. Charles Consel and Olivier Danvy. Tutorial notes on partial evaluation. In Susan L. Graham, editor, Proceedings of the Twentieth Annual ACM Symposium on Principles of Programming Languages, pages 493–501, Charleston, South Carolina, January 1993. ACM Press.

    Google Scholar 

  20. Charles Consel and Siau-Cheng Khoo. Semantics-directed generation of a Prolog compiler. Science of Computer Programming, 21:263–291, 1993.

    Article  MATH  MathSciNet  Google Scholar 

  21. Thierry Coquand and Peter Dybjer. Intuitionistic model constructions and normalization proofs. Mathematical Structures in Computer Science, 7:75–94, 1997.

    Article  MATH  MathSciNet  Google Scholar 

  22. Olivier Danvy. Type-directed partial evaluation. In John Hatcli., Torben Æ. Mogensen, and Peter Thiemann, editors, Partial Evaluation-Practice and Theory; Proceedings of the 1998 DIKU Summer School, number 1706 in Lecture Notes in Computer Science, pages 367–411, Copenhagen, Denmark, July 1998. Springer-Verlag.

    Google Scholar 

  23. Olivier Danvy, Morten Rhiger, and Kristoffer Rose. Normalization by evaluation with typed abstract syntax. Journal of Functional Programming, 11(6):673–680, 2001.

    Article  MATH  MathSciNet  Google Scholar 

  24. Andrzej Filinski. Normalization by evaluation for the computational lambdacalculus. In Samson Abramsky, editor, Typed Lambda Calculi and Applications, 5th International Conference, TLCA 2001, number 2044 in Lecture Notes in Computer Science, pages 151–165, Kraków, Poland, May 2001. Springer-Verlag.

    Chapter  Google Scholar 

  25. Daniel P. Friedman, Mitchell Wand, and Christopher T. Haynes. Essentials of Programming Languages. The MIT Press and McGraw-Hill, 1991.

    Google Scholar 

  26. Yoshihiko Futamura. Partial evaluation of computation process-an approach to a compiler-compiler. Higher-Order and Symbolic Computation, 12(4):381–391, 1999. Reprinted from Systems. Computers. Controls 2(5), 1971.

    Article  MATH  Google Scholar 

  27. Yoshihiko Futamura. Partial evaluation of computation process, revisited. Higher-Order and Symbolic Computation, 12(4):377–380, 1999.

    Article  Google Scholar 

  28. R. Stockton Gaines. On the translation of machine language programs. Communications of the ACM, 8(12):736–741, 1965.

    Article  Google Scholar 

  29. Robert Glück and Andrei V. Klimov. Metacomputation as a tool for formal linguistic modeling. In R. Trappl, editor, Cybernetics and Systems Research’ 94, volume 2, pages 1563–1570, Singapore, 1994. World Scientific.

    Google Scholar 

  30. Mayer Goldberg. Gödelization in the λ-calculus. Information Processing Letters, 75(1–2):13–16, 2000.

    Article  MathSciNet  Google Scholar 

  31. Carsten K. Gomard and Neil D. Jones. Compiler generation by partial evaluation. In G. X. Ritter, editor, Information Processing ’89. Proceedings of the IFIP 11th World Computer Congress, pages 1139–1144. IFIP, North-Holland, 1989.

    Google Scholar 

  32. Benjamin Grégoire and Xavier Leroy. A compiled implementation of strong reduction. In Simon Peyton Jones, editor, Proceedings of the 2002 ACM SIGPLAN International Conference on Functional Programming, Pittsburgh, Pennsylvania, September 2002. ACM Press. To appear.

    Google Scholar 

  33. Maurice H. Halstead. Machine Independent Computer Programming. Spartan Books, Washington, D.C., 1962.

    MATH  Google Scholar 

  34. Thérèse Hardin, Luc Maranget, and Bruno Pagano. Functional runtime systems within the lambda-sigma calculus. Journal of Functional Programming, 8(2):131–172, 1998.

    Article  MATH  MathSciNet  Google Scholar 

  35. Peter Henderson. Functional Programming-Application and Implementation. Prentice-Hall International, 1980.

    Google Scholar 

  36. R. Nigel Horspool and Nenad Marovac. An approach to the problem of detranslation of computer programs. The Computer Journal, 23(3):223–229, 1980.

    Google Scholar 

  37. Barron C. Housel and Maurice H. Halstead. A methodology for machine language decompilation. In Proceedings of the 27th ACM Annual Conference, pages 254–260, 1974.

    Google Scholar 

  38. Neil D. Jones. What not to do when writing an interpreter for specialisation. In Olivier Danvy, Robert Glück, and Peter Thiemann, editors, Partial Evaluation, number 1110 in Lecture Notes in Computer Science, pages 216–237, Dagstuhl, Germany, February 1996. Springer-Verlag.

    Google Scholar 

  39. Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. Partial Evaluation and Automatic Program Generation. Prentice-Hall International, London, UK, 1993. Available online at http://www.dina.kvl.dk/~sestoft/pebook/.

    MATH  Google Scholar 

  40. Neil D. Jones and Steven S. Muchnick. Some thoughts towards the design of an ideal language. In Susan L. Graham, editor, Proceedings of the Third Annual ACM Symposium on Principles of Programming Languages, pages 77–94. ACM Press, January 1976.

    Google Scholar 

  41. Neil D. Jones and Flemming Nielson. Abstract interpretation: a semantics-based tool for program analysis. In The Handbook of Logic in Computer Science. North-Holland, 1992.

    Google Scholar 

  42. Neil D. Jones and David A. Schmidt. Compiler generation from denotational semantics. In Neil D. Jones, editor, Semantics-Directed Compiler Generation, number 94 in Lecture Notes in Computer Science, pages 70–93, Aarhus, Denmark, 1980. Springer-Verlag.

    Google Scholar 

  43. Neil D. Jones, Peter Sestoft, and Harald Søndergaard. MIX: A self-applicable partial evaluator for experiments in compiler generation. Lisp and Symbolic Computation, 2(1):9–50, 1989.

    Article  Google Scholar 

  44. Jesper Jørgensen. Generating a compiler for a lazy language by partial evaluation. In Andrew W. Appel, editor, Proceedings of the Nineteenth Annual ACM Symposium on Principles of Programming Languages, pages 258–268, Albuquerque, New Mexico, January 1992. ACM Press.

    Google Scholar 

  45. Shin-ya Katsumata and Atsushi Ohori. Proof-directed de-compilation of low-level code. In David Sands, editor, Proceedings of the Tenth European Symposium on Programming, number 2028 in Lecture Notes in Computer Science, pages 352–366, Genova, Italy, April 2001. Springer-Verlag.

    Google Scholar 

  46. Peter J. Landin. The mechanical evaluation of expressions. The Computer Journal, 6(4):308–320, 1964.

    MATH  Google Scholar 

  47. Peter Lee. Realistic Compiler Generation. The MIT Press, 1989.

    Google Scholar 

  48. Henning Makholm. On Jones-optimal specialization for strongly typed languages. In Walid Taha, editor, Proceedings of the First Workshop on Semantics, Applications, and Implementation of Program Generation (SAIG 2000), number 1924 in Lecture Notes in Computer Science, pages 129–148, Montréal, Canada, September 2000. Springer-Verlag.

    Chapter  Google Scholar 

  49. William May. A simple decompiler-recreating source code without token resistance. Dr. Dobb’s Journal, 50:50–52, June 1988.

    Google Scholar 

  50. John McCarthy and James Painter. Correctness of a compiler for arithmetic expressions. In J. T. Schwartz, editor, Proceedings of the 1967 Symposium in Applied Mathematics, Vol. 19, Mathematical Aspects of Computer Science, pages 33–41. American Mathematical Society, Providence, Rhode Island, 1967.

    Google Scholar 

  51. Erik Meijer. Calculating Compilers. PhD thesis, Nijmegen University, Nijmegen, The Netherlands, 1992.

    Google Scholar 

  52. Austin Melton, David A. Schmidt, and George Strecker. Galois connections and computer science applications. In David H. Pitt et al., editors, Category Theory and Computer Programming, number 240 in Lecture Notes in Computer Science, pages 299–312, Guildford, UK, September 1986. Springer-Verlag.

    Google Scholar 

  53. Lockwood Morris. The next 700 formal language descriptions. Lisp and Symbolic Computation, 6(3/4):249–258, 1993.

    Article  Google Scholar 

  54. Alan Mycroft. Type-based decompilation (or program reconstruction via type reconstruction). In S. Doaitse Swierstra, editor, Proceedings of the Eighth European Symposium on Programming, number 1576 in Lecture Notes in Computer Science, pages 208–223, Amsterdam, The Netherlands, March 1999. Springer-Verlag.

    Google Scholar 

  55. Alan Mycroft, Shin-ya Katsumata, and Atsushi Ohori. Comparing type-based and proof-directed decompilation. In Peter Aiken and Elizabeth Burd, editors, Proceedings of the Working Conference on Reverse Engineering, Stuttgart, Germany, 2001. http://reengineer.org/wcre2001/.

  56. Flemming Nielson and Hanne Riis Nielson. Two-Level Functional Languages, volume 34 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 1992.

    Google Scholar 

  57. Todd A. Proebsting and Scott A. Watterson. Krakatoa: Decompilation in Java (does bytecode reveal source?). In Steve Vinoski, editor, Proceedings of the Third USENIX Conference on Object-Oriented Technologies (COOTS), pages 185–197, Portland, Oregon, June 1997. The USENIX Association.

    Google Scholar 

  58. Walid Taha, Henning Makholm, and John Hughes. Tag elimination and Jonesoptimality. In Olivier Danvy and Andrzej Filinski, editors, Programs as Data Objects, Second Symposium, PADO 2001, number 2053 in Lecture Notes in Computer Science, pages 257–275, Aarhus, Denmark, May 2001. Springer-Verlag.

    Google Scholar 

  59. Peter Thiemann. Combinators for program generation. Journal of Functional Programming, 9(5):483–525, 1999.

    Article  MATH  MathSciNet  Google Scholar 

  60. Mitchell Wand. Deriving target code as a representation of continuation semantics. ACM Transactions on Programming Languages and Systems, 4(3):496–517, 1982.

    Article  MATH  Google Scholar 

  61. Mitchell Wand. From interpreter to compiler: a representational derivation. In Harald Ganzinger and Neil D. Jones, editors, Programs as Data Objects, number 217 in Lecture Notes in Computer Science, pages 306–324, Copenhagen, Denmark, October 1985. Springer-Verlag.

    Google Scholar 

  62. Zhe Yang. Language Support for Program Generation: Reasoning, Implementation, and Applications. PhD thesis, Computer Science Department, New York University, New York, New York, August 2001.

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2002 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Sig Ager, M., Danvy, O., Goldberg, M. (2002). A Symmetric Approach to Compilation and Decompilation. In: Mogensen, T.Æ., Schmidt, D.A., Sudborough, I.H. (eds) The Essence of Computation. Lecture Notes in Computer Science, vol 2566. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-36377-7_14

Download citation

  • DOI: https://doi.org/10.1007/3-540-36377-7_14

  • Published:

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-00326-7

  • Online ISBN: 978-3-540-36377-4

  • eBook Packages: Springer Book Archive

Publish with us

Policies and ethics