diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-11-19 20:25:45 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-11-19 20:25:45 +0200 |
| commit | c85e4b4d2411e60af7387dec663ea62b03743eab (patch) | |
| tree | ae9d6a4f0caf4a24b8636050505490d03aa50047 /src/ops.c | |
| parent | 17a27d445295bbaf7c7c470b1e4648635af2f0a3 (diff) | |
| download | ek-c85e4b4d2411e60af7387dec663ea62b03743eab.tar.gz ek-c85e4b4d2411e60af7387dec663ea62b03743eab.zip | |
add implicit ret to void functions
Diffstat (limited to 'src/ops.c')
| -rw-r--r-- | src/ops.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -252,6 +252,21 @@ static int lower_id(struct ast_node *n, struct ops *ops) return 0; } +static int lower_ret(struct ast_node *n, struct ops *ops) +{ + if (AST_RETURN(n).expr) { + int ret = lower_op(AST_RETURN(n).expr, ops); + if (ret) + return ret; + } + + struct op *op = append_op(ops, OP_RET); + if (AST_RETURN(n).expr) + set_reg(&op->inputs, HEAD_OUTPUTS(ops).reg); + + return 0; +} + static int lower_op(struct ast_node *n, struct ops *ops) { int ret = 0; @@ -264,6 +279,7 @@ static int lower_op(struct ast_node *n, struct ops *ops) case AST_ASSIGN: ret = lower_assign(n, ops); break; case AST_UNOP: ret = lower_unop(n, ops); break; case AST_ID: ret = lower_id(n, ops); break; + case AST_RETURN: ret = lower_ret(n, ops); break; default: semantic_error(n->scope->fctx, n, "unimplemented lowering"); return -1; @@ -316,6 +332,7 @@ static void print_op(struct op *op) case OP_LDT: printf("ldt"); break; case OP_STW: printf("stw"); break; case OP_LDW: printf("ldw"); break; + case OP_RET: printf("ret"); break; case OP_MV: printf("mv"); break; default: printf("unimp"); break; } |
