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/asm.c | |
| parent | 17a27d445295bbaf7c7c470b1e4648635af2f0a3 (diff) | |
| download | ek-c85e4b4d2411e60af7387dec663ea62b03743eab.tar.gz ek-c85e4b4d2411e60af7387dec663ea62b03743eab.zip | |
add implicit ret to void functions
Diffstat (limited to 'src/asm.c')
| -rw-r--r-- | src/asm.c | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -57,6 +57,17 @@ static int print_stt(struct op *op, FILE *f) return 0; } +static int print_ret(struct op *op, FILE *f) +{ + /* technically speaking ret takes a number of inputs, but they should be + * marshaled into registers with moves etc. so don't worry about them + * here */ + fprintf(f, "jalr x0, 0(x21)\n"); + /* eventually add in proper ret alias to assembly language once I go + * through calling conventions etc. */ + return 0; +} + static int print_op(struct op *op, FILE *f) { int ret = 0; @@ -66,6 +77,7 @@ static int print_op(struct op *op, FILE *f) case OP_LI: ret = print_li(op, f); break; case OP_MV: ret = print_mv(op, f); break; case OP_STT: ret = print_stt(op, f); break; + case OP_RET: ret = print_ret(op, f); break; default: abort(); } @@ -77,7 +89,11 @@ int print_asm(struct ops *ops, const char *output) FILE *f = fopen(output, "w"); /* main should probably be mangled here as well */ - fprintf(f, "jal x0, main\n"); + fprintf(f, "jal x21, main\n"); + /* tell simulator to turn off (very much temp) */ + fprintf(f, "li x1, 3\n"); + fprintf(f, "csrrw mpower, x0, x1\n"); + int ret = 0; struct op *op = ops->base; while (op) { @@ -87,10 +103,6 @@ int print_asm(struct ops *ops, const char *output) op = op->next; } - /* tell simulator to turn off (very much temp) */ - fprintf(f, "li x1, 3\n"); - fprintf(f, "csrrw mpower, x0, x1\n"); - fclose(f); return ret; } |
