~sircmpwn/harec

ddc7d8be15830d5e5876018a19d0ec04218a6648 — Sebastian 1 year, 2 months ago 6780161
emit: deduplicate gen_typename from check

The functions were identical, except that the definition within emit
didn't check for errors after calling open_memstream.

Signed-off-by: Sebastian <sebastian@sebsite.pw>
3 files changed, 4 insertions(+), 12 deletions(-)

M include/check.h
M src/check.c
M src/emit.c
M include/check.h => include/check.h +2 -0
@@ 127,6 127,8 @@ void mkident(struct context *ctx, struct identifier *out,

void mkstrconst(struct expression *expr, const char *fmt, ...);

char *gen_typename(const struct type *type);

typedef void (*resolvefn)(struct context *,
		struct incomplete_declaration *idecl);


M src/check.c => src/check.c +1 -1
@@ 53,7 53,7 @@ mkstrconst(struct expression *expr, const char *fmt, ...)
	expr->constant.string.len = n;
}

static char *
char *
gen_typename(const struct type *type)
{
	size_t sz = 0;

M src/emit.c => src/emit.c +1 -11
@@ 3,6 3,7 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include "check.h"
#include "emit.h"
#include "qbe.h"
#include "typedef.h"


@@ 34,17 35,6 @@ emit_qtype(const struct qbe_type *type, bool aggr, FILE *out)
	}
}

static char *
gen_typename(const struct type *type)
{
	size_t sz = 0;
	char *ptr = NULL;
	FILE *f = open_memstream(&ptr, &sz);
	emit_type(type, f);
	fclose(f);
	return ptr;
}

static void
qemit_type(const struct qbe_def *def, FILE *out)
{