3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-20 04:43:40 +00:00

Add helper for accessing by base name

The existing access function isn't useful if we don't have access to the original
names of the input/output/state signals. There may be a better way to do this, but
it might require restructuring the SmtrStruct.
This commit is contained in:
Gus Smith 2025-05-17 15:17:29 -07:00
parent 10b8fdddb4
commit 1fdfba2a1a

View file

@ -114,6 +114,15 @@ public:
size_t i = field_names.at(name);
return list(fields[i].accessor, std::move(record));
}
SExpr access_by_base_name(SExpr record, std::string base_name)
{
// Find the field by its base name
auto it = std::find_if(fields.begin(), fields.end(), [&](const Field &field) { return field.name == base_name; });
if (it == fields.end()) {
log_error("Field with base name '%s' not found in struct '%s'.\n", base_name.c_str(), name.c_str());
}
return list(it->accessor, std::move(record));
}
std::vector<std::string> get_field_names()
{
std::vector<std::string> names;