This article has multiple issues. Please help talk page. (Learn how and when to remove these template messages)( or discuss these issues on the Learn how and when to remove this template message)
A source-to-source compiler, transcompiler or transpiler is a type of compiler that takes the source code of a program written in one programming language as its input and produces the equivalent source code in another programming language. A source-to-source compiler translates between programming languages that operate at approximately the same level of abstraction, while a traditional compiler translates from a higher level programming language to a lower level programming language. For example, a source-to-source compiler may perform a translation of a program from Pascal to C. An automatic parallelizing compiler will frequently take in a high level language program as an input and then transform the code and annotate it with parallel code annotations (e.g., OpenMP) or language constructs (e.g. Fortran's
Another purpose of source-to-source-compiling is translating legacy code to use the next version of the underlying programming language or an API that breaks backward compatibility. It will perform automatic code refactoring which is useful when the programs to refactor are outside the control of the original implementer (for example, converting programs from Python 2 to Python 3, or converting programs from an old API to the new API) or when the size of the program makes it impractical or time consuming to refactor it by hand.
One of the earliest programs of this kind was Digital Research's XLT86 in 1981, a program written by Gary Kildall, which translated .ASM source code for the Intel 8080 processor into .A86 source code for the Intel 8086. Using global data flow analysis on 8080 register usage, the translator would also optimize the output for code size and take care of calling conventions, so that CP/M-80 and MP/M-80 programs could be ported to the CP/M-86 and MP/M-86 platforms automatically. XLT86 itself was written in PL/I-80 and was available for CP/M-80 platforms as well as for DEC VMS (for VAX 11/750 or 11/780).
A similar, but much less sophisticated program was TRANS.COM, written by Tim Paterson in 1980 as part of 86-DOS. It could translate some Z80 assembly source code into .ASM source code for the 8086, but supported only a subset of opcodes, registers and modes, often still requiring significant manual correction and rework afterwards. Also it did not carry out any register and jump optimizations.
|Source language||Target language||Comment|
|BASIC||C||Transcompiled using BaCon|
|BASIC||Object Pascal||Transcompiled using SHBASIC using his own BASIC dialect|
(originally known as "C with classes")
|C||The cfront transcompiler was doing the conversion|
|COBOL||C||Transcompiled using OpenCOBOL|
|COBOL||Java||Transcompiled using P3COBOL|
|Cython||C||The resulting code is intended to be compiled to a module for the Python interpreter CPython|
|Julia||C||Julia generates native code and works well without C (or with), but a modified implementation of the Julia's implementation can compile individual functions or whole programs to C.|
|Logtalk||Prolog||Supports most Prolog implementations|
|PHP||C++||Transcompiled using HipHop for PHP|
|Python||C++||Transcompiled using Nuitka and ShedSkin|
|Scheme||C||Stalin compiler, Chicken Scheme|
|Vala||C, with additional libraries such as GObject|
|X10||C++ and Java|
When developers want to switch to a different language while retaining most of an existing codebase, it might be better to use a transcompiler compared to rewriting the whole software by hand. Depending on the quality of the transcompiler, the code may or may not need manual intervention in order to work properly. This is different from "transcompiled languages" where the specifications demand that the output source code always works without modification. All transpilers used to port a codebase will expect manual adjustment of the output source code if there is a need to achieve maximum code quality in terms of readability and platform convention.
|Tool||Source language||Target language||Comments|
|2to3 script||Python 2||Python 3||Even though 2to3 does its best at automating the translation process, further manual corrections are often needed.|
|c2go||C||Go||Before the 1.5 release, the Go compiler was written in C. An automatic translator was developed to automatically convert the compiler codebase from C into Go. Since Go 1.5, the "compiler and runtime are now implemented in Go and assembler, without C".|
|J2Eif||Java||Eiffel||The resulting Eiffel code has classes and structures similar to the Java program but following Eiffel syntax and conventions.|
|C2Eif||C||Eiffel||The resulting Eiffel code has classes and structures that try to be as clean as possible. The tool is complete and relies on embedding the C and assembly code if it cannot translate it properly.|
|Swiftify||Objective-C||Swift||Swiftify is an online source to source conversion tool from Objective-C into Swift. It assists developers who are migrating all or part of their iOS codebase into Swift. The conversion is aimed primarily at converting the syntax between Objective-C and Swift, and is helped because Apple took efforts to ensure compatibility between Swift and Objective-C runtimes.|
|Runtime Converter||PHP||Java||The Runtime Converter is an automatic tool which converts php source code into java source code. There is a Java runtime library for certain features of the PHP language, as well as the ability to call into the PHP binary itself using JNI for PHP standard library and extension function calls.|
A transcompiler pipeline is what results from recursive transcompiling. By stringing together multiple layers of tech, with a transcompile step between each layer, technology can be repeatedly transformed, effectively creating a distributed language independent specification.
Manage research, learning and skills at defaultLogic. Create an account using LinkedIn or facebook to manage and organize your Digital Marketing and Technology knowledge. defaultLogic works like a shopping cart for information -- helping you to save, discuss and share.Visit defaultLogic's partner sites below: