Issues: Code Generation
Again Freestudy9 comes with new post related to the Issues: Code Generation. Additionally, we had described it as a point to point information.
Issues in the Design of Code Generator
1. An input to the Code Generator
- An input to the code generator consists of the intermediate representation of the source program.
- Moreover, There are several types of the intermediate language, such as postfix notation, quadruples, and syntax trees or DAGs.
- So, The detection of semantic error should be done before submitting the input to the code submitting generator.
- The code generation phase require complete error-free intermediate code as an input.requires
2. Target program
- The output of the code generator is the target program. The output may take on a variety of forms; absolute machine language, relocatable machine language, or assembly language, language.
- Producing an absolute machine language program as output has the advantage that it can be placed in a location in memory and immediately executed.
- Producing a relocatable machine language program as output is that the subroutine can be compiled separately. A set of relocatable object modules can link together and loaded for execution by a linking loader.
- Similarly, Producing an assembly language program as output makes the process of code generation somewhat easier. We can generate symbolic instructions and use the macro what facilities of the assembler to help generate core.
3. Memory management
- Mapping names in the source program to addresses of data objects in run-time memory are done cooperatively by the front end and the code generator.
- So that We assume that a name in a three-address statement refers to a symbol table entry for three-address the name.
- From the symbol table information, a relative address can determine for the name bol
in a data area.
4. Instruction selection
- If we do not care about the efficiency of the target program, instruction selection is straightforward. It requires special handling. So that, For example, the sequence of statement example,
a := b + c
d := a + e
would be translated into
MOV b, R0
ADD c, R0
MOV R0, a
MOV a, R0
ADD e, R0
MOV R0, d
- So, Here the fourth statement is redundant, so we can eliminate that statement.
5. Register allocation Issues: Code Generation
- If the instruction contains register operands then such a use becomes shorter and faster than that of using in memory.
- Moreover, The use of registers often subdivided into two subproblems:
- During register allocation, we select the set of variables that will reside in registers at a point in the program.
- During a subsequent register assignment phase, we pick the specific register that a variable will reside in.
- Finding an optimal assignment of registers to variables is difficult, even with single register value.
- Mathematically the problem is NP-complete.
6. Choice of evaluation Issues: Code Generation
- The order in which computations performed can affect the efficiency of the target code. Some computation orders require fewer registers to hold intermediate results than others. Picking the best order is another difficult, NP-complete problem, and NP-complete
7. Approaches to code generation Issues: Code Generation
- Similarly, The most important criterion for a code generator is that it produces correct code.
- Correctness takes on special significance because of the number of special cases that code generator must face.
- Given the premium on correctness, designing a code generator so it can easily implement, tested, and maintained is an important design goal.