SpirVGenerator::Id SpirVGenerator::allocate_id(Node &node, Id type_id)
{
+ map<Node *, Declaration>::iterator i = declared_ids.find(&node);
+ if(i!=declared_ids.end())
+ {
+ if(i->second.type_id)
+ throw key_error(&node);
+ i->second.type_id = type_id;
+ return i->second.id;
+ }
+
+ Id id = next_id++;
+ declared_ids.insert(make_pair(&node, Declaration(id, type_id)));
+ return id;
+}
+
+SpirVGenerator::Id SpirVGenerator::allocate_forward_id(Node &node)
+{
+ map<Node *, Declaration>::iterator i = declared_ids.find(&node);
+ if(i!=declared_ids.end())
+ return i->second.id;
+
Id id = next_id++;
- insert_unique(declared_ids, &node, Declaration(id, type_id));
+ declared_ids.insert(make_pair(&node, Declaration(id, 0)));
return id;
}
void SpirVGenerator::visit(FunctionDeclaration &func)
{
- if(func.source==BUILTIN_SOURCE || func.definition!=&func)
+ if(func.source==BUILTIN_SOURCE)
return;
+ else if(func.definition!=&func)
+ {
+ if(func.definition)
+ allocate_forward_id(*func.definition);
+ return;
+ }
Id return_type_id = get_id(*func.return_type_declaration);
vector<unsigned> param_type_ids;
Id import_extension(const std::string &);
Id get_id(Node &) const;
Id allocate_id(Node &, Id);
+ Id allocate_forward_id(Node &);
Id write_constant(Id, Word, bool);
static ConstantKey get_constant_key(Id, const Variant &value);
Id get_constant_id(Id, const Variant &value);