[qfcc] Support type inference for spir-v

I guess I hadn't thought of it because GLSL doesn't have `auto`, but
since the builtin functions are implemented in Ruamoko, `auto` is
available and I use it for the atomic image functions.
This commit is contained in:
Bill Currie 2025-01-14 01:15:19 +09:00
parent 9ba335f91e
commit 88253a847b
5 changed files with 20 additions and 10 deletions

View file

@ -165,6 +165,7 @@ const type_t *append_type (const type_t *type, const type_t *new);
specifier_t default_type (specifier_t spec, const struct symbol_s *sym);
const type_t *find_type (const type_t *new);
void new_typedef (const char *name, type_t *type);
const type_t *auto_type (const type_t *type, const expr_t *init);
const type_t *field_type (const type_t *aux);
const type_t *pointer_type (const type_t *aux);
const type_t *tagged_pointer_type (unsigned tag, const type_t *aux);

View file

@ -585,16 +585,7 @@ initialize_def (symbol_t *sym, const expr_t *init, defspace_t *space,
auto ele_type = dereference_type (sym->type);
sym->type = array_type (ele_type, num_elements (init));
}
if (sym->type == &type_auto) {
if (init) {
if (!(sym->type = get_type (init))) {
sym->type = type_default;
}
} else {
error (0, "'auto' requires an initialized data declaration");
sym->type = type_default;
}
}
sym->type = auto_type (sym->type, init);
sym->def = new_def (sym->name, sym->type, space, storage);
reloc_attach_relocs (relocs, &sym->def->relocs);
}

View file

@ -71,3 +71,4 @@ void dump_dot (const char *stage, const void *data,
void dump_dot_type (void *_t, const char *filename){}
char *fubar;
const char *file_basename(const char *p, int keepdot) { return fubar;}
__attribute__((const)) const type_t *get_type (const expr_t *e) {return nullptr;}

View file

@ -2065,6 +2065,7 @@ spirv_declare_sym (specifier_t spec, const expr_t *init, symtab_t *symtab,
}
}
auto storage = spirv_storage_class (spec.storage);
sym->type = auto_type (sym->type, init);
sym->type = tagged_reference_type (storage, sym->type);
sym->lvalue = !spec.is_const;
sym->sy_type = sy_var;

View file

@ -749,6 +749,22 @@ find_type (const type_t *type)
return new;
}
const type_t *
auto_type (const type_t *type, const expr_t *init)
{
if (type == &type_auto) {
if (init) {
if (!(type = get_type (init))) {
type = type_default;
}
} else {
error (0, "'auto' requires an initialized data declaration");
type = type_default;
}
}
return type;
}
const type_t *
field_type (const type_t *aux)
{