Software systems frequently outlive the programming languages, APIs, and hardware architectures they were originally designed for. In high-performance computing (HPC), critical scientific simulations remain anchored to legacy Fortran codebases that struggle to leverage modern object-oriented designs or hardware accelerators (Bin Lei et al.; Nishath Rajiv Ranasinghe et al.). In enterprise software, developers spend up to 70% of their time on repetitive maintenance tasks, such as migrating away from deprecated APIs or refactoring sequential code into distributed frameworks (Jia Li et al.; Cristina David et al.).
Historically, migrating these large-scale codebases required manual rewrites or the construction of rule-based transpilers. Manual migration is prohibitively expensive and error-prone, while traditional transpilers are rigid and fail to scale because they cannot easily handle complex external libraries or diverse syntax (Aniketh Malyala et al.).
To overcome these limitations, a modern research direction combines machine learning, retrieval-augmented generation, and formal verification to automate program translation and multi-step code refactoring.
Learning to Translate Without Parallel Data
The core challenge of training machine learning models for source-to-source code translation (transpilation) is the scarcity of parallel data. Unlike natural language translation, where massive bilingual corpora exist, there are few large-scale datasets containing identical functions written in multiple programming languages.
To bypass this bottleneck, Baptiste Roziere et al. introduced TransCoder in Unsupervised Translation of Programming Languages, demonstrating that models can learn to translate functions between C++, Java, and Python using entirely monolingual source code.
Monolingual Source Code (Java) ───► [ Shared Embedding Space ] ◄─── Monolingual Source Code (Python)
│
▼
[ Cross-Lingual Mapping ]
This approach works because programming languages share fundamental structural patterns—such as loops, conditional branches, and variable assignments—and anchor tokens like standard mathematical operators or common library names. By training a model to reconstruct masked tokens within a single language and mapping different languages into a shared embedding space, the model learns to align the underlying semantics of distinct syntaxes without ever seeing a direct parallel example.
Overcoming Neural Blind Spots via Retrieval and Rules
While unsupervised neural models and large language models (LLMs) excel at capturing syntax, they suffer from predictable "blind spots," often generating plausible-looking code that contains subtle logic errors or invalid API calls (Aniketh Malyala et al.). To make neural translation reliable enough for production software, researchers combine parametric model memory with rule-based pre- and post-processing, as well as Retrieval-Augmented Generation (RAG).
Instead of relying solely on the weights of a pre-trained model, RAG pipelines look up real-world translation examples from a curated repository to guide the model's output. For instance, Manish Bhattarai et al. demonstrated that providing few-shot examples via RAG significantly improves the translation of legacy scientific code.
To maximize the utility of these retrieved examples, the authors later introduced task-specific embedding alignment in Enhancing Cross-Language Code Translation via Task-Specific Embedding Alignment in Retrieval-Augmented Generation. Rather than using generic text embeddings, they trained the retrieval mechanism to prioritize code examples that historically yielded the highest semantic similarity scores during translation. This ensures that the LLM receives contextually relevant structural blueprints, preventing syntax hallucinations.
Verified Lifting and Program Synthesis
For critical infrastructure, such as high-performance computing or distributed cloud systems, "mostly correct" code is unacceptable. To bridge the gap between neural flexibility and mathematical certainty, researchers utilize verified lifting—a technique that uses LLMs to generate candidate translations and formal methods to guarantee their correctness.
In Verified Code Transpilation with LLMs, Sahil Bhatia et al. developed LLMLIFT. This framework uses an LLM to translate general-purpose legacy code into highly optimized Domain-Specific Languages (DSLs), but routes the output through a Satisfiability Modulo Theories (SMT) solver. The solver acts as an automated judge, generating formal proofs of correctness to ensure that the optimized target code behaves identically to the source.
Legacy Code ──► [ Large Language Model ] ──► Candidate DSL Code ──► [ SMT Solver / Judge ] ──► Verified Code
│
(If Proof Fails)
│
▼
Refinement Loop
This hybrid paradigm also extends to architectural modernization. Maaz Bin Safeer Ahmad et al. developed Casper, a compiler that automatically translates sequential Java code into distributed MapReduce frameworks like Spark or Flink. Rather than relying on brittle pattern-matching rules, Casper uses program synthesis and automated theorem proving to discover semantically equivalent distributed implementations. By combining formal verification with a data-centric cost model, it guarantees functional equivalence while optimizing execution performance.
Navigating Multi-Step Refactoring and the Discovery Gap
Code migration is rarely a simple token-swapping exercise; it frequently requires complex, multi-step structural transformations. For example, migrating away from deprecated APIs often involves instantiating entirely new object hierarchies and managing complex state transitions rather than executing one-to-one function replacements (Cristina David et al.).
While symbolic frameworks like Cubix allow developers to write a refactoring transformation once and apply it across multiple languages (James Koppel et al.), LLMs offer a more flexible path for deep architectural rewrites. For example, Aya Lahlou et al. designed a multi-phase agentic pipeline that successfully translated a 19,000-line Fortran land surface model into JAX, a modern differentiable programming framework, unlocking massive simulation speedups.
Despite these successes, automating large-scale refactoring reveals a fundamental "discovery gap." In CodeTaste: Can LLMs Generate Human-Level Code Refactorings?, Alex Thillen et al. discovered that while AI agents excel at executing structural changes when provided with a detailed refactoring blueprint, they almost completely fail to identify what needs to be refactored when given only a vague focus area.
Because automated tools cannot yet fully replicate human architectural intuition, current deployment models favor human-AI partnerships. As Michael J. Muller et al. demonstrate, automated translation tools provide an invaluable "head start" for software engineers, provided the development environment includes features like confidence highlighting and alternative translations to assist humans in verifying and refining the output.
Key Foundational Work
A System which Automatically Improves Programs (1973) — contributed 1 concept elements to this direction.
Theory of Linear Equations Applied to Program Transformation (1983) — contributed 1 concept elements to this direction.