A functional macro expansion system for optimizing code generation: gaining context-sensitivity without losing confluence (poster)

As the maxhine-specific macro assemblers offer little support for hierarchical program abstraction, they are rather weak code-generator writing tools: reusable optimized code libraries cannot be easily constructed. The underlying reason is the lack of modularity. For instance, if some assembly macro M uses some register R as a temporary data storage, the programmer has to be most cautious when calling M: the macro expander is not able to issue a warning that the value possibly already stored in R will be lost during the execution of M. Clearly, this problem cannot be solved without contezt-sensttive macros. The traditional way to obtain some context-sensitivity is to use global expansion-time variables-in addition to the explicit macro arguments-for intermacro communication. For instance, when the contents of some memory location are loaded into the register file, a global variable may be used for recording the memory address, so that a possible subsequent load horn the same memory location can be eliminated. Still, global vaxiables do not provide modularity, and their use is subject to some basic limitations: information can be passed only from left to right and, in practice, only within straight-line code segments. Moreover, in the case of global variables we have to stick with the left-toright and depth-first expansion; but when macro arguments are the sole communication device, the final expansion result is independent of the expansion order of the individual macro calls. Thus, global variables are incompatible with the Church-Rosser or confluence property. Why should an assembly-level macro system be confluent? First, parallel implementations become possible: at any time, all the leaf nodes of the expansion tree (which originates from a single macro call) can be processed in parallel. Second, code maintainability is enhanced: if some macro definition is modified, this change propagates only to such nodes that are descendants of a call of the modified macro (with global variables, in contrast, the change could propagate to all the node+ on the right of the call). Third, it becomes straightforward to augment the macro expansion with external global optimizations: we may introduce an intermediate optimization layer inside the expansion tree, because we are free to select such an expansion order that

[1]  Guy L. Steele,et al.  Building interpreters by composing monads , 1994, POPL '94.

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

[3]  Eero Lassila,et al.  Towards Optimizing Code Generation by Domain-Sensitive Macro Expansion , 1997 .

[4]  Eero Lassila A macro expansion approach to embedded processor code generation , 1996, Proceedings of EUROMICRO 96. 22nd Euromicro Conference. Beyond 2000: Hardware and Software Design Strategies.

[5]  Thom W. Frühwirth,et al.  Theory and Practice of Constraint Handling Rules , 1998, J. Log. Program..

[6]  Arabellastrasse,et al.  Constraint Handling Rules ? , 1995 .

[7]  Didier Rémy,et al.  Objective ML: An Effective Object-Oriented Extension to ML , 1998, Theory Pract. Object Syst..