Enhancing LLMs in Long Code Translation through Instrumentation and Program State Alignment
Not on the map. Why?
Abstract (arXiv)
Code translation aims to transform code between programming languages while preserving functionality, with applications in cross-platform development and software migration. Recent advances in Large Language Models (LLMs) have improved code translation, but challenges remain, particularly in inferring program functionality. These issues worsen with longer and more complex code, where current LLMs struggle to handle length and intricate semantics. To evaluate LLMs on long code translation, we introduce LongTrans, a large-scale execution-based benchmark with C++, Java, and Python programs, ranging from hundreds to thousands of tokens. Our empirical study of 12 LLMs reveals a sharp performance decline as code length increases, with even the best-performing model, GPT-4o, achieving only 57.51% computational accuracy. This highlights the need for further research in long code translation. We argue that code translation should maintain invariant functionality while transforming syntax and keywords across languages. Despite differences in appearance, program states should remain consistent throughout execution. To address this, we propose PAST (Program State Alignment augmented Translation), which integrates instrumentation to capture and align program states during translation. This approach is the first to leverage LLMs to insert instrumentation in both original and translated code, tracing program states at runtime. By prompting the LLM to correct errors based on output traces, we mitigate inconsistencies and enhance translation accuracy. Experimental results show significant improvements, with computational accuracy rising from 57.51% to 84.70% for GPT-4o, 50.68% to 69.97% for Mistral-Large-2, and 52.45% to 76.43% for DeepSeek-Coder-V2. These improvements are consistent across models and datasets, with ablation studies confirming the benefits of instrumentation and state alignment.
Key facts. Cited by 4 papers in the map (data through 14 Oct 2026). First posted on arXiv 2 Apr 2025.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2025: 2; 2026: 2.
4 papers.
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligencecited by 15
- 2025Automated Snippet-Alignment Data Augmentation for Code Translationcited by 0
- 2026Design-Specification Tiling for ICL-based CAD Code Generationcited by 0
- 2026CIT-CAD: Constraint Intent Tree-based CAD Code Generation and Verificationcited by 0
- 2026CIT-CAD: Constraint Intent Tree-based CAD Code Generation and Verification7 Sep 2026
- 2026Design-Specification Tiling for ICL-based CAD Code Generation13 Mar 2026
- 2025From Code Foundation Models to Agents and Applications: A Comprehensive Survey and Practical Guide to Code Intelligence23 Nov 2025
- 2025Automated Snippet-Alignment Data Augmentation for Code Translation16 Oct 2025