aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qbe.c17
1 files 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 *