Composing Source-to-Source Data-Flow Transformations with Rewriting Strategies and Dependent Dynamic Rewrite Rules
Abstract
Data-flow transformations used in optimizing compilers are also useful in other programming tools such as code generators, aspect weavers, domain-specific optimizers, and refactoring tools. These applications require source-to-source transformations rather than transformations on a low-level intermediate representation. In this paper we describe the composition of source-to-source data-flow transformations in the program transformation language Stratego. The language supports the high-level specification of transformations by means of rewriting strategy combinators that allow a natural modeling of data- and control-flow without committing to a specific source language. Data-flow facts are propagated using dynamic rewriting rules. In particular, we introduce the concept of dependent dynamic rewrite rules for modeling the dependencies of data-flow facts on program entities such as variables. The approach supports the combination of analysis and transformation, the combination of multiple transformations, the combination with other types of transformations, and the correct treatment of variable binding constructs and lexical scope to avoid free variable capture.
Keywords
Constant Propagation Abstract Syntax Source Language Program Transformation Concrete SyntaxReferences
- 1.Aho, A., Sethi, R., Ullman, J.: Compilers: Principles, Techniques, and Tools. Addison-Wesley, Reading (1986)Google Scholar
- 2.Appel, A.: Modern compiler implementation in ML. Cambridge University Press, Cambridge (1998)Google Scholar
- 3.Assmann, U.: How To Uniformly Specify Program Analysis and Transformation. In: Gyimóthy, T. (ed.) CC 1996. LNCS, vol. 1060, pp. 121–135. Springer, Heidelberg (1996)Google Scholar
- 4.Bravenboer, M., van Dam, A., Olmos, K., Visser, E.: Program transformation with scoped dynamic rewrite rules. Technical Report UU-CS-2005-005, Institute of Information and Computing Sciences, Utrecht University (2005)Google Scholar
- 5.Click, C., Cooper, K.D.: Combining analyses, combining optimizations. ACM Transactions on Programming Languages and Systems 17(2), 181–196 (1995)CrossRefGoogle Scholar
- 6.Drape, S., de Moor, O., Sittampalam, G.: Transforming the .NET intermediate language using path logic programming. In: Kirchner, C. (ed.) Proceedings of the Fourth ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (PPDP 2002), Pittsburgh, Pensylvania, USA, October 2002, pp. 133–144. ACM, New York (2002)CrossRefGoogle Scholar
- 7.Lacey, D., de Moor, O.: Imperative program transformation by rewriting. In: Wilhelm, R. (ed.) CC 2001. LNCS, vol. 2027, pp. 52–68. Springer, Heidelberg (2001)CrossRefGoogle Scholar
- 8.Lerner, S., Grove, D., Chambers, C.: Combining dataflow analyses and transformations. In: SIGPLAN Symposium on Principles of Programming Languages (POPL 2002), Portland, Oregon, January 2002, pp. 270–282 (2002)Google Scholar
- 9.Lerner, S., Millstein, T., Chambers, C.: Automatically proving the correctness of compiler optimizations. In: Programming Language Design and Implementation (PLDI 2003), ACM SIGPLAN, June 2003, pp. 220–231 (2003)Google Scholar
- 10.Lerner, S., Millstein, T., Rice, E., Chambers, C.: Automated soundness proofs for dataflow analyses and transformations via local rules. In: Principles of Programming Languages (POPL 2005), ACM SIGPLAN, January 2005, pp. 364–377 (2005)Google Scholar
- 11.Martin, F.: PAG an efficient program analyzer generator. International Journal on Software Tools for Technology Transfer STTT 2(1), 46–67 (1998)zbMATHCrossRefGoogle Scholar
- 12.Muchnick, S.: Advanced compiler design and implementation. Morgan Kaufmann, San Francisco (1997)Google Scholar
- 13.Olmos, K., Visser, E.: Strategies for source-to-source constant propagation. In: Gramlich, B., Lucas, S. (eds.) Workshop on Reduction Strategies (WRS 2002), Copenhagen, Denmark, July 2002. ENTCS, vol. 70, p. 20. Elsevier, Amsterdam (2002)Google Scholar
- 14.Olmos, K., Visser, E.: Composing source-to-source data-flow transformations with rewriting strategies and dependent dynamic rewrite rules. Technical Report UU-CS-2005-006, Institute of Information and Computing Sciences, Utrecht University (2005)Google Scholar
- 15.Sittampalam, G., de Moor, O., Larsen, K.F.: Incremental execution of transformation specifications. In: SIGPLAN Symposium on Principles of Programming Languages (POPL 2004), pp. 26–38. ACM, New York (2004)CrossRefGoogle Scholar
- 16.Tjiang, S.W.K., Hennessy, J.L.: Sharlit—A tool for building optimizers. In: ACM SIGPLAN 1992 Conference on Programming Language Design and Implementation (July 1992)Google Scholar
- 17.Visser, E.: Scoped dynamic rewrite rules. In: van den Brand, M., Verma, R. (eds.) Rule Based Programming (RULE 2001). ENTCS, vol. 59/4. Elsevier Science Publishers, Amsterdam (2001)Google Scholar
- 18.Visser, E.: Meta-programming with concrete object syntax. In: Batory, D., Consel, C., Taha, W. (eds.) GPCE 2002. LNCS, vol. 2487, pp. 299–315. Springer, Heidelberg (2002)CrossRefGoogle Scholar
- 19.Visser, E.: Program transformation with Stratego/XT: Rules, strategies, tools, and systems in StrategoXT-0.9. In: Lengauer, C., Batory, D., Consel, C., Odersky, M. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 216–238. Springer, Heidelberg (2004)CrossRefGoogle Scholar
- 20.Visser, E., Benaissa, Z.-e.-A., Tolmach, A.: Building program optimizers with rewriting strategies. In: Proceedings of the third ACM SIGPLAN International Conference on Functional Programming (ICFP 1998), pp. 13–26. ACM Press, New York (1998)CrossRefGoogle Scholar
- 21.Wegman, M., Zadeck, F.: Constant propagation with conditional branches. ACM Transactions on Programming Languages and Systems 13, 181–210 (1991)CrossRefGoogle Scholar