skip to main content

Automatically deriving control-flow graph generators from operational semantics

Published:31 August 2022Publication History
Skip Abstract Section

Abstract

We develop the first theory of control-flow graphs from first principles, and use it to create an algorithm for automatically synthesizing many variants of control-flow graph generators from a language’s operational semantics. Our approach first introduces a new algorithm for converting a large class of small-step operational semantics to an abstract machine. It next uses a technique called ”abstract rewriting” to automatically abstract the semantics of a language, which is used both to directly generate a CFG from a program (”interpreted mode”) and to generate standalone code, similar to a human-written CFG generator, for any program in a language. We show how the choice of two abstraction and projection parameters allow our approach to synthesize several families of CFG-generators useful for different kinds of tools. We prove the correspondence between the generated graphs and the original semantics. We provide and prove an algorithm for automatically proving the termination of interpreted-mode generators. In addition to our theoretical results, we have implemented this algorithm in a tool called Mandate, and show that it produces human-readable code on two medium-size languages with 60−80 rules, featuring nearly all intraprocedural control constructs common in modern languages. We then show these CFG-generators were sufficient to build two static analyses atop them. Our work is a promising step towards the grand vision of being able to synthesize all desired tools from the semantics of a programming language.

References

  1. Mads Sig Ager. 2004. From Natural Semantics to Abstract Machines. In International Symposium on Logic-Based Program Synthesis and Transformation. 245–261. Google ScholarGoogle ScholarCross RefCross Ref
  2. Mads Sig Ager, Dariusz Biernacki, Olivier Danvy, and Jan Midtgaard. 2003. A Functional Correspondence between Evaluators and Abstract Machines. In Proceedings of the 5th ACM SIGPLAN international conference on Principles and Practice of Declarative Programming. 8–19. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Andrew W. Appel. 1998. Modern Compiler Implementation in ML. Cambridge University Press. isbn:0-521-58274-1 Google ScholarGoogle Scholar
  4. Franz Baader and Tobias Nipkow. 1999. Term Rewriting and All That. Cambridge University Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Didier Bert and Rachid Echahed. 1995. Abstraction of Conditional Term Rewriting Systems. In Logic Programming, Proceedings of the 1995 International Symposium, Portland, Oregon, USA, December 4-7, 1995. 162–176. http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=6300583 Google ScholarGoogle Scholar
  6. Didier Bert, Rachid Echahed, and Bjarte M Ø stvold. 1993. Abstract Rewriting. In International Workshop on Static Analysis. 178–192. Google ScholarGoogle Scholar
  7. Małgorzata Biernacka. 2006. A Derivational Approach to the Operational Semantics of Functional Languages. Ph.D. Dissertation. PhD thesis, BRICS PhD School, Department of Computer Science, Aarhus University, Aarhus, Denmark. Google ScholarGoogle Scholar
  8. Martin Bodin, Philippa Gardner, Thomas Jensen, and Alan Schmitt. 2019. Skeletal semantics and their interpretations. PACMPL, 3, POPL (2019), 44:1–44:31. https://doi.org/10.1145/3290357 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Denis Bogdanas and Grigore Roşu. 2015. K-Java: A Complete Semantics of Java. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, Mumbai, India, January 15-17, 2015. 445–456. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Michael Carbin and Armando Solar-Lezama. 2018. MITScript Language Specification. http://6.s081.scripts.mit.edu/sp18/handout-pdfs/specification.pdf Google ScholarGoogle Scholar
  11. Matteo Cimini and Jeremy G. Siek. 2016. The Gradualizer: A Methodology and Algorithm for Generating Gradual Type Systems. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, January 20 - 22, 2016. 443–455. https://doi.org/10.1145/2837614.2837632 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Matteo Cimini and Jeremy G. Siek. 2017. Automatically Generating the Dynamic Semantics of Gradually Typed Languages. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France, January 18-20, 2017. 789–803. http://dl.acm.org/citation.cfm?id=3009863 Google ScholarGoogle Scholar
  13. Clifford Noel Click. 1995. Combining Analyses, Combining Optimizations. Ph.D. Dissertation. Rice University. Google ScholarGoogle Scholar
  14. Michael Codish, Saumya K. Debray, and Roberto Giacobazzi. 1993. Compositional Analysis of Modular Logic Programs. In Conference Record of the Twentieth Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Charleston, South Carolina, USA, January 1993. 451–464. https://doi.org/10.1145/158511.158703 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Michael Codish, Moreno Falaschi, and Kim Marriott. 1991. Suspension Analysis for Concurrent Logic Programs. In Logic Programming, Proceedings of the Eigth International Conference, Paris, France, June 24-28, 1991. 331–345. Google ScholarGoogle Scholar
  16. Patrick Cousot and Radhia Cousot. 1992. Abstract Interpretation and Application to Logic Programs. The Journal of Logic Programming, 13, 2-3 (1992), 103–179. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Olivier Danvy. 2008. Defunctionalized Interpreters for Programming Languages. In Proceeding of the 13th ACM SIGPLAN International Conference on Functional Programming, ICFP 2008, Victoria, BC, Canada, September 20-28, 2008. 131–142. https://doi.org/10.1145/1411204.1411206 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Olivier Danvy and Jacob Johannsen. 2010. Inter-Deriving Semantic Artifacts for Object-Oriented Programming. J. Comput. System Sci., 76, 5 (2010), 302–323. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Olivier Danvy, Kevin Millikin, Johan Munk, and Ian Zerny. 2012. On Inter-Deriving Small-Step and Big-Step Semantics: A Case Study for Storeless Call-by-Need Evaluation. Theoretical Computer Science, 435 (2012), 21–42. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Olivier Danvy and Lasse R Nielsen. 2004. Refocusing in Reduction Semantics. BRICS Report Series, 11, 26 (2004). Google ScholarGoogle Scholar
  21. David Darais, Nicholas Labich, Phúc C Nguyen, and David Van Horn. 2017. Abstracting Definitional Interpreters (Functional Pearl). Proceedings of the ACM on Programming Languages, 1, ICFP (2017), 12. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. David Darais, Matthew Might, and David Van Horn. 2015. Galois Transformers and Modular Abstract Interpreters: Reusable Metatheory for Program Analysis. In Proceedings of the 2015 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2015, part of SPLASH 2015, Pittsburgh, PA, USA, October 25-30, 2015. 552–571. https://doi.org/10.1145/2814270.2814308 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Nachum Dershowitz. 1987. Termination of Rewriting. Journal of Symbolic Computation, 3, 1-2 (1987), 69–115. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Matthias Felleisen, Robert Bruce Findler, and Matthew Flatt. 2009. Semantics Engineering with PLT Redex. Mit Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Jeanne Ferrante and Joe D Warren. 1987. The Program Dependence Graph and Its Use in Optimization. ACM Transactions on Programming Languages and Systems, 9, 3 (1987), 319–349. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The Essence of Compiling with Continuations. In Proceedings of the ACM SIGPLAN’93 Conference on Programming Language Design and Implementation (PLDI), Albuquerque, New Mexico, USA, June 23-25, 1993. 237–247. https://doi.org/10.1145/155090.155113 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Dionna Amalie Glaze and David Van Horn. 2014. Abstracting Abstract Control. In DLS’14, Proceedings of the 10th ACM Symposium on Dynamic Languages, part of SPLASH 2014, Portland, OR, USA, October 20-24, 2014. 11–22. https://doi.org/10.1145/2661088.2661098 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Dionna Amalie Glaze, Nicholas Labich, Matthew Might, and David Van Horn. 2013. Optimizing Abstract Abstract Machines. In ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA - September 25 - 27, 2013. 443–454. https://doi.org/10.1145/2500365.2500604 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. John Hannan and Dale Miller. 1992. From Operational Semantics to Abstract Machines. Mathematical Structures in Computer Science, 2, 4 (1992), 415–459. Google ScholarGoogle ScholarCross RefCross Ref
  30. Chris Hathhorn, Chucky Ellison, and Grigore Roşu. 2015. Defining the Undefinedness of C. In Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation, Portland, OR, USA, June 15-17, 2015. 336–345. https://doi.org/10.1145/2737924.2737979 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Cornelis Huizing, Ron Koymans, and Ruurd Kuiper. 2010. A Small Step for Mankind. In Concurrency, Compositionality, and Correctness. Springer, 66–73. Google ScholarGoogle Scholar
  32. Jean-Marie Hullot. 1980. Canonical Forms and Unification. In International Conference on Automated Deduction. 318–334. Google ScholarGoogle ScholarCross RefCross Ref
  33. Husain Ibraheem and David A Schmidt. 1997. Adapting Big-Step Semantics to Small-Step Style: Coinductive Interpretations and "Higher-Order" Derivations. Electronic Notes in Theoretical Computer Science, 10 (1997), 121. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Suresh Jagannathan and Stephen Weeks. 1995. A Unified Treatment of Flow Analysis in Higher-Order Languages. In Conference Record of POPL’95: 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Francisco, California, USA, January 23-25, 1995. 393–407. https://doi.org/10.1145/199448.199536 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Neil D Jones. 1981. Flow Analysis of Lambda Expressions. In International Colloquium on Automata, Languages, and Programming. 114–128. Google ScholarGoogle Scholar
  36. Jasper FT Kamperman and Humphrey Robert Walters. 1993. ARM Abstract Rewriting Machine. Google ScholarGoogle Scholar
  37. Andy King and Mark Longley. 1995. Abstract Matching Can Improve on Abstract Unification. Google ScholarGoogle Scholar
  38. Casey Klein, John Clements, Christos Dimoulas, Carl Eastlund, Matthias Felleisen, Matthew Flatt, Jay A McCarthy, Jon Rafkind, Sam Tobin-Hochstadt, and Robert Bruce Findler. 2012. Run Your Research: On the Effectiveness of Lightweight Mechanization. ACM SIGPLAN Notices, 47, 1 (2012), 285–296. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. James Koppel, Varot Premtoon, and Armando Solar-Lezama. 2018. One Tool, Many Languages: Language-Parametric Transformation with Incremental Parametric Syntax. Proceedings of the ACM on Programming Languages, 2, OOPSLA (2018), 122. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Matthew R Lakin and Andrew M Pitts. 2007. A Metalanguage for Structural Operational Semantics. In Symposium on Trends in Functional Programming. Google ScholarGoogle Scholar
  41. Dallas S Lankford. 1975. Canonical Inference. University of Texas, Department of Mathematics and Computer Sciences. Google ScholarGoogle Scholar
  42. Derrick Lin, James Koppel, Angela Chen, and Armando Solar-Lezama. 2017. QuixBugs: A Multi-Lingual Program Repair Benchmark Set Based on the Quixey Challenge. In Proceedings Companion of the 2017 ACM SIGPLAN International Conference on Systems, Programming, Languages, and Applications: Software for Humanity. 55–56. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Panagiotis Manolios. 2001. Mechanical Verification of Reactive Systems. Google ScholarGoogle Scholar
  44. Jan Midtgaard. 2012. Control-flow Analysis of Functional Programs. ACM Comput. Surv., 44, 3 (2012), Article 10, June, 33 pages. issn:0360-0300 https://doi.org/10.1145/2187671.2187672 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Jan Midtgaard and Thomas P. Jensen. 2008. A Calculational Approach to Control-Flow Analysis by Abstract Interpretation. In Static Analysis, 15th International Symposium, SAS 2008, Valencia, Spain, July 16-18, 2008. Proceedings. 347–362. https://doi.org/10.1007/978-3-540-69166-2_23 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Jan Midtgaard and Thomas P. Jensen. 2009. Control-flow Analysis of Function Calls and Returns by Abstract Interpretation. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming (ICFP ’09). ACM, New York, NY, USA. 287–298. isbn:978-1-60558-332-7 https://doi.org/10.1145/1596550.1596592 Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Dominic P Mulligan, Scott Owens, Kathryn E Gray, Tom Ridge, and Peter Sewell. 2014. Lem: Reusable Engineering of Real-World Semantics. ACM SIGPLAN Notices, 49, 9 (2014), 175–188. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Flemming Nielson, Hanne R Nielson, and Chris Hankin. 2015. Principles of Program Analysis. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Nathaniel Nystrom, Michael R Clarkson, and Andrew C Myers. 2003. Polyglot: An Extensible Compiler Framework for Java. In International Conference on Compiler Construction. 138–152. Google ScholarGoogle Scholar
  50. Daejun Park, Andrei Stefănescu, and Grigore Roşu. 2015. KJS: A Complete Formal Semantics of JavaScript. In ACM SIGPLAN Notices. 50, 346–356. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Corina S Păsăreanu, Radek Pelánek, and Willem Visser. 2005. Concrete Model Checking with Abstract Matching and Refinement. In International Conference on Computer Aided Verification. 52–66. Google ScholarGoogle Scholar
  52. Justin Pombrio and Shriram Krishnamurthi. 2018. Inferring Type Rules for Syntactic Sugar. In Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation. 812–825. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Justin Pombrio, Shriram Krishnamurthi, and Mitchell Wand. 2017. Inferring Scope through Syntactic Sugar. Proceedings of the ACM on Programming Languages, 1, ICFP (2017), 44. Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. Casper Bach Poulsen and Peter D Mosses. 2014. Deriving Pretty-Big-Step Semantics from Small-Step Semantics. In European Symposium on Programming Languages and Systems. 270–289. Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Camilo Rocha, José Meseguer, and César Muñoz. 2017. Rewriting Modulo SMT and Open System Analysis. Journal of Logical and Algebraic Methods in Programming, 86, 1 (2017), 269–297. Google ScholarGoogle ScholarCross RefCross Ref
  56. Grigore Roşu and Traian Florin Şerbănută. 2010. An Overview of the K Semantic Framework. The Journal of Logic and Algebraic Programming, 79, 6 (2010), 397–434. Google ScholarGoogle ScholarCross RefCross Ref
  57. David A Schmidt. 1996. Abstract Interpretation of Small-Step Semantics. In LOMAPS Workshop on Analysis and Verification of Multiple-Agent Languages. 76–99. Google ScholarGoogle Scholar
  58. Ilya Sergey and Dave Clarke. 2011. From Type Checking by Recursive Descent to Type Checking with an Abstract Machine. In Proceedings of the Eleventh Workshop on Language Descriptions, Tools and Applications. 2. Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. Ilya Sergey, Dominique Devriese, Matthew Might, Jan Midtgaard, David Darais, Dave Clarke, and Frank Piessens. 2013. Monadic Abstract Interpreters. In ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’13, Seattle, WA, USA, June 16-19, 2013. 399–410. https://doi.org/10.1145/2491956.2491979 Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. Olin Shivers. 1991. Control-Flow Analysis of Higher-Order Languages. Ph.D. Dissertation. PhD thesis, Carnegie Mellon University. Google ScholarGoogle ScholarDigital LibraryDigital Library
  61. Tamás Szabó, Sebastian Erdweg, and Markus Voelter. 2016. IncA: A DSL for the Definition of Incremental Program Analyses. In Automated Software Engineering (ASE), 2016 31st IEEE/ACM International Conference on. 320–331. Google ScholarGoogle ScholarDigital LibraryDigital Library
  62. David Van Horn and Matthew Might. 2010. Abstracting Abstract Machines. In 15th ACM SIGPLAN International Conference on Functional Programming, ICFP’10. Google ScholarGoogle Scholar
  63. Ferdinand Vesely and Kathleen Fisher. 2019. One Step at a Time. In European Symposium on Programming. 205–231. Google ScholarGoogle ScholarCross RefCross Ref
  64. Guannan Wei, James Decker, and Tiark Rompf. 2018. Refunctionalization of Abstract Abstract Machines: Bridging the Gap Between Abstract Abstract Machines and Abstract Definitional Interpreters (Functional Pearl). Proceedings of the ACM on Programming Languages, 2, ICFP (2018), 105. Google ScholarGoogle ScholarDigital LibraryDigital Library
  65. Yong Xiao, Amr Sabry, and Zena M. Ariola. 2001. From Syntactic Theories to Interpreters: Automating the Proof of Unique Decomposition. Higher-Order and Symbolic Computation, 14, 4 (2001), 387–409. https://doi.org/10.1023/A:1014408032446 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Automatically deriving control-flow graph generators from operational semantics

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Article Metrics

        • Downloads (Last 12 months)250
        • Downloads (Last 6 weeks)20

        Other Metrics

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!