compiler

Unnamed Compiled Systems Language Project
git clone http://frotz.net/git/compiler.git
Log | Files | Refs

commit e886a2fd04ee2edbef3e73e08ee5c321f6199251
parent ac2c86d387816bd127c17453abcd98e02092cc80
Author: Brian Swetland <swetland@frotz.net>
Date:   Fri, 17 Dec 2021 14:29:02 -0800

ir: better assign codegen

- special case assign where lhs is SYMBOL to avoid mov + st where st works

Diffstat:
Msrc/codegen-ir.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/codegen-ir.c b/src/codegen-ir.c @@ -281,14 +281,21 @@ i32 gen_addr_expr(Ast node) { i32 gen_assign(Ast lhs, Ast expr) { gen_trace("gen_assign()"); - i32 raddr = gen_addr_expr(lhs); + i32 base; + i32 offset; + if (lhs->kind == AST_SYMBOL) { + sym_get_loc(lhs->sym, &base, &offset); + } else { + base = gen_addr_expr(lhs); + offset = 0; + } i32 rval = gen_expr(expr); if (lhs->type->size == 4) { - inst_stwi(rval, raddr, 0); + inst_stwi(rval, base, offset); return rval; } else if (lhs->type->size == 1) { - inst_stbi(rval, raddr, 0); + inst_stbi(rval, base, offset); return rval; } else { err_ast = lhs;