GENERATOR
Error detection
Speed
Memory space
Machine code
Easy to write
Better error
messages
Slower
More memory space
C, C++ etc.
Intermediate code
Easy to write
Better error messages
Slower
More memory space
Java, LISP, UNIX Shell
etc.
Front
end
Parser
Static
checker
Type checking
(compatibility of
operators and
operands)
Intermediate code
generator
Syntax checks
Intermedia
te code
Code
generator
INTERMEDIATE REPRESENTATIONS OF
COMPILER
Close to target
machine
Close to source
language
Source
program
High level
intermediate
representation
....
.
Low level
intermediate
representation
Target
code
than 1 parent
In syntax tree it would be replicated as many time s it would appear in
the expression.
Syntax tree
DAG
+
+
a
*
a
*
-
+
+
a
a
a
*
b
b
c
c b
*
d
E E1+T
E E1-T
ET
T(E)
T id
T num
=
+
i
10
id
num
10
t1=b-c
t2=a*t1
t3=a+t2
t4=t1*d
t5=t3+t4
addres
s
instructi
on
General
Implemented
using records
with fields as
addresses
ADDRESSES
Name
Constant
SYMBOL LABELS
Used to alter flow of control
Represents the index of a 3 address instruction in a sequence
of instructions.
INSTRUCTIONS
Assignment instruction
address; op is
operations)
Assignment instruction
z=x op y (z , x, y are
arithmetic or logical
(z , x, y are
address; op is unary
operation: unary
plus, minus,
negation, shift, conversion
operation)
Copy instruction
x=y
z= op y
QUADRUPLES
Has four fields : op, arg1,arg2, result
z=x + y : + is op; x, y are arg1 and arg2 respectively and z is
the result
A=B*-C + B*-C
T1= minus C
T2=B*T1
T3=B*T1
T4=T2+T3
A=T4
OP
ARG1
ARG2
RESULT
minus
T1
T2
T1
T4
T2
T3
T4
T4
T1
TRIPLES
Has only 3 fields (no result field)
Result of operation is referred by its position.
DGA representation
Benefit of quadruples over tuples
Optimizing compiler
Move an instruction that computes a temporary t, instruction that uses it
need not be changed.
SINGLE ASSIGNMENT
An intermediate representation that facilitates optimization.
All assignments in SSA are to variables with distinct names
hence name static single assignment.
TYPE EXPRESSIONS
TYPE EQUIVALENCE
If 2 type expressions are equal then return the type or error
Ambiguity arises if the expression is given a name and it is
then applied to subsequent sub expression
When
they
Are of same basic type
They are formed by applying the same constructor to the same basic
types
One is a type name and the other denotes it
TYPE CHECKING
Assigns a type expression to each component of the source program
compiler determine that these expression confine to the collection of
logical rules type system of the source program
Synthesis
Built the type of
expression from the type
of its sub expressions.
Requires name to be
declared before use
Inference
Type of the language
construct from the way it
is used.
TYPE CONVERSIONS
Explicit conversions
Implicit conversions
Casts
Coercions
Usually widening is done
Usually widening is done
CONTROL FLOW
Boolean Expression
BOOLEAN EXPRESSIONS
Comprised of Boolean operators
|| && !
FLOW-CONTROL STATEMENTS
the transalations
One pass for statements and two passes for expression