





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of intermediate representation (ir) in compiler design, its importance, and the process of translating high-level ir to low-level ir. Various ir representations, such as three-address code and stack machine, and provides examples of translating expressions, array accesses, structure accesses, and control structures. It also touches upon the translation of nested expressions and statements.
Typology: Papers
1 / 29
This page cannot be seen from the preview
Don't miss anything!






















Lexical Analysis^ Syntax Analysis Semantic Analysis Intermediate Code Gen
Source code(character stream)
token stream abstract syntax
tree
abstract syntax^ tree + symbol
tables, types
Intermediate code
regular expressions grammars static semantics
» High-level IR (HIR): Language independent but closer
to the language » Low-level IR (LIR): Machine independent but closer
to the machine » A significant part of the compiler is both language and
machine independent!
Pentium Java bytecode Itanium TI C5x ARM
optimize
optimize
optimize
Fortran
y^
a = b OP c y^
Advantage: Makes compiler analysis/opti easier
y^
Was popular for CISC architectures y^
Advantage: Easier to generate machine code
y^
Like Java bytecode y^
Advantage: Easier to generate from AST
Assignment instructions^ »
a = b OP C (binary op)^ y
arithmetic: ADD, SUB,MUL, DIV, MOD y logic: AND, OR, XOR y comparisons: EQ, NEQ,LT, GT, LEQ, GEQ
»^
a = OP b (unary op)^ y
arithmetic MINUS,logical NEG
»^
a = b : copy instruction »^
a = [b] : load instruction »^
[a] = b : store instruction »^
a = addr b: symbolicaddress
Flow of control^ »
label L: label instruction »^
jump L: unconditional jump »^
cjump a L : conditional jump
Function call^ »
call f(a1, ..., an) »^
a = call f(a1, ..., an)
IR describes the instructionset of an abstract machine
» [[e]] = the low IR representation of high IR construct e
» Denoted as: t = [[e]] » Low IR representation of e whose result value is
stored in t
» t = v
t1 = addr v t2 = [[e]] t3 = t2 * S t4 = t1 + t3 t = [t4]
/* ie load */
array v
e
t1 = addr v t2 = t1 + S t = [t2]
/* ie load */
struct v
f
Semantics:
then evaluate e
[[ s1 ]] [[ s2 ]] ... [[ sN ]]
seq
s
s
sN