- Three address code
In
computer science , three-address code (often abbreviated to TAC or 3AC) is a form of representing intermediate code used bycompiler s 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).Each statement has the general form of:
where "x", "y" and "z" are variables, constants or temporary variables generated by the
compiler . "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 (SSA).Example
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 goto L3 ; unconditional jump L2: 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 L3:
ee also
*
Intermediate language
*Reduced instruction set computer External links
* [http://cs.wwc.edu/~aabyan/464/Quads.html Three-Address Code and Register Allocation]
* [http://www.cs.arizona.edu/classes/cs453/fall07/DOCS/intcode.html CSc 453: A Three-Address Intermediate Code Instruction Set for C--]
Wikimedia Foundation. 2010.