ChatPaper.aiChatPaper

EVOC2RUST: Een skeletgestuurd raamwerk voor projectniveau C-naar-Rust-vertaling

EVOC2RUST: A Skeleton-guided Framework for Project-Level C-to-Rust Translation

August 6, 2025
Auteurs: Chaofan Wang, Tingrui Yu, Jie Wang, Dong Chen, Wenrui Zhang, Yuling Shi, Xiaodong Gu, Beijun Shen
cs.AI

Samenvatting

Rust's compile-time veiligheidsgaranties maken het ideaal voor veiligheidskritische systemen, wat de vraag naar het vertalen van legacy C-codebases naar Rust heeft doen toenemen. Hoewel er verschillende benaderingen voor deze taak zijn ontstaan, kampen ze met inherente afwegingen: op regels gebaseerde oplossingen hebben moeite om te voldoen aan de eisen voor codeveiligheid en idiomatisch gebruik, terwijl LLM-gebaseerde oplossingen vaak falen in het genereren van semantisch equivalente Rust-code, vanwege de zware afhankelijkheden van modules in de gehele codebase. Recente studies hebben aangetoond dat beide oplossingen beperkt zijn tot kleinschalige programma's. In dit artikel stellen we EvoC2Rust voor, een geautomatiseerd framework voor het omzetten van volledige C-projecten naar equivalente Rust-projecten. EvoC2Rust maakt gebruik van een skeletgeleide vertaalstrategie voor projectniveau vertaling. De pijplijn bestaat uit drie evolutionaire fasen: 1) het decomposeert eerst het C-project in functionele modules, gebruikt een feature-mapping-versterkte LLM om definities en macro's te transformeren en genereert type-gecontroleerde functiestubs, die een compileerbaar Rust-skelet vormen; 2) het vertaalt vervolgens incrementeel de functie, waarbij de corresponderende stub-placeholder wordt vervangen; 3) ten slotte repareert het compilatiefouten door LLM en statische analyse te integreren. Door evolutionaire augmentatie combineert EvoC2Rust de voordelen van zowel op regels gebaseerde als LLM-gebaseerde oplossingen. Onze evaluatie op open-source benchmarks en zes industriële projecten toont de superieure prestaties van EvoC2Rust in projectniveau C-naar-Rust vertaling. Gemiddeld behaalt het 17,24% en 14,32% verbeteringen in syntactische en semantische nauwkeurigheid ten opzichte van LLM-gebaseerde benaderingen, samen met een 96,79% hogere codeveiligheidsratio dan de op regels gebaseerde tools. Op moduleniveau bereikt EvoC2Rust 92,25% compilatie- en 89,53% test-slaagpercentages op industriële projecten, zelfs voor complexe codebases en lange functies.
English
Rust's compile-time safety guarantees make it ideal for safety-critical systems, creating demand for translating legacy C codebases to Rust. While various approaches have emerged for this task, they face inherent trade-offs: rule-based solutions face challenges in meeting code safety and idiomaticity requirements, while LLM-based solutions often fail to generate semantically equivalent Rust code, due to the heavy dependencies of modules across the entire codebase. Recent studies have revealed that both solutions are limited to small-scale programs. In this paper, we propose EvoC2Rust, an automated framework for converting entire C projects to equivalent Rust ones. EvoC2Rust employs a skeleton-guided translation strategy for project-level translation. The pipeline consists of three evolutionary stages: 1) it first decomposes the C project into functional modules, employs a feature-mapping-enhanced LLM to transform definitions and macros and generates type-checked function stubs, which form a compilable Rust skeleton; 2) it then incrementally translates the function, replacing the corresponding stub placeholder; 3) finally, it repairs compilation errors by integrating LLM and static analysis. Through evolutionary augmentation, EvoC2Rust combines the advantages of both rule-based and LLM-based solutions. Our evaluation on open-source benchmarks and six industrial projects demonstrates EvoC2Rust's superior performance in project-level C-to-Rust translation. On average, it achieves 17.24% and 14.32% improvements in syntax and semantic accuracy over the LLM-based approaches, along with a 96.79% higher code safety rate than the rule-based tools. At the module level, EvoC2Rust reaches 92.25% compilation and 89.53% test pass rates on industrial projects, even for complex codebases and long functions.
PDF62August 7, 2025