[Paper Review] Learning C to x86 Translation: An Experiment in Neural Compilation
This paper investigates neural compilation by training Transformer models to translate C code into x86 assembly, treating compilation as a sequence-to-sequence task. Despite achieving 80% syntactic correctness and high BLEU scores (~90), the best model compiles only 33% of functions correctly, especially struggling with complex functions involving arrays and multiple arguments.
Deep learning has had a significant impact on many fields. Recently, code-to-code neural models have been used in code translation, code refinement and decompilation. However, the question of whether these models can automate compilation has yet to be investigated. In this work, we explore neural compilation, building and evaluating Transformer models that learn how to produce x86 assembler from C code. Although preliminary results are relatively weak, we make our data, models and code publicly available to encourage further research in this area.
Motivation & Objective
- To investigate whether deep learning models can automate end-to-end compilation from high-level C code to x86 assembly.
- To evaluate the feasibility of supervised neural compilation as a foundation for future unsupervised compilation of new languages and ISAs.
- To build and release a parallel C-x86 assembler corpus for future research in neural compilation.
- To analyze the limitations of sequence-to-sequence models in handling complex control flow and data structures in compilation tasks.
Proposed method
- Formalizes machine compilation as a sequence-to-sequence task using the Transformer architecture.
- Constructs a parallel C-to-x86 assembler dataset using Anghabench, a function-level C corpus, and GCC-generated assembly.
- Trains Transformer models with maximum likelihood estimation on the parallel corpus, varying data size, model size, and hyperparameters.
- Evaluates models using BLEU scores for syntactic similarity and manual inspection for semantic correctness.
- Uses subword tokenization to handle rare or out-of-vocabulary tokens in C and assembly code.
- Employs a benchmark from a program synthesis evaluation set to test semantic correctness of compiled functions.
Experimental results
Research questions
- RQ1Can Transformer-based models learn to translate C functions into semantically correct x86 assembly?
- RQ2How does model performance vary with training data size, model capacity, and training duration?
- RQ3To what extent can neural models generate syntactically correct assembly, and how often is it semantically meaningful?
- RQ4What are the failure modes of neural compilation, particularly for functions with arrays and multiple arguments?
- RQ5Is it feasible to use supervised neural models as a starting point for unsupervised compilation of new programming languages and ISAs?
Key findings
- The best model achieves approximately 80% syntactic correctness in generating x86 assembly from C code.
- BLEU scores reach around 90 on certain benchmarks, indicating strong surface-level similarity to reference assembly.
- Only 33% of functions in the benchmark are compiled correctly, with significant failure on functions involving arrays and multiple arguments.
- The model frequently produces short, syntactically valid but semantically meaningless assembly when inputs are complex, mimicking an unconditional assembler language model.
- Syntax errors such as unbalanced parentheses occur when the model terminates generation prematurely, indicating issues with sequence length and decoding control.
- Despite high BLEU scores, semantic correctness remains a major challenge, highlighting the gap between surface-level and functional equivalence in compilation.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.