Three address code
Encyclopedia
In computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

, three-address code (often abbreviated to TAC or 3AC) is a form of representing intermediate code
Intermediate language
In computer science, an intermediate language is the language of an abstract machine designed to aid in the analysis of computer programs. The term comes from their use in compilers, where a compiler first translates the source code of a program into a form more suitable for code-improving...

 used by compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

s to aid in the implementation of code-improving transformations. Each instruction in three-address code can be described as a 4-tuple
Tuple
In mathematics and computer science, a tuple is an ordered list of elements. In set theory, an n-tuple is a sequence of n elements, where n is a positive integer. There is also one 0-tuple, an empty sequence. An n-tuple is defined inductively using the construction of an ordered pair...

: (operator, operand1, operand2, result).

Each statement has the general form of:



such as:



where x, y and z are variables, constants or temporary variables generated by the compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

. op represents any operator, e.g. an arithmetic operator.

Expressions containing more than one fundamental operation, such as:



are not representable in three-address code as a single instruction. Instead, they are decomposed into an equivalent series of instructions, such as







The term three-address code is still used even if some instructions use more or fewer than two operands. The key features of three-address code are that every instruction implements exactly one fundamental operation, and that the source and destination may refer to any available register.

A refinement of three-address code is static single assignment form
Static single assignment form
In compiler design, static single assignment form is a property of an intermediate representation , which says that each variable is assigned exactly once...

 (SSA).

Example


int main(void)
{
int i;
int b[10];
for (i = 0; i < 10; ++i) {
b[i] = i*i;
}
}

The preceding C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

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 {
x=x+1;

}
else
if(c {
y=y+1
}


1..if(a 2..if(c 3..go to next
4..t1=x+1
5..x=t1
6..go to 2
7..t2=y+1
8..t2=y
9..go to next

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK