MCPcopy Create free account
hub / github.com/Meridian59/Meridian59 / simplify_expr

Function simplify_expr

blakcomp/codeutil.c:506–527  ·  view source on GitHub ↗

/ * 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. */

Source from the content-addressed store, hash-verified

504 * Returns highest # local variable used in code for expression.
505 */
506int 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}

Callers 4

codegen_callFunction · 0.85
codegen_returnFunction · 0.85
codegen_ifFunction · 0.85
codegen_whileFunction · 0.85

Calls 3

is_base_levelFunction · 0.85
make_temp_varFunction · 0.85
flatten_exprFunction · 0.85

Tested by

no test coverage detected