commit 48e097d6e3695483c839b9d7b94b2f7373616ac5
parent ddd6b146ba5135d00b0fc5ca16ba5ec807d246f7
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 20 Dec 2020 15:39:12 -0500
gen: re-order pushi/geni arguments
Using out, instr, args... better matches qbe, e.g.
%temp.0 =l loadl %arg.0
Diffstat:
3 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/include/qbe.h b/include/qbe.h
@@ -193,9 +193,9 @@ struct qbe_program {
void qbe_append_def(struct qbe_program *prog, struct qbe_def *def);
-void geni(struct qbe_statement *stmt, enum qbe_instr instr, const struct qbe_value *out, ...);
+void geni(struct qbe_statement *stmt, const struct qbe_value *out, enum qbe_instr instr, ...);
const char *genl(struct qbe_statement *stmt, uint64_t *id, const char *fmt);
-void pushi(struct qbe_func *func, enum qbe_instr instr, const struct qbe_value *out, ...);
+void pushi(struct qbe_func *func, const struct qbe_value *out, enum qbe_instr instr, ...);
const char *pushl(struct qbe_func *func, uint64_t *id, const char *fmt);
void pushc(struct qbe_func *func, const char *text);
void push(struct qbe_func *func, struct qbe_statement *stmt);
diff --git a/src/gen.c b/src/gen.c
@@ -53,7 +53,7 @@ alloc_temp(struct gen_context *ctx, struct qbe_value *val,
struct qbe_value size;
constl(&size, type->size);
- pushi(ctx->current, alloc_for_align(type->align), val, &size, NULL);
+ pushi(ctx->current, val, alloc_for_align(type->align), &size, NULL);
}
// Given value src of type A, and value dest of type pointer to A, store src in
@@ -66,7 +66,7 @@ gen_store(struct gen_context *ctx,
const struct qbe_type *qtype = src->type;
assert(qtype->stype != Q__VOID); // Invariant
assert(qtype->stype != Q__AGGREGATE); // TODO
- pushi(ctx->current, store_for_type(qtype->stype), NULL, src, dest, NULL);
+ pushi(ctx->current, NULL, store_for_type(qtype->stype), src, dest, NULL);
}
// Given value src of type pointer to A, and value dest of type A, load dest
@@ -80,8 +80,8 @@ gen_load(struct gen_context *ctx,
const struct qbe_type *qtype = dest->type;
assert(qtype->stype != Q__VOID); // Invariant
assert(qtype->stype != Q__AGGREGATE); // TODO
- pushi(ctx->current,
- load_for_type(qtype->stype, is_signed), dest, src, NULL);
+ pushi(ctx->current, dest,
+ load_for_type(qtype->stype, is_signed), src, NULL);
}
// Same as gen_load but dest is initialized to a new temporary
@@ -158,7 +158,7 @@ gen_expr_return(struct gen_context *ctx,
if (expr->_return.value) {
gen_expression(ctx, expr->_return.value, ctx->return_value);
}
- pushi(ctx->current, Q_JMP, NULL, ctx->end_label, NULL);
+ pushi(ctx->current, NULL, Q_JMP, ctx->end_label, NULL);
}
static void
@@ -244,7 +244,7 @@ gen_function_decl(struct gen_context *ctx, const struct declaration *decl)
struct qbe_value load;
gen_loadtemp(ctx, &load, &rval, qdef->func.returns,
type_is_signed(fntype->func.result));
- pushi(&qdef->func, Q_RET, NULL, &load, NULL);
+ pushi(&qdef->func, NULL, Q_RET, &load, NULL);
qbe_append_def(ctx->out, qdef);
ctx->current = NULL;
diff --git a/src/qbe.c b/src/qbe.c
@@ -178,11 +178,11 @@ va_geni(struct qbe_statement *stmt, enum qbe_instr instr,
}
void
-geni(struct qbe_statement *stmt, enum qbe_instr instr,
- const struct qbe_value *out, ...)
+geni(struct qbe_statement *stmt, const struct qbe_value *out,
+ enum qbe_instr instr, ...)
{
va_list ap;
- va_start(ap, out);
+ va_start(ap, instr);
va_geni(stmt, instr, out, ap);
va_end(ap);
}
@@ -218,12 +218,12 @@ push(struct qbe_func *func, struct qbe_statement *stmt)
}
void
-pushi(struct qbe_func *func, enum qbe_instr instr,
- const struct qbe_value *out, ...)
+pushi(struct qbe_func *func, const struct qbe_value *out,
+ enum qbe_instr instr, ...)
{
struct qbe_statement stmt = {0};
va_list ap;
- va_start(ap, out);
+ va_start(ap, instr);
va_geni(&stmt, instr, out, ap);
va_end(ap);
push(func, &stmt);