diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-15 01:35:19 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-15 02:01:21 +0300 |
| commit | 5a728ae106b978c6de0fa6316f37eb3b4a86a405 (patch) | |
| tree | 20c5e1f08aa4c6c84f22d6b31d0965c36a38ab94 /src/asm.c | |
| parent | 8ce25e04620d4173748a7d7dd310351bac90eacc (diff) | |
| download | qbt-5a728ae106b978c6de0fa6316f37eb3b4a86a405.tar.gz qbt-5a728ae106b978c6de0fa6316f37eb3b4a86a405.zip | |
format
Diffstat (limited to 'src/asm.c')
| -rw-r--r-- | src/asm.c | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -248,11 +248,9 @@ static void output_restore(struct insn n, FILE *o, struct fn *f) static void output_store(struct insn n, FILE *o) { - struct val offset = n.out; struct val b = n.in[0]; struct val t = n.in[1]; - assert(offset.class == IMM); assert(b.class == REG); assert(t.class == REG); @@ -260,7 +258,7 @@ static void output_store(struct insn n, FILE *o) if (n.vtype == I9) width = 't'; - int64_t off = offset.v; + int64_t off = n.v; fprintf(o, "st %c %s, %lli(%s)\n", width, rname(t), (long long int)off, rname(b)); } @@ -269,9 +267,7 @@ static void output_load(struct insn n, FILE *o) { struct val t = n.out; struct val b = n.in[0]; - struct val offset = n.in[1]; - assert(offset.class == IMM); assert(b.class == REG); assert(t.class == REG); @@ -279,7 +275,7 @@ static void output_load(struct insn n, FILE *o) if (n.vtype == I9) width = 't'; - int64_t off = offset.v; + int64_t off = n.v; fprintf(o, "ld %c %s, %lli(%s)\n", width, rname(t), (long long int)off, rname(b)); } @@ -295,6 +291,21 @@ static void output_lt(struct insn i, FILE *o) rname(i.out), rname(i.in[0]), rname(i.in[1])); } +static void output_alloc(struct insn i, FILE *o) +{ + assert(i.type == ALLOC); + /** @todo alignment is ignored, is that our responsibility? */ + fprintf(o, "addi sp, sp, -%lli\n", i.v); + fprintf(o, "mov %s, sp\n", rname(i.out)); +} + +static void output_dealloc(struct insn i, FILE *o) +{ + assert(i.type == DEALLOC); + /** @todo alignment is ignored */ + fprintf(o, "addi sp, sp, %lli\n", i.v); +} + static void output_insn(struct insn n, FILE *o, struct fn *f) { /* one insn directly matches one or more assembly instructions, @@ -309,6 +320,8 @@ static void output_insn(struct insn n, FILE *o, struct fn *f) case CALL: output_call(n, o); break; case STORE: output_store(n, o); break; case LOAD: output_load(n, o); break; + case ALLOC: output_alloc(n, o); break; + case DEALLOC: output_dealloc(n, o); break; case SAVE: output_save(n, o, f); break; case RESTORE: output_restore(n, o, f); break; default: fprintf(stderr, "unimplemented insn: %s\n", op_str(n.type)); |
