Table of Contents
Fetching ...

Code Translation with Compiler Representations

Marc Szafraniec, Baptiste Roziere, Hugh Leather, Francois Charton, Patrick Labatut, Gabriel Synnaeve

TL;DR

The paper tackles unreliable cross-language code translation by introducing compiler intermediate representations as an auxiliary modality. It uses LLVM IR to augment source-code representations and trains models for code translation and decompilation, evaluating on C++, Java, Rust, and Go. Compared to a code-only baseline (TransCoder) and an IR-only pivot method, the IR-augmented approach achieves an average 11% relative improvement in correct translations, with up to 170% improvement over the pivot, and substantial gains in low-data regimes (e.g., 26% to Rust). The study extends the evaluation dataset with hundreds of Go and Rust functions and demonstrates strong IR decompilation performance, up to 78% accuracy in decompiling LLVM IR to C++. These results suggest that leveraging IRs can significantly improve neural code translation reliability without adding inference-time cost.

Abstract

In this paper, we leverage low-level compiler intermediate representations (IR) to improve code translation. Traditional transpilers rely on syntactic information and handcrafted rules, which limits their applicability and produces unnatural-looking code. Applying neural machine translation (NMT) approaches to code has successfully broadened the set of programs on which one can get a natural-looking translation. However, they treat the code as sequences of text tokens, and still do not differentiate well enough between similar pieces of code which have different semantics in different languages. The consequence is low quality translation, reducing the practicality of NMT, and stressing the need for an approach significantly increasing its accuracy. Here we propose to augment code translation with IRs, specifically LLVM IR, with results on the C++, Java, Rust, and Go languages. Our method improves upon the state of the art for unsupervised code translation, increasing the number of correct translations by 11% on average, and up to 79% for the Java -> Rust pair with greedy decoding. We extend previous test sets for code translation, by adding hundreds of Go and Rust functions. Additionally, we train models with high performance on the problem of IR decompilation, generating programming source code from IR, and study using IRs as intermediary pivot for translation.

Code Translation with Compiler Representations

TL;DR

The paper tackles unreliable cross-language code translation by introducing compiler intermediate representations as an auxiliary modality. It uses LLVM IR to augment source-code representations and trains models for code translation and decompilation, evaluating on C++, Java, Rust, and Go. Compared to a code-only baseline (TransCoder) and an IR-only pivot method, the IR-augmented approach achieves an average 11% relative improvement in correct translations, with up to 170% improvement over the pivot, and substantial gains in low-data regimes (e.g., 26% to Rust). The study extends the evaluation dataset with hundreds of Go and Rust functions and demonstrates strong IR decompilation performance, up to 78% accuracy in decompiling LLVM IR to C++. These results suggest that leveraging IRs can significantly improve neural code translation reliability without adding inference-time cost.

Abstract

In this paper, we leverage low-level compiler intermediate representations (IR) to improve code translation. Traditional transpilers rely on syntactic information and handcrafted rules, which limits their applicability and produces unnatural-looking code. Applying neural machine translation (NMT) approaches to code has successfully broadened the set of programs on which one can get a natural-looking translation. However, they treat the code as sequences of text tokens, and still do not differentiate well enough between similar pieces of code which have different semantics in different languages. The consequence is low quality translation, reducing the practicality of NMT, and stressing the need for an approach significantly increasing its accuracy. Here we propose to augment code translation with IRs, specifically LLVM IR, with results on the C++, Java, Rust, and Go languages. Our method improves upon the state of the art for unsupervised code translation, increasing the number of correct translations by 11% on average, and up to 79% for the Java -> Rust pair with greedy decoding. We extend previous test sets for code translation, by adding hundreds of Go and Rust functions. Additionally, we train models with high performance on the problem of IR decompilation, generating programming source code from IR, and study using IRs as intermediary pivot for translation.
Paper Structure (1 section, 1 figure)

This paper contains 1 section, 1 figure.

Table of Contents

  1. Introduction