What is intermediate and target code generation in a compiler?
What is intermediate and target code generation in a compiler?
32807-Apr-2023
Updated on 08-Apr-2023
Home / DeveloperSection / Forums / What is intermediate and target code generation in a compiler?
What is intermediate and target code generation in a compiler?
Krishnapriya Rajeev
07-Apr-2023Intermediate Code Generation: In the process of translating source code into machine code, a compiler may construct one or more intermediate representations, which can have different forms, including trees, graphs, or quadruples. This intermediate code is simple and easy to translate into the target machine. The objective of the intermediate code is to make the translation process easier and more efficient.
Code Generation: After the intermediate code has been generated, the machine-independent code optimization phase attempts to improve the intermediate code so that better target code can be generated. The optimization can have different objectives, including faster execution, shorter code, or code that consumes less power.
Finally, the code generator takes the intermediate representation of the source program and maps it into the target language. The intermediate instructions are translated into sequences of machine instructions that perform the same task as the original program. The output of the code generator is the target code that can be executed on the target machine.