Professional Documents
Culture Documents
a) Allocation:
It allocates memory for the program in the main memory . In order to allocate
memory to the program, the loader allocates the memory on the basis of the size of
the program, this is known as allocation. The loader gives the space in memory
where the object program will be loaded for execution.
b) Linking:
c) Relocation:
It modifies the object program so that it can be loaded at an address different from
the location. There are some address-dependent locations in the program, and these
address constants must be modified to fit the available space, this can be done by
loader and this is known as relocation. In order to allow the object program to be
loaded at a different address than the one initially supplied, the loader modifies the
object program by modifying specific instructions.
d) Loading:
It brings the object program into the main memory for execution. The loader loads
the program into the main memory for execution of that program. It loads machine
instruction and data of related programs and subroutines into the main memory, this
process is known as loading. The loader performs loading; hence, the assembler
must provide the loader with the object program.
eg. Absolute Loader
3. EXPLAIN DIFFERENT TYPES OF LOADER.
In compiler design, a loader is a program that is responsible for loading executable
programs into memory for execution. The loader reads the object code of a program, which
is usually in binary form, and copies it into memory. The loader is typically part of the
operating system and is invoked by the system’s bootstrap program or by a command from
a user. Loaders can be of seven types:
1. Absolute Loader:
- An absolute loader is one of the simplest types of loaders.
- It loads a program into memory at a specific location, known as an absolute
address.
- The addresses of the program's instructions and data are fixed and specified in the
executable file.
- Absolute loaders are not very flexible and are rarely used in modern systems.
2. Relocating Loader:
- A relocating loader is more flexible than an absolute loader.
- It loads a program into memory, allowing it to be loaded at any location.
- The loader adjusts the addresses specified in the program's instructions and data to
reflect the actual location where the program is loaded.
- Relocating loaders are commonly used in modern systems to support programs
that can be loaded into different memory locations.
3. Direct Linking Loader:
- In direct linking, the linking process occurs at compile time rather than at runtime.
- The loader combines object files (compiled source code) into an executable file by
directly merging their code and data sections.
- The linking is done statically, meaning that the addresses of external symbols are
resolved at compile time.
- Direct linking results in faster loading times but lacks flexibility compared to
dynamic linking.
4. Dynamic Linking Loader:
- Dynamic linking loaders link executable files with shared libraries (DLLs in
Windows, shared objects in Unix-like systems) at runtime.
- Shared libraries contain code that multiple programs can use, reducing memory
usage and facilitating updates.
- The loader locates the required shared libraries, loads them into memory, resolves
references to symbols in these libraries, and updates the program's memory space
accordingly.
- Dynamic linking allows for more efficient memory usage and easier updates but
may incur a small performance overhead during runtime due to the dynamic linking
process.
5. Compile and Go Loader:
6. General Loader:
7. Program Linking Loader
2. Loading: When you execute the program, the dynamic loader is invoked. It
locates the required shared libraries based on the paths specified during
compilation or through environment variables. Then, it loads these libraries into
memory alongside the main program.
3. Symbol Resolution: Once the libraries are loaded, the dynamic loader resolves
the unresolved references in the main program's code by linking them to the
appropriate symbols or functions in the shared libraries. It updates the
placeholders with the correct memory addresses.
5. Execution: Finally, the program starts executing, now with all its dependencies
loaded and linked dynamically. Any calls to functions or symbols from the shared
libraries are resolved at runtime.
Let us assume an input string 4 * 5 + 6 for computing synthesized attributes. The annotated
parse tree for the input string is
2. Inherited Attributes – These are the attributes which derive their values from their
parent or sibling nodes i.e. value of inherited attributes are computed by value of parent or
sibling nodes.
Example:
A --> BCD { C.in = A.in, C.type = B.type }
Computation of Inherited Attributes –
Construct the SDD using semantic actions.
The annotated parse tree is generated and attribute values are computed in top
down manner.
Example: Consider the following grammar
S --> T L
T --> int
T --> float
T --> double
L --> L1, id
L --> id
The SDD for the above grammar can be written as follow
Let us assume an input string int a, c for computing inherited attributes. The annotated
parse tree for the input string is
A context-free grammar G = (VT, VN, S, P) whose parsing table has no multiple entries is said
to be LL(1). In the name LL(1),
the first L stands for scanning the input from left to right,
the second L stands for producing a leftmost derivation,
and the 1 stands for using one input symbol of lookahead at each step to make parsing
action decision.
E → T E’
E’ → + T E’ | λ
T → F T’
T’ → * F T’ | λ
F → (E) | id
N/I id + * ( ) $
E E→TE’ E→TE’
E’ E’→+TE’ E’→ λ E’→ λ
T T→FT’ T→FT’
T’ T’→ λ T’→*FT’ T’→ λ T’→ λ
F F→id F→(E)
is an LL(1) grammar
LL(1) grammars enjoys several nice properties: for example they are not ambiguous and
not left recursive.
1. Quadruple
2. Triples
1. Quadruple
To implement the three address codes, the quadruples have four fields. The name of the
operator, the first source operand, the second source operand, and the result are all contained
in the quadruple field.
Quadruples field
Operator
Source 1
Source 2
Destination
Example:
p := -q * r + s
t1 := -q
t2 := r + s
t3 := t1 * t2
p := t3
2. Triples
To implement the three address codes, the triples have three fields. The name of the operator,
the first source operand, and the second source operand are all contained in the field of
triples.
Triples fields
Operator
Source 1
Source 2
Example – p := -q * r + s
t1 := -q t2 := r + sM t3 := t1 * t2 p := t3
Evaluation order – The code generator decides the order in which the
instruction will be executed. The order of computations affects the efficiency
of the target code. Among many computational orders, some will require only
fewer registers to hold the intermediate results. However, picking the best
order in the general case is a difficult NP-complete problem.
Approaches to code generation issues: Code generator must always generate
the correct code. It is essential because of the number of special cases that a
code generator might face. Some of the design goals of code generator are:
1. Correct
2. Easily maintainable
3. Testable
4. Efficient