[qfcc] Handle address of field expressions

In particular, spir-v needs special handling to avoid unwanted loads.
This commit is contained in:
Bill Currie 2025-01-21 22:43:51 +09:00
parent 198821f0d3
commit 53afbc3a9b
2 changed files with 20 additions and 0 deletions

View file

@ -2579,6 +2579,9 @@ address_expr (const expr_t *e1, const type_t *t)
break;
}
return error (e1, "invalid type for unary &");
case ex_field:
e = new_address_expr (e1->field.type, e1, nullptr);
break;
case ex_expr:
if (e1->expr.op == '.') {
e = new_address_expr (e1->expr.type,

View file

@ -1571,6 +1571,22 @@ spirv_access_chain (const expr_t *e, spirvctx_t *ctx,
return id;
}
static unsigned
spirv_address (const expr_t *e, spirvctx_t *ctx)
{
auto lvalue = e->address.lvalue;
if (lvalue->type != ex_field && lvalue->type != ex_array) {
internal_error (e, "not field or array");
}
if (e->address.offset) {
internal_error (e, "offset on address");
}
const type_t *res_type;
const type_t *acc_type;
unsigned id = spirv_access_chain (lvalue, ctx, &res_type, &acc_type);
return id;
}
static unsigned
spirv_assign (const expr_t *e, spirvctx_t *ctx)
{
@ -1958,6 +1974,7 @@ spirv_emit_expr (const expr_t *e, spirvctx_t *ctx)
[ex_vector] = spirv_vector,
[ex_compound] = spirv_compound,
[ex_alias] = spirv_alias,
[ex_address] = spirv_address,
[ex_assign] = spirv_assign,
[ex_branch] = spirv_branch,
[ex_return] = spirv_return,