Source-to-source compiler: Difference between revisions

Content deleted Content added
GreenC bot (talk | contribs)
Rescued 5 archive links; reformat 5 links. Wayback Medic 2.5 per WP:USURPURL and JUDI batch #20
Altered template type. Add: chapter-url, chapter, title. Removed or converted URL. | Use this tool. Report bugs. | #UCB_Gadget
 
(9 intermediate revisions by 7 users not shown)
Line 5:
{{Program execution}}
{{Data transformation}}
A '''source-to-source translator''', '''source-to-source compiler''' ('''S2S compiler'''), '''transcompiler''', or '''transpiler'''<ref name="ARC_1988_Transpiler"/><ref name="Pountain_1989"/><ref name="Sector7_1993_Transpiler"/> is a type of [[translatorTranslator (computing)|translator]] that takes the [[source code]] of a program written in a [[programming language]] as its input and produces an equivalent source code in the same or a different programming language, usually as an [[intermediate representation]]. A source-to-source translator converts between programming languages that operate at approximately the same level of [[abstractionAbstraction (computer science)|abstraction]], while a traditional [[compiler]] translates from a [[highHigh-level programming language|higher level programming language]] to a [[lowLow-level programming language|lower level programming language]]. For example, a source-to-source translator may perform a translation of a program from [[Python (programming language)|Python]] to [[JavaScript (programming language)|JavaScript]], while a traditional compiler translates from a language like [[C (programming language)|C]] to [[Assembly language|assembly]] or [[Java (programming language)|Java]] to [[Java bytecode|bytecode]].<ref name="Devopedia_Transpiler"/> 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 <code>forall</code> statements).<ref name="Pountain_1989"/><ref name="Compiler_Types"/>
 
