[qfcc] Use temp expressions as spir-v id carriers

spir-v uses SSA, so temps cannot be assigned to directly, so instead use
the temp expression as a reference for the result id of the rhs of the
assignment. This would get function calls working if the they actually
emitted any code (right now, just a place-holder id so spirv-dis doesn't
fall over).
This commit is contained in:
Bill Currie 2024-11-04 16:42:44 +09:00
parent 95cedd879a
commit a0845e65fb
3 changed files with 20 additions and 2 deletions

View file

@ -859,6 +859,7 @@ bool is_math_op (int op) __attribute__((const));
bool is_logic (int op) __attribute__((const));
bool is_deref (const expr_t *e) __attribute__((pure));
bool is_temp (const expr_t *e) __attribute__((pure));
bool has_function_call (const expr_t *e) __attribute__((pure));
bool is_function_call (const expr_t *e) __attribute__((pure));

View file

@ -1880,6 +1880,12 @@ is_deref (const expr_t *e)
return e->type == ex_uexpr && e->expr.op == '.';
}
bool
is_temp (const expr_t *e)
{
return e->type == ex_temp;
}
bool
has_function_call (const expr_t *e)
{

View file

@ -798,12 +798,22 @@ spirv_assign (const expr_t *e, spirvctx_t *ctx)
unsigned src = spirv_emit_expr (e->assign.src, ctx);
unsigned dst = 0;
if (is_temp (e->assign.dst)) {
// spir-v uses SSA, so temps cannot be assigned to directly, so instead
// use the temp expression as a reference for the result id of the
// rhs of the assignment.
//FIXME const cast (store elsewhere)
((expr_t *) e->assign.dst)->id = src;
return src;
}
if (is_deref (e->assign.dst)) {
auto ptr = e->assign.dst->expr.e1;
dst = spirv_emit_expr (ptr, ctx);
}
if (!dst) return src;//FIXME workaround for temp
if (!dst) {
internal_error (e, "invalid assignment?");
}
auto def = spirv_new_insn (SpvOpStore, 3, ctx->current);
D_var_o(int, def, 1) = dst;
@ -814,7 +824,8 @@ spirv_assign (const expr_t *e, spirvctx_t *ctx)
static unsigned
spirv_branch (const expr_t *e, spirvctx_t *ctx)
{
return 0;
//FIXME
return 1;
}
static unsigned