diff --git a/ir/copy_on_write_inl.h b/ir/copy_on_write_inl.h index 743ad8ae93..8b9d07160a 100644 --- a/ir/copy_on_write_inl.h +++ b/ir/copy_on_write_inl.h @@ -233,6 +233,15 @@ struct COWfieldref, field> { // FIXME -- need NodeMap specializations if any backend ever uses that template +/* specialization for std::variant */ +template T::*field> +struct COWfieldref, field> { + COWinfo *info; + + size_t index() const { return info->get()->*field.index(); } + // FIXME -- what do we need here? Do we need a specialization of std::visit? +}; + } // namespace P4::IR #endif /* IR_COPY_ON_WRITE_INL_H_ */ diff --git a/tools/ir-generator/irclass.cpp b/tools/ir-generator/irclass.cpp index 0b09d0f855..328e5a04d6 100644 --- a/tools/ir-generator/irclass.cpp +++ b/tools/ir-generator/irclass.cpp @@ -448,12 +448,17 @@ IrElement::access_t IrClass::outputCOWfieldrefs(std::ostream &out) const { if (fld->isStatic) continue; if (e->access != access) out << indent << (access = e->access); out << indent << "COWfieldref<" << name << ", "; - const IrClass *cls = fld->type->resolve(fld->clss ? fld->clss->containedIn : nullptr); - if (cls != nullptr && !fld->isInline) out << "const "; - out << fld->type->toString(); - if (cls != nullptr && !fld->isInline) out << "*"; - out << fld->type->declSuffix() << ", &" << name << "::" << fld->name << "> " - << fld->name << ";\n"; + if (fld->is()) { + out << fld->name << "_variant"; + } else { + const IrClass *cls = fld->type->resolve(fld->clss ? fld->clss->containedIn + : nullptr); + if (cls != nullptr && !fld->isInline) out << "const "; + out << fld->type->toString(); + if (cls != nullptr && !fld->isInline) out << "*"; + out << fld->type->declSuffix(); + } + out << ", &" << name << "::" << fld->name << "> " << fld->name << ";\n"; } } return access;