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. 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.
翻译:在本文中,我们利用低水平的编译者中间演示来改进代码翻译。 传统翻译者依靠综合信息和手工设计的规则来改进代码翻译。 传统翻译者依靠综合信息和手写规则,这限制了它们的可适用性,并产生了异常的代码。 应用神经机翻译方法成功地扩大了一套程序, 从而可以进行自然的翻译。 但是, 他们将代码作为文本符号的序列处理, 并且仍然没有充分区分使用不同语言的语义的类似代码。 结果是低质量翻译, 降低NMT的实用性, 并强调需要一种方法来大大提高其准确性。 我们在这里建议增加与IRs的代码翻译, 特别是LLLVM IR, 并在 C++、 Java、 Rust 和 Go 语言上的结果。 我们的方法改进了不受监管的代码翻译的艺术状态, 平均将正确翻译的数量增加11%, 并且将Java - Rust 配对的79% 。 我们扩展了以前的代码翻译测试组, 增加了数百个 Go 和 Rst 函数的精确翻译。 此外, 我们用高性化的模型来进行IR 的版本的测试。