Source-to-source Compiler

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 forall statements).[1]

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.

Transcompilers may either keep translated code as close to the source code as possible to ease development and debugging of the original source code, or may change the structure of the original code so much that the translated code does not look like the source code.[2] There are also debugging utilities that map the transpiled source code back to the original code; for example, the JavaScript Source Map[3] standard allows mapping of the JavaScript code executed by a web browser back to the original source in a transpiled-to-JavaScript language.[4]

Examples of transcompiled languages include Closure Compiler, CoffeeScript, Dart, Haxe, TypeScript and Emscripten.[5]


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).[6]

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.[7][8]

Programming language implementations

The first implementations of some programming languages started as transcompilers, and the default implementation for some of those languages are still transcompilers. In addition to the table below, a CoffeeScript maintainer provides a list of languages that compile to JavaScript.[9]

Porting a codebase

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.

Transcompiler pipelines

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.

XSLT is a general purpose transform tool which can be used between many different technologies, to create such a derivative code pipeline.

See also


  1. ^ "Types of compilers". 1997-2005. Retrieved 2010. 
  2. ^ Fowler, Martin (February 12, 2013). "Transparent Compilation". Retrieved 2013. 
  3. ^ Lenz, Fitzgerald (11 February 2011). "Source Map Revision 3 Proposal". 
  4. ^ Seddon, Ryan (21 March 2012). "Introduction to JavaScript Source Maps". Retrieved 2015. 
  5. ^ Epic Games; Mozilla. "HTML5 Epic Citadel". 
  6. ^ Digital Research (1981). XLT86 - 8080 to 8086 Assembly Language Translator - User's Guide (PDF). Pacific Grove, CA, USA: Digital Research Inc. Archived (PDF) from the original on 2016-11-18. Retrieved . 
  7. ^ Seattle Computer Products (1980): 86-DOS - Disk Operating System for the 8086. User's manual, version 0.3 - Preliminary. Seattle Computer Products, Seattle ([1]).
  8. ^ Paterson, Tim (2013-12-19) [1982]. "Microsoft DOS V1.1 and V2.0: Z80 to 8086 Translator version 2.21 /msdos/v11source/TRANS.ASM". Computer History Museum, Microsoft. Retrieved .  (NB. While the publishers claim this would be MS-DOS 1.1 and 2.0, it actually is SCP MS-DOS 1.25 and TeleVideo PC DOS 2.11.)
  9. ^ "List of languages that compile to JS". Retrieved . 
  10. ^ Peter van Eerten. "BaCon - A free BAsic CONverter for Unix, BSD and MacOSX". Retrieved . 
  11. ^ Iushin Software. "SHBASIC". Iushin Softwares. Retrieved . 
  12. ^ "Script# by nikhilk". Retrieved . 
  13. ^ "Smart Mobile Studio". Retrieved . 
  14. ^ "Babel · The compiler for writing next generation JavaScript". Retrieved . 
  15. ^ "Traceur is a compiler". Retrieved . 
  16. ^ "j2objc - Java to iOS Objective-C translation tool and runtime". 2014-02-13. Retrieved . 
  17. ^ "java2c-transcompiler - A simple source-to-source from Java to C - Google Project Hosting". Retrieved 2014. 
  18. ^ "IntelLabs/julia". GitHub. 
  19. ^ "Google Groups". 
  20. ^ "MoonScript, a language that compiles to Lua". Retrieved . 
  21. ^ "Shed Skin, An experimental (restricted-Python)-to-C++ compiler". Retrieved . 
  22. ^ Maptastic Maple (3.3.9). "Sass: Syntactically Awesome Style Sheets". Retrieved . 
  23. ^ "Xtend, modernized Java". Eclipse project. Retrieved . 
  24. ^ "C->Go translator". Retrieved 2018. 
  25. ^ "Go 1.5 Release Notes". Retrieved 2018. 
  26. ^ Russ Cox. "Go 1.3+ Compiler Overhaul". Retrieved 2018. 
  27. ^ "Js_of_ocaml". Retrieved 2014. 
  28. ^ "J2Eif Research Page - Chair of Software Engineering". doi:10.1007/978-3-642-21952-8_4. Retrieved . 
  29. ^ "C2Eif Research Page - Chair of Software Engineering". Retrieved . 
  30. ^ "Swiftify Objective-C to Swift Converter". Retrieved . 
  31. ^ "Runtime Converter". Retrieved . 

  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.



Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.

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: : Music Genres | Musicians | Musical Instruments | Music Industry
NCR Works : Retail Banking | Restaurant Industry | Retail Industry | Hospitality Industry

  Contact Us