Compiler Design (MCA554) – Unit 5: Code Generation and Code Optimization
Based on MCA Semester III Syllabus --- Introduction to Code Generation Code Generation is the final phase of a compiler. Its purpose is to convert intermediate code into target machine code. Compiler Flow: Source Program ↓ Lexical Analysis ↓ Syntax Analysis ↓ Semantic Analysis ↓ Intermediate Code ↓ Code Generation ↓ Machine Code --- Objectives of Code Generation A good code generator should: Produce correct code Produce efficient code Use memory efficiently Reduce execution time --- Inputs to Code Generator The code generator receives: Intermediate Code Symbol Table Runtime Information Example: t1 = a + b t2 = t1 * c --- Outputs of Code Generator The output is machine code or assembly code. Example: MOV R1, a ADD R1, b MUL R1, c --- Machine Dependent Code Generation Machine-dependent code generation considers: CPU architecture Number of registers Mem...