/ * simplify_expr: Generate code to simplify the given expression * until it is an id or a constant. * If the expression is complicated, this involves * evaluating it into a temporary variable, and then changing the * expression to just evaluate to the temporary variable. * Returns highest # local variable used in code for expression. */
| 504 | * Returns highest # local variable used in code for expression. |
| 505 | */ |
| 506 | int simplify_expr(expr_type expr, int maxlocal) |
| 507 | { |
| 508 | int our_maxlocal = maxlocal; |
| 509 | id_type id; |
| 510 | |
| 511 | if (is_base_level(expr)) |
| 512 | return our_maxlocal; |
| 513 | |
| 514 | id = make_temp_var(maxlocal + 1); /* Temporary to store expression */ |
| 515 | |
| 516 | our_maxlocal = flatten_expr(expr, id, maxlocal); |
| 517 | |
| 518 | /* Count temp var, if rhs didn't use any new temps */ |
| 519 | if (our_maxlocal == maxlocal) |
| 520 | our_maxlocal++; |
| 521 | |
| 522 | /* Modify expression to make it just a local variable */ |
| 523 | expr->value.idval = id; |
| 524 | expr->type = E_IDENTIFIER; |
| 525 | |
| 526 | return our_maxlocal; |
| 527 | } |
no test coverage detected