LEGO-Compiler: Enhancing Neural Compilation Through Translation Composability

Shuoming Zhang, Jiacheng Zhao, Chunwei Xia, Zheng Wang, Yunji Chen, Xiaobing Feng, Huimin Cui · 2025

Read LEGO-Compiler: Enhancing Neural Compilation Through Translation Composability by Shuoming Zhang, Jiacheng Zhao, Chunwei Xia, Zheng Wang, Yunji Chen, Xiaobing Feng, Huimin Cui (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2505-20356.txt.

Introduction

Shuoming Zhang and six co-authors present LEGO-Compiler, a system that uses large language models to compile high-level code into assembly, in a two thousand twenty-five paper. Language models handle short programs well but struggle with long, complex ones.

The system splits the input program into manageable blocks, translates them through a verifiable workflow checked by external tests, and self-corrects using feedback. Formal proofs of translation composability back the block-by-block design. Accuracy exceeds ninety-nine percent on ExeBench and reaches about ninety-eight percent on the industrial AnsiBench. Compilable code size improves by nearly an order of magnitude, suggesting language models can complement traditional compilers on system-level tasks.

Catalog record

CREATORShuoming Zhang, Jiacheng Zhao, Chunwei Xia, Zheng Wang, Yunji Chen, Xiaobing Feng, Huimin Cui
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE69 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2505-20356

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

LEGO-Compiler: Enhancing Neural Compilation Through Translation Composability Shuoming Zhang, Jiacheng Zhao, Chunwei Xia, Zheng Wang, Yunji Chen, Xiaobing Feng, Huimin Cui Abstract Large language models (LLMs) have the potential to revolutionize how we design and implement compilers and code translation tools. However, existing LLMs struggle to handle long and complex programs. We introduce LEGO-Compiler, a novel neural compilation system that leverages LLMs to translate high-level languages into assembly code. Our approach centers on three key innovations: LEGO translation, which decomposes the input program into manageable blocks; breaking down the complex compilation process into smaller, simpler verifiable steps by organizing it as a verifiable LLM workflow by external tests; and a feedback mechanism for self-correction. Supported by formal proofs of translation composability, LEGO-Compiler demonstrates high accuracy on multiple datasets, including over 99% on ExeBench and 97.9% on industrial-grade AnsiBench. Additionally, LEGO-Compiler has also acheived near one order-of-magnitude improvement on compilable code size scalability. This work opens new avenues for applying LLMs to system-level tasks, complementing traditional compiler technologies. 1 Introduction The rapid development of Large Language Models (LLMs) has led to an expansion of their applications and effectiveness across various domains ( rombach2022high ; openai2023chatgpt ; sora2024 ; copilot2024 ) . One important area where LLMs have shown impressive results is code translation, including tasks such as code generation from natural languages ( zan-etal-2023-large ) and transformation between programming languages ( llmcodetranslation2024fse ) . In code translation, LLMs have demonstrated remarkable accuracy and readability, often surpassing manually crafted translators. While LLMs have shown promising results in translating between high-level programming languages ( roziere2020unsupervised ; roziere2021leveraging ; CodeGen-ICLR23 ) and in decompilation tasks ( decompile-fu2019coda ; decompile-cao2022boosting ; decompile-armengol2023slade ) , their application to translating from high-level languages to low-level assembly languages remains a relatively unexplored area, which is traditionally dominated by handcrafted compilers. However, compilers require significant engineering effort and are tailored to specific languages/architectures. It is interesting to explore whether LLMs can be used to automate the compilation process, and if so, to what extent they can achieve this. Although earlier investigations armengol2021learning ; c2llvm-HPEC22 have shown low translation accuracy, recent work llmcompiler2024emnlp has shown that LLMs finetuned with compiler-generated bilingual corpora can outperform advanced LLMs in C-x86 compilation tasks and can achieve up to 91% behavioral accuracy. However, an in-depth understanding of LLMs’ capabilities in this domain is still lacking. As compilation is typically divided into two main aspects: translation and optimization. This work focuses on exploring and answering about LLM capabilities in the translation aspect of compilation. LLMs are pre-trained on vastly large code corpora. some are monolingual, and some may be bilingual (where LLMs can learn the translation rule between two languages). However, most of these LLMs do not disclose their training datasets, so their capabilities can only be assessed through empirical testing. We primarily find that current LLMs learn the neural compilation process from directly compiler-generated bilingual corpora, which is an intuitive way to construct a pretraining dataset and teach LLMs to compile. However, we also found that assembly code directly generated by compilers is hard for LLMs to learn due to several challenges. These include the presence of semantically opaque labels, symbols or numeric values that LLMs struggle to translate accurately, and the need to handle symbol renaming for identifiers with the same name in different scopes, etc. Although style migration or modifications to existing compilers can be made, these approaches still rely on an existing compiler to perform the neural compilation job, which doesn’t outperform existing designs. Our work takes a different approach where we do not require bilingual corpora, as a result, we don’t necessarily rely on an existing compiler. We guide LLMs to transform high-level code into assembly code step-by-step. To achieve this, we first propose an adaptive compilation-knowledge guided LLM workflow, which involves a series of steps with verifications to ensure stepwise correctness, including control flow annotation, struct annotation, renaming transformation, variable mapping transformation and final assembly generation. By splitting the complex compilation task into smaller, manageable steps, we significantly reduce the task complexity in each step by forcing LLMs to focus on certain easier step and achieve substantial improvements in overall accuracy. More importantly, the scalability of current code translation is an important and challenging problem. Although advanced LLMs already have hundreds of thousands tokens context limit, they can not merely compile a code with 2.6k tokens in CoreMark ( gal2012coremark ) , which is just a 200-LOC function. The major challenges within this significant LLM failure are two-fold: (1) the complexity within each expression/statement, and (2) the complexity of program structures. (1) is continuingly improved with more advanced LLMs or with proper knowledge guidance and is not our research focus. However, (2) is more fundamentally challenging, as a program can be arbitrarily large and complex, and LLMs are not designed to handle such complexity, direct LLM translation is just not scalable. To tackle this scalability problem, we propose LEGO translation , which draws inspiration from the modular and composable nature of LEGO blocks to divide-and-conquer it. This method breaks down large programs into manageable, semantically-composable control blocks, analogous to LEGO pieces. These blocks are then independently translated and rebuilt to form a full translation in much larger scale. We combine the novel LEGO translation method with our proposed neural compilation workflow, and design LEGO-Compiler , a scalable, LLM-driven system that leverages the power of LLMs to perform scalable neural compilation tasks. LEGO-Compiler can correctly compile over 99% of the code in ExeBench ( armengol2022exebench ) , a large scale dataset with careful unit-testing. We can also correctly compile 97.9% of AnsiBench ansibench2011github , a collection of well-known ANSI C standard benchmark suites, including CoreMark ( gal2012coremark ) , an industrial-grade codebase that encompasses most common programming language features in C, where we compile all of its 40 functions correctly. Regarding scalability, we have verified that LEGO translation method can significantly scale up the capability of neural code translation performed by LLMs. By ablating LEGO-Compiler methods in AnsiBench evaluation and additional Csmith csmith2011pldi evaluation, a random C code generator for compiler testing, LEGO translation scales up the available code size for neural compilation by near an order of magnitude. The main contributions of this work are as follows: • We propose the novel LEGO translation method to scale up the neural compilation task. By breaking down large programs into manageable, semantically-composable control blocks, the complexity of neural compilation tasks for LLMs is significantly reduced. • We propose a novel verifiable step-by-step neural compilation workflow that guides LLMs to transform high-level code into low-level assembly. With breakdown steps, we characterize and evaluate the compilation process in LLM’s perspective, and achieve substantial improvements in behavioral accuracy compared to end-to-end translation. • We provide both theoretical and empirical studies by formally defining the composability in code translation that underpins the LEGO translation method and empirically demonstrating LEGO-Compiler’s effectiveness through extensive evaluations. LEGO-Compiler achieve over 99% accuracy on ExeBench, 97.9% accuracy on AnsiBench. Ablation study also showcases that LEGO translation boosts the scalability of neural-compilable code size by an order of magnitude. The model-independent evaluation process also serves as an important benchmark for LLMs on complex system-level tasks. 2 Related Work 2.1 Code Translation

Read the complete text