Three address code
From Wikipedia, the free encyclopedia
In computer science, three address code (TAC) is a form of representing intermediate code used by compilers to aid in the implementation of code-improving transformations. Each TAC can be described as a quadruple (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, i.e.,
The term three address code is still used even if some instructions use more or less 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. The three address code table:
Assignment Statement | x := y op z | x, y, z are names, constants, or compiler generated temporaries; op is any binary operator |
x := op y | op is a unary operator | |
Indexed Assignment | x := y[i]
x[i] := y |
x, y, i are data objects |
Copy Statement | x := y | x, y are data objects |
Unconditional jump | goto L | L is the label of the next statement to be executed |
Conditional jump | if x relop y goto L | x, y are data objects
relop is a binary operator that compares x to y and indicates true/false L is the label of the next statement to be executed if relop indicates true |
Procedure calls and returns | param x | x is a parameter |
call p, n | p is the procedure, n is the number of parameters | |
return y | y is an optional return value | |
Address and pointer assignments |
x := &y x := *y *x := y |
x is set to the location of y
x is set to the value at the location y the value pointed to by x is set to the r-value of y |