ArticleslgStudy

computer science

Source-to-source compiler

Source-to-source compiler is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Source-to-source compiler rather than just read about it. In short: A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler is a type of 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 o…

Key takeaways

  • Source-to-source compiler belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Source-to-source compiler to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Source-to-source compiler from memory before moving on to harder problems.

Reference excerpt

A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler is a type of 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 abstraction, while a traditional compiler translates from a higher level language to a lower level language. For example, a source-to-source translator may perform a translation of a program from Python to JavaScript, while a traditional compiler translates from a language like C to assembly or Java to bytecode. 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). 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. There are also debugging utilities that map the transcompiled source code back to the original code; for example, the JavaScript Source Map standard 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. Examples include Closure Compiler, CoffeeScript, Dart, Haxe, Opal, TypeScript and Emscripten.

Assembly language translators So called Assembly language translators are a class of source-to-source translators converting code from one assembly language into another, including (but not limited to) across different processor families and system platforms.

Intel CONV86

Intel marketed their 16-bit processor 8086 to be source compatible to the 8080, an 8-bit processor. To support this, Intel had an ISIS-II-based translator from 8080 to 8086 source code named CONV86 (also referred to as CONV-86 and CONVERT 86) available to OEM customers since 1978, possibly the earliest program of this kind. It supported multiple levels of translation and ran at 2 MHz on an Intel Microprocessor Development System MDS-800 with 8-inch floppy drives. According to user reports, it did not work very reliably.

SCP TRANS86 Seattle Computer Products (SCP) offered TRANS86.COM, written by Tim Paterson in 1980 while developing 86-DOS. The utility could translate Intel 8080 and Zilog Z80 assembly source code (with Zilog/Mostek mnemonics) into .ASM source code for the Intel 8086 (in a format only compatible with SCP's cross-assembler ASM86 for CP/M-80), but supported only a subset of opcodes, registers and modes, and often still required significant manual correction and rework afterwards. Also, performing only a mere transliteration, the brute-force single-pass translator did not carry out any register and jump optimizations. It took about 24 KB of RAM. The SCP version 1 of TRANS86.COM ran on Z80-based systems. Once 86-DOS was running, Paterson, in a self-hosting-inspired approach, utilized TRANS86 to convert itself into a program running under 86-DOS. Numbered version 2, this was named TRANS.COM instead. Later in 1982, the translator was apparently also available from Microsoft.

Sorcim TRANS86 Also named TRANS86, Sorcim offered an 8080 to 8086 translator as well since December 1980. Like SCP's program it was designed to port CP/M-80 application code (in ASM, MAC, RMAC or ACT80 assembly format) to MS-DOS (in a format compatible with ACT86). In ACT80 format it also supported a few Z80 mnemonics. The translation occurred on an instruction-by-instruction basis with some optimization applied to conditional jumps. The program ran under CP/M-80, MP/M-80 and Cromemco DOS with a minimum of 24 KB of RAM, and had no restrictions on the source file size.

Digital Research XLT86 Much more sophisticated and the first to introduce optimizing compiler technologies into the source translation process was Digital Research's XLT86 1.0 in September 1981. XLT86 1.1 was available by April 1982. The program was written by Gary Kildall and translated .ASM source code for the Intel 8080 processor (in a format compatible with ASM, MAC or RMAC assemblers) into .A86 source code for the 8086 (compatible with ASM86). Using global data flow analysis on 8080 register usage, the five-phase multi-pass translator would also optimize the output for code size and take care of calling conventions (CP/M-80 BDOS calls were mapped into BDOS calls for CP/M-86), 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.COM itself was written in PL/I-80 for CP/M-80 platforms. The program occupied 30 KB of RAM for itself plus additional memory for the program graph. On a 64 KB memory system, the maximum source file size supported was about 6 KB, so that larger files had to be broken down accordingly before translation. Alternatively, XLT86 was also available for DEC VAX/VMS. Although XLT86's input and output worked on source-code level, the translator's in-memory representation of the program and the applied code optimizing technologies set the foundation to binary recompilation.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Source-to-source compiler

Start with the simplest possible case. Write down what Source-to-source compiler claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Source-to-source compiler before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Source-to-source compiler ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Source-to-source compiler

In research
Source-to-source compiler appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Source-to-source compiler in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Source-to-source compiler is common in secondary-school and first-year university syllabi. It links to neighbouring topics Source-to-source compilers, Utility software types, so understanding it makes those chapters shorter.
In everyday life
Look for Source-to-source compiler outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Source-to-source compiler” →

How to study Source-to-source compiler in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Source-to-source compiler means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Source-to-source compiler out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Source-to-source compiler in simple terms?

A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler is a type of 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…

Why does Source-to-source compiler matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Source-to-source compiler?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Source-to-source compiler.

Tags

  • Source-to-source compilers
  • Utility software types

Keep exploring