Skip to content

Commit

Permalink
COWptr/variant fixes (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDodd committed Dec 13, 2024
1 parent 70531da commit 74626b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 9 additions & 0 deletions ir/copy_on_write_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ struct COWfieldref<T, NameMap<U, MAP>, field> {

// FIXME -- need NodeMap specializations if any backend ever uses that template

/* specialization for std::variant */
template <class T, class... TYPES, std::variant<TYPES...> T::*field>
struct COWfieldref<T, std::variant<TYPES...>, field> {
COWinfo<T> *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_ */
17 changes: 11 additions & 6 deletions tools/ir-generator/irclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IrVariantField>()) {
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;
Expand Down

0 comments on commit 74626b4

Please sign in to comment.