Another purpose of source-to-source-compiling is translating legacy code to use the next version of the underlying programming language or an application programming interface ([[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 structure 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.<ref name="Fowler_2013"/> There are also debugging utilities that map the transcompiled source code back to the original code; for example, the [[JavaScript]] Source Map standard{{Citation needed|reason=Not a standard|date=September 2020}} allows mapping of the JavaScript code executed by a [[web browser]] back to the original source when the JavaScript code was, for example, minified or produced by a transcompiled-to-JavaScript language.{{Citation needed|date=September 2020}}
Line 49:
|-
|[[Babel (transpiler)|Babel]]
|[[ECMAScript|ES6+]] 6+ ([[JavaScript|JS]])
|ES5
|
Line 59:
|-
|[[Cfront]]
|[[C++]]
|[[C (programming language)|C]]
|
Line 65:
|[[ClojureScript]]
|[[Clojure]]
|JavaScript
|
|-
|[[CoffeeScript]]
|[[CoffeeScript]]
|JavaScript
|
Line 70 ⟶ 75:
|[https://dafny.org Dafny]
|[[Dafny (programming language)|Dafny]]
|C#, [[JavaScript|JS]], [[Java (programming language)|Java]], C++, [[Go (programming language)|Go]], [[Python (programming language)|Python]]
|
|-
Line 80 ⟶ 85:
|h5<ref name="Olivenbaum"/>
|[[C Sharp (programming language)|C#]]
|JavaScript
|
|-
|[[Eiffel (programming language)|Eiffel]], via [[EiffelStudio]]
|Eiffel
|C, [[Common Intermediate Language]]
|
|-
|[[Elm_(programming_language)|Elm]]
|[[Elm]]
|JavaScript
|
Line 88 ⟶ 103:
|
|-
|[[HipHop for PHP|HipHop]] for PHP (HPHPc)
|[[PHP]]
|C++
Line 116 ⟶ 131:
|[[Rust (programming language)|Rust]]
|C
|Experimental compiler that is able to bootstrap the official rustRust compiler (rustc)
|-
|[https://nim-lang.org/ Nim]
|[[Nim (programming language)|Nim]]
|C, C++, [[Objective-C]], JavaScript
|
|-
|[[PureScript]]
|[[PureScript]]
|JavaScript
|
|-
|[[Reason_(programming_language)|ReasonML]]
|[[Reason]]
|JavaScript
|
|-
|[https://rescript-lang.org/ ReScript]
|[[OCaml]]
|JavaScript
|
|-
|[[Sather]]
|Sather
|C
|
|-
|-
|[[Scala (programming language)#Other_compilers_and_targets|Scala.js]]
|[[Scala (programming language)|Scala]]
|JavaScript
|
Line 131 ⟶ 167:
|[[Objective-C]]
|[[Swift (programming language)|Swift]]
|
|-
|[[V (programming language)|V]]
|V
|C
|
|-
|[[Vala (programming language)|Vala]]
|Vala
|C
|
|-
|[[Visual Eiffel]]
|[[Eiffel (programming language)|Eiffel]]
|C
|
Line 186 ⟶ 232:
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|language independent specification]].
 
[[XSLT]] is a general-purpose transform tool that can be used between many different technologies, to create such a [[derivative code]] pipeline.<ref name="W3C_XSLT2">World Wide Web Consortium (W3C). "XSL Transformations (XSLT) Version 2.0". https://www.w3.org/TR/xslt-20/</ref>
 
=== Recursive transcompiling ===
Line 237 ⟶ 283:
<ref name="Scanlon_1988">{{cite book |title=8086/8088/80286 assembly language |author-last=Scanlon |author-first=Leo J. |date=1988 |publisher=Brady Books |isbn=978-0-13-246919-7 |page=[https://archive.org/details/8086808880286ass0000scan/page/12 12] |url=https://archive.org/details/8086808880286ass0000scan/page/12 |quote=[…] The [[8086]] is software-compatible with the [[8080]] at the assembly-language level. […]}}</ref>
<ref name="Kildall_1972_Optimization">{{Cite book |title=Global expression optimization during compilation |author-first=Gary Arlen |author-last=Kildall |author-link=Gary Arlen Kildall |type=Ph.D. dissertation |publisher=[[University of Washington]], Computer Science Group |___location=Seattle, Washington, USA |date=May 1972 |id=Thesis No. 20506, Technical Report No. 72-06-02}}</ref>
<ref name="Kildall_1973_Optimization">{{Cite journalbook |author-first=Gary Arlen |author-last=Kildall |author-link=Gary Kildall |date=1973-10-01 |title=A Unified Approach to Global Program Optimization |journal=Proceedings of the 1st Annualannual ACM SIGACT-SIGPLAN Symposiumsymposium on Principles of Programmingprogramming Languageslanguages (POPL)- |series=POPL '73 |chapter=A unified approach to global program optimization |author-link=Gary Kildall |date=1973-10-01 |___location=Boston, Massachusetts, USA |pages=194–206 |doi=10.1145/512927.512945 |hdl=10945/42162 |s2cid=10219496 |chapter-url=http://static.aminer.org/pdf/PDF/000/546/451/a_unified_approach_to_global_program_optimization.pdf |access-date=2006-11-20 |url-status=live |archive-url=https://web.archive.org/web/20170629213307/http://static.aminer.org/pdf/PDF/000/546/451/a_unified_approach_to_global_program_optimization.pdf |archive-date=2017-06-29}}</ref>
<ref name="XLT86_1981">{{cite book |date=September 1981 |title=XLT86 – 8080 to 8086 Assembly Language Translator – User's Guide |edition=First printing |publisher=[[Digital Research, Inc.]] |___location=Pacific Grove, California, USA |url=http://www.s100computers.com/Software%20Folder/Assembler%20Collection/Digital%20Research%20XLT86%20Manual.pdf |access-date=2016-11-18 |url-status=live |archive-url=https://web.archive.org/web/20161118230700/http://www.s100computers.com/Software%20Folder/Assembler%20Collection/Digital%20Research%20XLT86%20Manual.pdf |archive-date=2016-11-18|id=[https://archive.org/stream/bitsavers_digitalResuideSep81_2620625/XLT86_Users_Guide_Sep81_djvu.txt archive.org copy]}}</ref>
<ref name="Digital_Research_1981_News">{{cite magazine |title=XLT86 Reduces Conversion Effort in Assembly Language Program Translation |series=Product Update |magazine=Digital Research News – for Digital Research Users Everywhere |publisher=[[Digital Research, Inc.]] |___location=Pacific Grove, California, USA |date=November 1981 |volume=1 |number=1 |id=Fourth Quarter |pages=2, 7 |url=https://amaus.net/static/S100/software/DRI/Digital%20Research%20News/01x01%201981%20Digital%20Research%20News.pdf |archive-url=https://web.archive.org/web/20211110124333/https://amaus.net/static/S100/software/DRI/Digital%20Research%20News/01x01%201981%20Digital%20Research%20News.pdf |url-status=usurped |archive-date=10 November 2021 |access-date=2020-01-18 |quote=[…] An 8- to 16-bit assembly code translator is now available from [[Digital Research]]. Called XLT86, it is designed to help ease the time-consuming process of converting [[CP/M]] software products from [[8080]]- to [[8086]]-based microcomputers. XLT86 can be used to translate any assembly language programs that are compatible with Digital Research's ASM, MAC or RMAC assembler format. The XLT86 program translator first reads an 8080 assembly language program and then produces an output file containing 8086 assembly language statements acceptable to the Digital Research ASM-86 assembler. Unlike other 8086 code converters that translate a single 8080 instruction into as many as ten 8086 instructions, XLT86 performs extensive [[data flow analysis]] to determine register usage throughout the original program. The information collected through this analysis is used during program translation to eliminate unnecessary flag save and restore operations. "The resulting 8086 program is both simpler and more compact than equivalent programs produced by other translators," according to Curt Geske, of the Digital Research marketing group. "Furthermore, XLT86 allows OEMs, end users and software vendors to preserve their investment in 8080-based assembly language programs when changing to 16-bit 8086-based computers by reducing the conversion effort." Programs translated by XLT86 run on both [[CP/M-86]] and [[MP/M-86]] […] XLT86 is available immediately. It operates on any 8-bit CP/M or [[MP/M]] system, or under the [[OpenVMS|VMS]] operating-system for use on [[Digital Equipment Corporation]] [[DEC VAX|VAX]] series [[minicomputer]]s. The CP/M version is priced at [[United States dollar|$]]150. The VAX version sells for $8,000. […]}}</ref>
Line 276 ⟶ 322:
<ref name="Sector7_1993_Transpiler">{{cite news |title=Transpiler |author=((Sector 7 Software Limited)) |___location=Bedford, Bedfordshire, UK |newspaper=[[Official Gazette of the United States Patent and Trademark Office]] |volume=1157 |edition=1 |date=1993-12-07 |orig-date=1992-09-22 |publisher=[[U.S. Patent and Trademark Office]] |page=TM&nbsp;81 |series=Class 9 |id=SN&nbsp;74-316.610 |url=https://books.google.com/books?id=Aokm04NulboC&pg=RA1-PA81 |access-date=2020-01-18 |url-status=live |archive-url=https://web.archive.org/web/20200201130513/https://books.google.de/books?id=Aokm04NulboC&pg=RA1-PA81&lpg=RA1-PA81&redir_esc=y |archive-date=2020-02-01 |quote=[…] Priority claimed under Sec. 44(D) on United Kingdom Application No. 1495953, filed 1992-03-31 Reg. No. A1495953, dated 1992-03-31, expires 1999-03-31. For computer software and programs (U.S. Cl. 38). First use 1991-08-01, in commerce 1991-08-01.}} (NB. This company develops products such as VX/BASIC, a BASIC-to-C transpiler for [[DEC VMS]]. Despite their claim, theirs is not the first public use of the term transpiler, see i.e. [[#ARC-1988|ARC's BASIC-to-C transpiler]] for the [[Amiga]] in 1988 and the [[#Pountain-1989|Occam Transpiler]] by Concurrent Technology Systems (CTS)<!-- by Meier and Wespi --> in 1989.)</ref>
<ref name="Ocam1">{{cite web |title=Overview |work=Js_of_ocaml - Reference Manual |publisher=Ocsigen |url=http://ocsigen.org/js_of_ocaml/manual/overview |access-date=2014-10-08 |archive-url=https://web.archive.org/web/20181208123603/http://ocsigen.org/js_of_ocaml/manual/overview |archive-date=2018-12-08}}</ref>
<ref name="J2EIF">{{cite book |title=J2Eif Research Page – Chair of Software Engineering |date=2011 |pages=20–35 |doi=10.1007/978-3-642-21952-8_4 |publisher=Se.inf.ethz.ch |isbn=978-3-642-21952-8 |url=http://se.inf.ethz.ch/research/j2eif/ |access-date=2014-07-08 |url-status=live |archive-url=https://web.archive.org/web/20200101165402/http://se.inf.ethz.ch/research/j2eif/ |archive-date=2020-01-01}}</ref>
<ref name="C2EIF">{{cite web |title=C2Eif Research Page – Chair of Software Engineering |publisher=Se.inf.ethz.ch |url=http://se.inf.ethz.ch/research/c2eif/ |access-date=2014-07-08 |url-status=live |archive-url=https://web.archive.org/web/20200101165402/http://se.inf.ethz.ch/research/c2eif/ |archive-date=2020-01-01}}</ref>