diff options
Diffstat (limited to 'src/lower.c')
-rw-r--r-- | src/lower.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lower.c b/src/lower.c index ad3d1b9..46ce2c3 100644 --- a/src/lower.c +++ b/src/lower.c @@ -44,6 +44,13 @@ static int lower_binop(struct state *state, struct ast *binop) return -1; switch (binop->k) { + case AST_ADD: printf(" + "); break; + case AST_SUB: printf(" - "); break; + case AST_MUL: printf(" * "); break; + case AST_DIV: printf(" / "); break; + case AST_REM: printf(" %% "); break; + case AST_LSHIFT: printf(" << "); break; + case AST_RSHIFT: printf(" >> "); break; default: internal_error("missing binop lowering"); return -1; @@ -63,6 +70,12 @@ static int lower_comparison(struct state *state, struct ast *comp) return -1; switch (comp->k) { + case AST_LT: printf(" < "); break; + case AST_GT: printf(" > "); break; + case AST_LE: printf(" <= "); break; + case AST_GE: printf(" <= "); break; + case AST_NE: printf(" != "); break; + case AST_EQ: printf(" == "); break; default: internal_error("missing comparison lowering"); return -1; @@ -148,8 +161,25 @@ static int lower_init(struct state *state, struct ast *init) return 0; } +static int lower_unop(struct state *state, struct ast *expr) +{ + switch (expr->k) { + case AST_LNOT: printf("-"); break; + case AST_NOT: printf("~"); break; + case AST_NEG: printf("-"); break; + default: + internal_error("missing unop lowering"); + return -1; + } + + return lower_expr(state, unop_expr(expr)); +} + static int lower_expr(struct state *state, struct ast *expr) { + if (is_unop(expr)) + return lower_unop(state, expr); + if (is_binop(expr)) return lower_binop(state, expr); |