Skip to content

Commit

Permalink
irgen: Generate explicit instantiations
Browse files Browse the repository at this point in the history
- explicit instantiations for all Vector and IndexedVector used in any
  .def file
  • Loading branch information
ChrisDodd committed May 27, 2024
1 parent ce5cb8c commit 7b6da8a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tools/ir-generator/irclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i
e->generate_impl(impl);
}

out << "#endif /* " << macroname << " */" << std::endl;

///////////////////////////////// tree

t << "#pragma once\n"
Expand All @@ -174,13 +172,22 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i
"D(Vector<IR::Node>) "
"B(Node), ##__VA_ARGS__) \\"
<< std::endl;
impl << "template class IR::Vector<IR::Node>;" << std::endl;
out << "extern template class IR::Vector<IR::Node>;" << std::endl;
impl << "template class IR::IndexedVector<IR::Node>;" << std::endl;
out << "extern template class IR::IndexedVector<IR::Node>;" << std::endl;
for (auto cls : *getClasses()) {
if (cls->needVector || cls->needIndexedVector)
if (cls->needVector || cls->needIndexedVector) {
t << "T(Vector<IR::" << cls->containedIn << cls->name
<< ">, D(Node), "
"##__VA_ARGS__) \\"
<< std::endl;
if (cls->needIndexedVector)
impl << "template class IR::Vector<IR::" << cls->containedIn << cls->name
<< ">;" << std::endl;
out << "extern template class IR::Vector<IR::" << cls->containedIn << cls->name
<< ">;" << std::endl;
}
if (cls->needIndexedVector) {
// We generate IndexedVector only if needed; we expect users won't use
// these if they don't want to place them in fields.
t << "T(IndexedVector<IR::" << cls->containedIn << cls->name
Expand All @@ -190,6 +197,11 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i
<< ">) "
"B(Node), ##__VA_ARGS__) \\"
<< std::endl;
impl << "template class IR::IndexedVector<IR::" << cls->containedIn << cls->name
<< ">;" << std::endl;
out << "extern template class IR::IndexedVector<IR::" << cls->containedIn << cls->name
<< ">;" << std::endl;
}
if (cls->needNameMap) BUG("visitable (non-inline) NameMap not yet implemented");
if (cls->needNodeMap) BUG("visitable (non-inline) NodeMap not yet implemented");
}
Expand Down Expand Up @@ -247,6 +259,8 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i
<< " inline bool operator!=(NodeDiscriminator lhs, RTTI::TypeId rhs) { return "
"RTTI::TypeId(lhs) != rhs; }\n";
t << "} // namespace IR" << std::endl;

out << "#endif /* " << macroname << " */" << std::endl;
}

void IrClass::generateTreeMacro(std::ostream &out) const {
Expand Down

0 comments on commit 7b6da8a

Please sign in to comment.