From 1fdfba2a1afd9a7811c314914c0ee53cc9abff8e Mon Sep 17 00:00:00 2001 From: Gus Smith Date: Sat, 17 May 2025 15:17:29 -0700 Subject: [PATCH] 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. --- backends/functional/smtlib_rosette.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backends/functional/smtlib_rosette.cc b/backends/functional/smtlib_rosette.cc index 6769d7384..82bfd662a 100644 --- a/backends/functional/smtlib_rosette.cc +++ b/backends/functional/smtlib_rosette.cc @@ -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 get_field_names() { std::vector names;