nooc

nooc programming language compiler
git clone git://git.nihaljere.xyz/nooc
Log | Files | Refs | LICENSE

commit f1d18ddf65c8f1530e67d88b9c2e1736bd6f713e
parent 78c66786fbc61bd189601b144ebacf2c7fbb2760
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Thu, 13 Jan 2022 17:33:39 -0600

replace IR_SIZE with size field, and add flags field to struct temp

This will simplify determining the size and type of a temp.

Diffstat:
Mir.c | 23+++++++++++------------
Mir.h | 6+++++-
Mutil.c | 3---
Mx64.c | 26++++++--------------------
4 files changed, 22 insertions(+), 36 deletions(-)

diff --git a/ir.c b/ir.c @@ -83,7 +83,6 @@ bumpinterval(struct iproc *out, struct instr *instr, size_t index) { case IR_LABEL: case IR_CONDJUMP: case IR_JUMP: - case IR_SIZE: case IR_ALLOC: break; case IR_STORE: @@ -106,7 +105,7 @@ assign(struct iproc *out, uint8_t size) { size_t t = NEWTMP; STARTINS(IR_ASSIGN, t); - PUTINS(IR_SIZE, size); + out->temps.data[t].size = size; return t; } @@ -115,7 +114,7 @@ immediate(struct iproc *out, uint8_t size, uint64_t val) { size_t t = NEWTMP; STARTINS(IR_ASSIGN, t); - PUTINS(IR_SIZE, size); + out->temps.data[t].size = size; PUTINS(IR_IMM, val); return t; } @@ -125,7 +124,7 @@ load(struct iproc *out, uint8_t size, uint64_t index) { size_t t = NEWTMP; STARTINS(IR_ASSIGN, t); - PUTINS(IR_SIZE, size); + out->temps.data[t].size = size; PUTINS(IR_LOAD, index); return t; } @@ -135,19 +134,17 @@ alloc(struct iproc *out, uint8_t size, uint64_t count) { size_t t = NEWTMP; STARTINS(IR_ASSIGN, t); - PUTINS(IR_SIZE, size); + out->temps.data[t].size = size; + out->temps.data[t].flags = TF_PTR; PUTINS(IR_ALLOC, count); return t; } -static size_t +static void store(struct iproc *out, uint8_t size, uint64_t src, uint64_t dest) { - size_t t = NEWTMP; - PUTINS(IR_SIZE, size); - PUTINS(IR_STORE, src); + STARTINS(IR_STORE, src); PUTINS(IR_EXTRA, dest); - return t; } static uint64_t @@ -393,7 +390,8 @@ genproc(struct decl *decl, struct proc *proc) size_t what = NEWTMP; decl->index = what; STARTINS(IR_ASSIGN, what); - PUTINS(IR_SIZE, type->size); + iproc.temps.data[what].flags = TF_INT; // FIXME: move this to a separate function? + iproc.temps.data[what].size = type->size; // FIXME: should we check that it's a power of 2? PUTINS(IR_IN, i); } @@ -403,7 +401,8 @@ genproc(struct decl *decl, struct proc *proc) size_t what = NEWTMP; decl->index = what; STARTINS(IR_ASSIGN, what); - PUTINS(IR_SIZE, 8); + iproc.temps.data[what].flags = TF_PTR; // FIXME: move this to a separate function? + iproc.temps.data[what].size = type->size; // FIXME: should we check that it's a power of 2? PUTINS(IR_IN, i); } diff --git a/ir.h b/ir.h @@ -24,7 +24,6 @@ struct instr { IR_ASSIGN, IR_CALLARG, IR_IN, - IR_SIZE, IR_EXTRA, } op; }; @@ -32,6 +31,11 @@ struct instr { struct temp { uint64_t start; uint64_t end; + enum { + TF_PTR, + TF_INT, + } flags; + uint8_t size; uint8_t reg; }; diff --git a/util.c b/util.c @@ -141,9 +141,6 @@ dumpir(struct iproc *instrs) case IR_IN: fprintf(stderr, "in %lu\n", instr->val); break; - case IR_SIZE: - fprintf(stderr, "s%lu ", instr->val); - break; case IR_IMM: fprintf(stderr, "imm %lu\n", instr->val); break; diff --git a/x64.c b/x64.c @@ -692,31 +692,18 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins total += ret(text); NEXT; break; - case IR_SIZE: - size = ins->val; + case IR_STORE: + src = proc->temps.data[ins->val].reg; + NEXT; + assert(ins->op == IR_EXTRA); + total += mov_mr64_r64(text, proc->temps.data[ins->val].reg, src); NEXT; - - switch (ins->op) { - case IR_STORE: - src = proc->temps.data[ins->val].reg; - NEXT; - assert(ins->op == IR_EXTRA); - total += mov_mr64_r64(text, proc->temps.data[ins->val].reg, src); - NEXT; - break; - default: - die("x64 emitblock: unhandled size instruction"); - } break; case IR_ASSIGN: tmp = ins->val; dest = proc->temps.data[ins->val].reg; NEXT; - assert(ins->op == IR_SIZE); - size = ins->val; - NEXT; - switch (ins->op) { case IR_CEQ: total += mov_r64_r64(text, dest, proc->temps.data[ins->val].reg); @@ -773,7 +760,7 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins } NEXT; - while (ins->op == IR_CALLARG) { + while (ins < end && ins->op == IR_CALLARG) { count++; total += push_r64(text, proc->temps.data[ins->val].reg); NEXT; @@ -796,7 +783,6 @@ emitblock(struct data *text, struct iproc *proc, struct instr *start, struct ins NEXT; break; - case IR_STORE: case IR_IMM: case IR_ALLOC: die("x64 emitblock: invalid start of instruction");