harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit f9a224f8ccb000b709e42ed4ee41d25822822ab5
parent ae5d1492884997ae3036dbc24a4a111bec67a5a4
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed,  4 Aug 2021 08:48:22 +0200

gen: add mkrtfunc utility

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Minclude/gen.h | 1+
Msrc/gen.c | 12++----------
Msrc/genutil.c | 11+++++++++++
3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/include/gen.h b/include/gen.h @@ -71,6 +71,7 @@ struct qbe_value mkcopy(struct gen_context *ctx, struct gen_value *value, const char *fmt); struct qbe_value mkqtmp(struct gen_context *ctx, const struct qbe_type *qtype, const char *fmt); +struct qbe_value mkrtfunc(struct gen_context *ctx, const char *name); // qinstr.c enum qbe_instr alloc_for_align(size_t align); diff --git a/src/gen.c b/src/gen.c @@ -17,11 +17,7 @@ static void gen_copy_memcpy(struct gen_context *ctx, struct gen_value dest, struct gen_value src) { - struct qbe_value rtfunc = { - .kind = QV_GLOBAL, - .name = strdup("rt.memcpy"), - .type = &qbe_long, - }; + struct qbe_value rtfunc = mkrtfunc(ctx, "rt.memcpy"); struct qbe_value sz = constl(dest.type->size); struct qbe_value dtemp = { .kind = QV_TEMPORARY, @@ -373,11 +369,7 @@ gen_expr_struct_at(struct gen_context *ctx, struct qbe_value base = mkqval(ctx, &out); if (expr->_struct.autofill) { - struct qbe_value rtfunc = { - .kind = QV_GLOBAL, - .name = strdup("rt.memset"), - .type = &qbe_long, - }; + struct qbe_value rtfunc = mkrtfunc(ctx, "rt.memset"); struct qbe_value size = constl(expr->result->size), zero = constl(0); pushi(ctx->current, NULL, Q_CALL, &rtfunc, diff --git a/src/genutil.c b/src/genutil.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "gen.h" #include "qbe.h" #include "util.h" @@ -72,3 +73,13 @@ mktemp(struct gen_context *ctx, const struct type *type, const char *fmt) .name = gen_name(ctx, fmt), }; } + +struct qbe_value +mkrtfunc(struct gen_context *ctx, const char *name) +{ + return (struct qbe_value){ + .kind = QV_GLOBAL, + .name = strdup(name), + .type = ctx->arch.ptr, + }; +}