•
TAC consists of a sequence of instructions, each instruction may have up to
three addresses, prototypically t1 = t2 op t3
•
Addresses may be one of:
–
A name. Each name is a symbol table index. For convenience, we write
the
names as the identifier.
–
A constant.
–
A compiler-generated temporary. Each time a temporary address is needed, the
compiler generates another name from the stream t1, t2, t3, etc.
• Temporary names
allow for code optimization to easily move instructions
• At target-code
generation time, these names will be allocated to registers or to memory.
•
TAC Instructions
–
Symbolic labels will be used by instructions that alter the flow of control.
The
instruction addresses of labels will be filled in later.
L: t1 = t2 op t3
–
Assignment instructions: x = y op z
• Includes binary arithmetic and logical
operations
–
Unary assignments: x = op y
• Includes unary arithmetic op (-) and
logical op (!) and type
conversion
–
Copy instructions: x = y
–
Unconditional jump: goto L
• L is a symbolic label of an instruction
–
Conditional jumps:
if x goto L If x is
true, execute instruction L next
ifFalse x goto L If x
is false, execute instruction L next
–
Conditional jumps:
if x relop y goto L
–
Procedure calls. For a procedure call p(x1, …, xn)
param x1
…
param xn
call p, n
–
Function calls : y= p(x1, …, xn) y = call p,n , return y
–
Indexed copy instructions: x = y[i] and x[i] = y
•
Left: sets x to the value in the location i memory units beyond y
•
Right: sets the contents of the location i memory units beyond x to y
–
Address and pointer instructions:
•
x = &y sets the value of x to be the location (address) of y.
•
x = *y, presumably y is a pointer or temporary whose value is a
location.
The value of x is set to the contents of that location.
•
*x = y sets the value of the object pointed to by x to the value of y.
Example:
Given the statement do i = i+1; while (a[i] < v ); , the
TAC can be written as below in two ways, using either symbolic labels or
position number of instructions for labels.
0 comments