[qfcc] Make spirv kinds easier to use

Having a specific function for each kind gets out of hand fast.
This commit is contained in:
Bill Currie 2025-01-24 13:47:57 +09:00
parent d062fef8aa
commit f946a515e6
4 changed files with 11 additions and 11 deletions

View file

@ -100,6 +100,6 @@ const plitem_t *spirv_operand_kind (const char *set, const char *kind);
uint32_t spirv_instruction_opcode (const char *set, const expr_t *opcode);
bool spirv_setup_intrinsic_symtab (symtab_t *symtab);
uint32_t spirv_execution_model (const char *model);
uint32_t spirv_enum_val (const char *enum_name, const char *enumerant);
#endif//__spirv_grammar_h

View file

@ -66,7 +66,7 @@ new_attribute(const char *name, const expr_t *params)
if (e->expr.op != '='
|| !is_string_val (e->expr.e1)
|| e->expr.e2->type != ex_value) {
error (e, "not a key=literal constnat");
error (e, "not a key=literal constant");
err = true;
}
} else if (e->type != ex_value) {

View file

@ -535,7 +535,7 @@ spirv_setup_intrinsic_symtab (symtab_t *symtab)
}
uint32_t
spirv_execution_model (const char *model)
spirv_enum_val (const char *enum_name, const char *enumerant)
{
const char *set = "core";
auto grammar = find_grammar (set);
@ -544,15 +544,15 @@ spirv_execution_model (const char *model)
return false;
}
symtab_t symtab = { .procsymbol_data = grammar };
auto model_enum = spirv_intrinsic_symbol ("ExecutionModel", &symtab);
if (!model_enum) {
error (0, "ExecutionModel not found");
auto enum_enum = spirv_intrinsic_symbol (enum_name, &symtab);
if (!enum_enum) {
error (0, "%s not found", enum_name);
return 0;
}
auto model_val = symtab_lookup (model_enum->namespace, model);
if (!model_val) {
error (0, "Execution model %s not found", model);
auto enum_val = symtab_lookup (enum_enum->namespace, enumerant);
if (!enum_val) {
error (0, "Builtin %s not found", enumerant);
return 0;
}
return model_val->value->uint_val;
return enum_val->value->uint_val;
}

View file

@ -2233,7 +2233,7 @@ spirv_create_entry_point (const char *name, const char *model_name)
}
}
attribute_t *mode = nullptr;
unsigned model = spirv_execution_model (model_name);
unsigned model = spirv_enum_val ("ExecutionModel", model_name);
if (model == SpvExecutionModelFragment) {
mode = new_attribute ("mode",
new_int_expr (SpvExecutionModeOriginUpperLeft, false));