Introduction and Issues in the Design of a Code Generator.
Size: 79.39 KB
Language: en
Added: Feb 19, 2017
Slides: 13 pages
Slide Content
Code Generation - Principles of Compiler Design Presenter: PRABU.R BP150504, II MSC CS, PG Department of Computer Science, Sacred Heart College, Tirupattur.
AGENDA Introduction Issues in the Design of a Code Generation.
Introduction It is the final phase in the compiler model. Input as a Intermediate representation of the source program and output as equivalent target program. Int. code Int. code Src Progm Front end Code Optimizer Code Generator Symbol Table Target Progm
Issues in Design of Code Gen. Input to the Code Generator Target Program Memory Management Instruction Section Register Allocation Choices of Evaluation Order Approaches to Code Generation
1. Input to the Code Generator The input to the code gen. consists of intermediate representation of the source program Which is produced by the front end, together with info in the symbol table, used to determine the run time address of objects denoted by the names in intermediate representation. Three several choices for the IL : Linear representation such as postfix notation Three-address code such as quadruples. Graphical representation such as syntax tree and dags.
2. Target Program Output of code gen is Target Program. Like Intermediate Code, this output also takes many forms: Absolute Machine Language Relocatable Machine Language Assembly Language. Producing an absolute ML has the advantage that it can be placed in a fixed location in memory and immediately executed. Compilers such as WATFIV and PL/C, produces Absolute code.
2. Cont.. On the other hand while producing relocatable ML, we gain flexibility that we can call other programs from an object module. Where as while producing assembly language program, process of code generation is easier. We can generate symbolic instructions and use the macro facilities of the assembler to help generate code.
3. Memory Management Mapping names in the source program to addresses of data objects in run time memory is done cooperatively by the front end and the code generator. We assumed names in a Three address statement refers to the names in symbol table entry for the name. If Machine code is being generated, labels in three address statement have to be converted to addresses of instruction. This process is analogous in Back patching.
4. Instruction Selection The nature of instruction set of the target ML determines the difficulty of instruction selection. X:=y+z MOV y,R0 ADD z,R0 MOV R0,x
5. Register Allocation The use of register allocation is often subdivided into two sub problems: During register allocation During a subsequent register assignment phase. Certain machines register pairs Multiplication: M x,y Division: D x,y t:=a+b t :=t*b t:= a/b
6. Choices of Evaluation Order The order in which computations are performed can affect the efficiency of the target code. Some computation orders requires fewer registers to hold intermediate results than others. Picking a best order is another difficult, NP-complete problem.
7. Approaches to Code Generation The most important criterion for a code generator is that it produce correct code. Correctness takes on significance because of the no of special cases that a code generator might face. Given the premium on correctness, designing a code gen so it can be easily implemented, tested and maintained is an important design deal.