From 52c17530f2e2dbc61a3bf1d4950c8b9eaeab86de Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 27 Apr 2024 13:49:52 -0700 Subject: qbe: Temporarily set func->end = func->start in funcalloc This way way can just use funcinst. --- qbe.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/qbe.c b/qbe.c index 5c76bb2..adbc6f7 100644 --- a/qbe.c +++ b/qbe.c @@ -266,12 +266,15 @@ static void funcalloc(struct func *f, struct decl *d) { enum instkind op; - struct inst *inst; + struct block *end; + struct value *v; unsigned long long size; int align; assert(!d->type->incomplete); assert(d->type->size > 0); + end = f->end; + f->end = f->start; size = d->type->size; align = d->u.obj.align; switch (align) { @@ -282,16 +285,14 @@ funcalloc(struct func *f, struct decl *d) default: size += align - 16; /* fallthrough */ case 16: op = IALLOC16; break; } - inst = mkinst(f, op, ptrclass, mkintconst(size), NULL); - arrayaddptr(&f->start->insts, inst); + v = funcinst(f, op, ptrclass, mkintconst(size), NULL); if (align > 16) { /* TODO: implement alloc32 in QBE and use that instead */ - inst = mkinst(f, IADD, ptrclass, &inst->res, mkintconst(align - 16)); - arrayaddptr(&f->start->insts, inst); - inst = mkinst(f, IAND, ptrclass, &inst->res, mkintconst(-align)); - arrayaddptr(&f->start->insts, inst); + v = funcinst(f, IADD, ptrclass, v, mkintconst(align - 16)); + v = funcinst(f, IAND, ptrclass, v, mkintconst(-align)); } - d->value = &inst->res; + d->value = v; + f->end = end; } static struct value * -- cgit v1.2.3