LEGO-Compiler: Enhancing Neural Compilation Through Translation Composability
Shuoming Zhang, Jiacheng Zhao, Chunwei Xia, Zheng Wang, Yunji Chen, Xiaobing Feng, Huimin Cui
TL;DR
LEGO-Compiler introduces a scalable neural compilation framework that uses LEGO translation to decompose large programs into composable control blocks, paired with a verifiable, stepwise workflow and a self-correction loop. The method achieves high behavioral accuracy on real-world benchmarks ($>99\%$ on ExeBench and $97.9\%$ on AnsiBench) and demonstrates near an order-of-magnitude improvements in code-size scalability, validated through formal composability proofs and extensive experiments. By reducing context length and enabling modular translation, the approach offers a practical pathway for LLMs to contribute to system-level tasks while complementing traditional compilers. Limitations include handling highly dynamic language features and very large codebases, with future work focusing on integration with external tools, broader architecture support, and optimization techniques.
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.
