Three-address code
Appearance
In computer science, three-address code (often abbreviated to TAC or 3AC) is an intermediate code used by compilers to aid in the implementation of code-improving transformations. Each instruction in three-address code can be described as a 4-tuple: (operator, operand1, operand2, result). The name derives from the fact that three variables are referenced by each statement.
Syntax
Each statement has the general form of:
T
A refinement of three-address code is static single assignment form (SSA).
Examples
int main(void)
{
int i;
int b[10];
for (i = 0; i < 10; ++i) {
b[i] = i*i;
}
}
The preceding C program, translated into three-address code, might look something like the following:
i := 0 ; assignment
L1: if i >= 10 goto L2 ; conditional jump
t0 := i*i
t1 := &b ; address-of operation
t2 := t1 + i ; t2 holds the address of b[i]
*t2 := t0 ; store through pointer
i := i + 1
goto L1
L2:
Another example:
if(a<b)
{
x=x+1;
}
else if(c<d)
{
y=y+1
}
1..if(a<b) then goto 4 2..if(c<d) then goto 7 3..go to next 4..t1=x+1 5..x=t1 6..go to next 7..t2=y+1 8..y=t2 9..go to next