harec

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

commit af58546fbf151a25c075f85c0810034b696d02a7
parent c58aca7a0361e28bf25f24414e9fc00c11184f14
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 25 Sep 2021 13:05:11 +0200

gen: rig up anonymous type info via type()

This does not include the work necessary to actually gen the
static typeinfo declarations in gen_type_info.

Diffstat:
Msrc/gen.c | 18+++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -2511,7 +2511,11 @@ mktyperef(struct gen_context *ctx, const struct type *type) { size_t n; char *name; + struct qbe_def *qdef; switch (type->storage) { + case STORAGE_FCONST: + case STORAGE_ICONST: + abort(); // Invariant case STORAGE_BOOL: case STORAGE_CHAR: case STORAGE_F32: @@ -2539,9 +2543,6 @@ mktyperef(struct gen_context *ctx, const struct type *type) .type = type_store_type(ctx->store), .name = mkrttype(type->storage), }; - case STORAGE_FCONST: - case STORAGE_ICONST: - abort(); // Invariant case STORAGE_ALIAS: n = snprintf(NULL, 0, "type.%u", type->id); name = xcalloc(1, n + 1); @@ -2560,11 +2561,18 @@ mktyperef(struct gen_context *ctx, const struct type *type) case STORAGE_TAGGED: case STORAGE_TUPLE: case STORAGE_UNION: - // TODO: Emit typeinfo (here) + qdef = xcalloc(1, sizeof(struct qbe_def)); + qdef->name = gen_name(ctx, ".typeinfo.%d"); + qdef->kind = Q_DATA; + + struct qbe_data_item *subitem = &qdef->data.items; + gen_type_info(ctx, type, subitem); + qbe_append_def(ctx->out, qdef); + return (struct gen_value){ .kind = GV_GLOBAL, .type = type_store_type(ctx->store), - .name = "TODO", + .name = strdup(qdef->name), }; } abort(); // Unreachable