一句话:Hayroll 以模块化包装器方式让 C-to-Rust 翻译具备预处理器感知能力,恢复条件编译的可配置性与宏抽象,且不修改底层翻译器。
既有 C-to-Rust 翻译器在翻译前先运行 C 预处理器 cpp,因而丢弃了条件编译带来的可配置性,也丢失了以宏表达的程序员自定义抽象。本文提出 Hayroll,一个模块化包装器,在不修改底层翻译器的前提下使其具备预处理器感知能力。Hayroll 由两层协作组成:条件编译翻译层用符号执行推导源码每一行的激活条件,将程序切分为一组覆盖所有代码行的配置特定翻译任务;宏翻译层对宏进行分类,为宏展开节点打标签,再通过底层翻译器输出中的标签把 C 宏重建为 Rust 函数或宏。两层只通过任务划分与源码注解通信,底层翻译器保持黑盒。实现在 C2Rust 上,但设计与翻译器无关。在 CRUST-Bench、LibmCS 与 zlib 上的评估表明,Hayroll 能成功重建大部分语法宏,并通过符号执行避免配置爆炸,其输出通过与原翻译器相同的测试。
Previous C-to-Rust translators run the C preprocessor cpp on their input before translation. This discards configurability, and it loses programmer-defined abstractions expressed as C macros. We present Hayroll, a modular wrapper that makes C-to-Rust translation preprocessor-aware without modifying the underlying translator. Hayroll consists of two cooperating layers. The conditional compilation translation layer uses symbolic execution to derive activation conditions for each line of the source code. It splits the program into a set of configuration-specific translation tasks that together cover every line of code. These tasks are then passed independently to the macro translation layer. The macro translation layer classifies macros, annotates macro-expanded nodes with tags, and sends the code through the underlying translator. It then reconstructs C macros as Rust functions or macros by retrieving these tags from the translator’s output. Because the layers communicate only through task partitioning and source-code annotations, the underlying translator remains a black box; no invasive changes are required. Our implementation uses C2Rust, but the design is translator-agnostic. We evaluated Hayroll on CRUST-Bench, LibmCS, and zlib. Hayroll successfully reconstructs most syntactical macros and avoids configuration explosion through symbolic execution. Hayroll's output passes the same tests as the underlying C-to-Rust transpiler. These results show that decoupled preprocessor analysis can restore configurability and abstraction to C-to-Rust translation in a practical and modular way.
@article{PengKBE26,
title = {Hayroll: A Modular Wrapper for Translating C Macros and Conditional Compilation to Rust},
author = {Haoran Peng and Baris Kasikci and Gilbert Louis Bernstein and Michael D. Ernst},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {PLDI},
year = {2026},
doi = {10.1145/3808276}
}