Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.

Similar presentations


Presentation on theme: "The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders."— Presentation transcript:

1 The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders

2 Learning Objectives Explain the code generation phase. Explain the purpose of linkers and loaders.

3 Translation Process

4 Code Generation The address of each variable is now calculated and stored in the symbol table as each is encountered. Intermediate code is produced which, after optimisation (see next slide), is turned into executable code / machine code All errors due to incorrect use of the language have been removed by this stage. All errors due to incorrect use of the language have been removed by this stage.

5 Optimisation Reduce the size of the object code (so it will take up less memory) by removing any duplicate or redundant instructions which improve speed of execution. One practical example of code which would benefit from optimising would be when inputting a list of numbers to find their total as there would be no need to store the numbers first. For further explanations and examples of “duplicate” or “redundant” instructions: For further explanations and examples of “duplicate” or “redundant” instructions: http://en.wikipedia.org/wiki/Peephole_optimization

6 Loaders Copy object code into (primary) memory ready for execution at run time. The loader decides where in memory to place the code and then adjusts memory addresses as described in Memory Management. Memory ManagementMemory Management However, this applies to “whole” programs which have all the procedures and code they use within them. Therefore “absolute” addresses are known and are adjusted by loader into “relative” addresses at run time. Therefore “absolute” addresses are known and are adjusted by loader into “relative” addresses at run time.

7 Library Routines Already compiled procedures / modules which are intentionally external to the main compiled program so that: 1. They are available for other programs to use. 2. If they are changed then these changes affect all programs which use them without the need to change each program which uses them.

8 Linkers As library routines are external and are already compiled when a program which requires them is compiled then the addresses of these routines are completely unknown to the program. Only their names / identifiers are known. Only their names / identifiers are known. Linkers calculate the addresses of any external references in a compiled program to library routines, after the main program and the library routines have been loaded (by a loader) into main memory. This enables the main program together with the library routines it uses (modules) to be executed and interact with one another. This enables the main program together with the library routines it uses (modules) to be executed and interact with one another.

9 Linking Loaders Load and link.

10 The variable identifier. The kind of variable. E.g. Simple variable, structured variable such as an array, procedure, keyword etc … E.g. Simple variable, structured variable such as an array, procedure, keyword etc … Type of variable. E.g. Integer, decimal, string etc … E.g. Integer, decimal, string etc … Other Information. E.g. Bounds of array E.g. Bounds of array Run-time address of the variable or its value if it is a constant. Symbol Table Syntax (& Semantic Analysis Lexical Analysis Code Generation

11 Plenary Explain the code generation phase.

12 Plenary The address of each variable is now calculated and stored in the symbol table as each is encountered. Intermediate code is produced which, after optimisation (see next slide), is turned into executable code / machine code All errors due to incorrect use of the language have been removed by this stage. All errors due to incorrect use of the language have been removed by this stage.

13 Plenary Explain the purpose of linkers and loaders.

14 Loaders Copy object code into (primary) memory ready for execution at run time. The loader decides where in memory to place the code and then adjusts memory addresses as described in Memory Management. Memory ManagementMemory Management However, this applies to “whole” programs which have all the procedures and code they use within them. Therefore “absolute” addresses are known and are adjusted by loader into “relative” addresses at run time. Therefore “absolute” addresses are known and are adjusted by loader into “relative” addresses at run time.

15 Linkers As library routines are external and are already compiled when a program which requires them is compiled then the addresses of these routines are completely unknown to the program. Only their names / identifiers are known. Only their names / identifiers are known. Linkers calculate the addresses of any external references in a compiled program to library routines, after the main program and the library routines have been loaded (by a loader) into main memory. This enables the main program together with the library routines it uses (modules) to be executed and interact with one another. This enables the main program together with the library routines it uses (modules) to be executed and interact with one another.


Download ppt "The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders."

Similar presentations


Ads by Google