Chapter 2: Introduction to compilers

Intermediate Code Generation

. Abstraction at the source level identifiers, operators, expressions, statements, conditionals, iteration, functions (user defined, system defined or libraries)

. Abstraction at the target level memory locations, registers, stack, opcodes, addressing modes, system libraries, interface to the operating systems

. Code generation is mapping from source level abstractions to target machine abstractions

. Map identifiers to locations (memory/storage allocation)

. Explicate variable accesses (change identifier reference to relocatable/absolute address

. Map source operators to opcodes or a sequence of opcodes

. Convert conditionals and iterations to a test/jump or compare instructions

. Layout parameter passing protocols: locations for parameters, return values, layout of activations frame etc.

. Interface calls to library, runtime system, operating systems

By the very definition of an intermediate language it must be at a level of abstraction which is in the middle of the high level source language and the low level target (machine) language. Design of the intermediate language is important. The IL should satisfy 2 main properties :

. easy to produce, and

. easy to translate into target language.

Thus it must not only relate to identifiers, expressions, functions & classes but also to opcodes, registers, etc. Then it must also map one abstraction to the other.

These are some of the things to be taken care of in the intermediate code generation.