harec

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

commit 24110631779e71493b5219f7e0fdecc9cd3c7b3e
parent ebb0549a72bf561e2dc0ed65970b186f1defe83d
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat,  3 Jul 2021 11:48:09 -0400

gen: implement indirect assignment

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

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

diff --git a/src/gen.c b/src/gen.c @@ -368,12 +368,26 @@ gen_expr_assign(struct gen_context *ctx, assert(0); // TODO } - assert(!expr->assign.indirect); // TODO assert(object->type == EXPR_ACCESS); // Invariant struct gen_temp obj; gen_access_address(ctx, &obj, object); - gen_expr(ctx, value, &obj); + if (expr->assign.indirect) { + struct gen_temp temp; + gen_direct(ctx, &temp, object->result, "assign.%d"); + + struct qbe_value qtemp, otemp; + qval_temp(ctx, &qtemp, &temp); + qval_temp(ctx, &otemp, &obj); + enum qbe_instr instr = load_for_type(ctx, object->result); + pushi(ctx->current, &qtemp, instr, &otemp, NULL); + + temp.indirect = true; + temp.type = type_dereference(object->result); + gen_expr(ctx, value, &temp); + } else { + gen_expr(ctx, value, &obj); + } } static void