Skip to main content
Engineering LibreTexts

1.6: Intermediate steps

  • Page ID
    29010
  • Intermediate Code Generator

    Most compilers translate a source program into an independent intermediate code, then the back end of the compiler uses this intermediate code to generate the target code specifically for the machine architecture and operating system that the code is being written for.

    The benefits of using machine independent intermediate code are:

    • Because of the machine independent intermediate code, portability will be enhanced.For ex, suppose, if a compiler translates the source language to its target machine language without having the option for generating intermediate code, then for each new machine, a full native compiler is required. Because, obviously, there were some modifications in the compiler itself according to the machine specifications.
    • It is easier to apply source code modification to improve the performance of source code by optimising the intermediate code.

    In a compiler that uses an intermediate language, there may be two instruction selection stages—one to convert the parse tree (that information that comes from the previous stages of the compiling process) into intermediate code, and a second phase much later to convert the intermediate code into instructions from the instruction set of the target machine. 

    Adapted from: "Intermediate Code Generation in Compiler Design" by Aaqib Bashir is licensed under CC BY-SA 4.0