Title
MARTINI: The Little Match and Replace Tool for Automatic Application Rewriting with Code Examples
Abstract
Rewriting code for cleanliness, API changes, and new programming models is a common, yet time-consuming task. Localized or syntax-based changes are often mechanical and can be automated with text-based rewriting tools, like sed. However, non-localized or semantic-based changes require specialized tools that usually come with complex, hard-coded rules that require expertise in compilers. This means techniques for source rewriting are either too simple for complex tasks or too complex to be customized by non-expert users; in either case, developers are often forced to manually update their code instead. This work describes a new approach to code rewriting which exposes complex and semantic-driven rewrite capabilities to users in a simple and natural way. Rewrite rules are expressed as a pair of parameterized "before-and-after" source code snippets, one to describe what to match and one to describe what the replacement looks like. Through this novel and user-friendly interface, programmers can automate and customize complex code changes which require a deep understanding of the language without any knowledge of compiler internals. As our prototype, MARTINI, is built on top of Clang, we can (conceptually) handle all Clang's input languages, including CUDA, SYCL, and many other C/C++-based interfaces, like Kokkos and OpenMP. To showcase usability, we implemented the clang-tidy rule "modernize-use-nullptr" and a simple instrumentation example. To further illustrate the potential of MARTINI, we reimplemented HIPIFY, which translates CUDA to HIP. Compared to hipify-perl and hipify-clang from HIPIFY, our version is easier to implement, more understandable, and customizable. The latter allows us to outperform HIPIFY-generated code by slightly modifying the translation rules of MARTINI-HIPIFY.
Year
DOI
Venue
2022
10.1007/978-3-031-12597-3_2
EURO-PAR 2022: PARALLEL PROCESSING
Keywords
DocType
Volume
refactoring, metaprogramming, AST matchers
Conference
13440
ISSN
Citations 
PageRank 
0302-9743
0
0.34
References 
Authors
0
4
Name
Order
Citations
PageRank
Alister Johnson100.34
Camille Coti200.34
Allen D. Malony325131.26
Johannes Doerfert413.07