2. A compiler is a computer program (or set of
programs) that transforms source code written
in a programming language (the source
language) into another computer language
(the target language, often having a binary
form known as object code).
4. The term decompiler is most commonly applied
to a program which translates executable
programs (the output from a compiler) into
source code in a (relatively) high level
language which, when compiled, will produce
an executable whose behavior is the same as
the original executable program
5.
6. 1. Lexical analysis: in a compiler linear
analysis is called lexical analysis or scanning
2. Preprocessor: in addition to a compiler
several other programs may be required to
create and executable target program. A
source program may be divided into
modules stored in spa rate files. The task of
collection the source program is sometimes
entrusted to distinct program called a
preprocessing.
7. 3. Parsing: hierarchical analysis is called parsing or
syntax analysis.
4. Semantic analysis: is the phase in which the
compiler adds semantic information to the parse
tree and builds the symbol table. This phase
performs semantic checks such as type checking
(checking for type errors), or object binding
(associating variable and function references with
their definitions), or definite assignment (requiring
all local variables to be initialized before use),
rejecting incorrect programs or issuing warnings.
8. 5. Code generation: the final phase of the
compiler is the generation of target code
consisting normally of relocatable machine
code or assembly code.
6. Code optimization: the code optimization
phase attempts to improve the
intermediate code, so that faster-running
machine code will result.
9. Compilers bridge source programs in high-level
languages with the underlying hardware.
A compiler requires :
1) Determining the correctness of the syntax of
programs.
2) Generating correct and efficient object code.
3) Run-time organization.
4) Formatting output according to assembler and/or
linker conventions.
11. 1. The front end:
checks whether the program is correctly written
in terms of the programming language syntax and
semantics. Here legal and illegal programs are
recognized. Errors are reported, if any, in a useful
way. Type checking is also performed by collecting
type information. The frontend then generates an
intermediate representation or IR of the source
code for processing by the middle-end.
12. 2. The middle end:
Is where optimization takes place. Typical
transformations for optimization are removal of
useless or unreachable code, discovery and
propagation of constant values, relocation of
computation to a less frequently executed place
(e.g., out of a loop), or specialization of
computation based on the context. The middle-end
generates another IR for the following
backend. Most optimization efforts are focused on
this part.
13. 3. The back end:
Is responsible for translating the IR from the middle-end
into assembly code. The target instruction(s) are
chosen for each IR instruction. Register allocation
assigns processor registers for the program variables
where possible. The backend utilizes the hardware by
figuring out how to keep parallel execution units busy,
filling delay slots, and so on.
14. One classification of compilers is by the platform
on which their generated code executes. This is
known as the target platform.
The output of a compiler that produces code for a
virtual machine (VM) may or may not be executed
on the same platform as the compiler that
produced it. For this reason such compilers are not
usually classified as native or cross compilers.
15. EQN, a preprocessor for typesetting
mathematics
Compilers for Pascal
The C compilers
The Fortran H compilers.
The Bliss/11 compiler.
Modula – 2 optimization compiler.
17. A single pass compiler makes a single pass over
the source text, parsing, analyzing, and
generating code all at once.
18. let var n:
integer;
var c: char
in begin
c := ‘&’;
n := n+1
end
PUSH 2
LOADL 38
STORE 1[SB]
LOAD 0[SB]
LOADL 1
CALL add
STORE 0[SB]
POP 2
Ident HALT
N
c
Type
Int
char
Address
0[SB]
1[SB]
19. A multi pass compiler makes several passes
over the program. The output of a preceding
phase is stored in a data structure and used by
subsequent phases.
20.
21. Automatic parallelization:
The last one of which implies automation when
used in context, refers to converting sequential
code into multi-threaded or vectorized (or even
both) code in order to utilize multiple
processors simultaneously in a shared-memory
multiprocessor (SMP) machine.
22. The compiler usually conducts two passes of analysis
before actual parallelization in order to determine the
following:
Is it safe to parallelize the loop? Answering this
question needs accurate dependence analysis and
alias analysis
Is it worthwhile to parallelize it? This answer
requires a reliable estimation (modeling) of the
program workload and the capacity of the parallel
system.
23. The Fortran code below can be auto-parallelized by a
compiler because each iteration is independent of the
others, and the final result of array z will be correct
regardless of the execution order of the other
iterations.
do i=n ,1
z(i) = x(i) + y(i(
enddo
24. On the other hand, the following code cannot be
auto-parallelized, because the value of z(i) depends
on the result of the previous iteration, z(i-1).
do i=2, n
z(i) = z(i-1)*2
enddo
25. This does not mean that the code cannot be
parallelized. Indeed, it is equivalent to
do i=2, n
z(i) = z(1)*2**(i-1)
enddo
26. Automatic parallelization by compilers or tools is very
difficult due to the following reasons:
Dependence analysis is hard for code using indirect
addressing, pointers, recursion, and indirect
function calls.
loops have an unknown number of iterations.
Accesses to global resources are difficult to
coordinate in terms of memory allocation, I/O, and
shared variables.
27. Due to the inherent difficulties in full automatic
parallelization, several easier approaches exist to get
a parallel program in higher quality. They are:
Allow programmers to add "hints" to their
programs to guide compiler parallelization.
Build an interactive system between programmers
and parallelizing tools/compilers.
Hardware-supported speculative multithreading.