Search code examples
compiler-construction

Is this diagram of a compiler inaccurate?


I am reading my textbook and I see this diagram for a compiler:

enter image description here

Is this inaccurate? Where is the assembly code produced? It says the output of a compiler is machine code but I thought the output of a compiler is assembly code?


Solution

  • Not at all - compiler is a very vague term (see this answer for the etymology). As mentioned by user207421, there are compilers that produce object code, interpretable byte-code and assembly.

    However, there are compilers that also produce other high-level languages i.e. they effectively convert code from one high-level langauge to another (see transcompilers). There are also compilers that convert code from low-level languages (once again, it can be object code, byte-code or assembly) to high-level languages (see decompilers). Then there are compilers which generate code to run on other CPU architectures than the one on which they are running (see cross-compiler). Furthermore, there are also compilers that produce other compilers (the so called compiler-compilers) - these take some form of description of a language and produce a compiler for that language.

    This page is a good place to start if you'd like to learn more.