harec

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

commit 54e90c96c0b78b2b80b07563cf9f25cb2574e2e1
parent 98bca555e925528996607579e5d1e6c6ca806f1e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  2 Aug 2021 18:36:55 +0200

gen: implement field access

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

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

diff --git a/src/gen.c b/src/gen.c @@ -174,6 +174,21 @@ gen_access_ident(struct gen_context *ctx, const struct expression *expr) } static struct gen_value +gen_access_field(struct gen_context *ctx, const struct expression *expr) +{ + const struct struct_field *field = expr->access.field; + struct gen_value glval = gen_expr(ctx, expr->access._struct); + struct qbe_value qlval = mkcopy(ctx, &glval, "object.%d"); + struct qbe_value offs = constl(field->offset); + pushi(ctx->current, &qlval, Q_ADD, &qlval, &offs, NULL); + return (struct gen_value){ + .kind = GV_TEMP, + .type = field->type, + .name = qlval.name, + }; +} + +static struct gen_value gen_expr_access(struct gen_context *ctx, const struct expression *expr) { struct gen_value addr; @@ -182,7 +197,10 @@ gen_expr_access(struct gen_context *ctx, const struct expression *expr) addr = gen_access_ident(ctx, expr); break; case ACCESS_INDEX: + assert(0); // TODO case ACCESS_FIELD: + addr = gen_access_field(ctx, expr); + break; case ACCESS_TUPLE: assert(0); // TODO }