| Operand Descriptors (cont.) |
x+1 we would like to produce the code:
| move | x,D1 |
| add | #1,D1 |
operand_desc *expr_gen(node * expr)
{ operand_desc *left_loc, *right_loc, *new_loc;
switch (expr->internal.type) {
. . .
case Nplus:
left_loc = expr_gen(expr->internal.child[0]);
right_loc = expr_gen(expr->internal.child[1]);
if is_temporary(left_loc) {
output ``add right_loc,left_loc'';
freeOp(right_loc);
return left_loc;
} else if is_temporary(right_loc) {
output ``add left_loc,right_loc'';
freeOp(left_loc)
return right_loc;
} else {
new_loc = get_temporary();
output ``move left_loc,new_loc'';
output ``add right_loc,new_loc'';
freeOp(left_loc);
freeOp(right_loc);
return new_loc;
}
break;
.
.
.
As a result, the low-level code generator's interface must provide the means to determine various properties of the locations described by operand descriptors:
| Operand Descriptors (cont.) |