mirror of
https://github.com/YosysHQ/yosys
synced 2026-07-18 21:25:47 +00:00
remove ambiguity in implementation
This commit is contained in:
parent
01f0fd751f
commit
857f356f1f
3 changed files with 26 additions and 38 deletions
|
|
@ -96,10 +96,17 @@ fstHandle FstData::getHandle(std::string name) {
|
|||
return 0;
|
||||
};
|
||||
|
||||
dict<int,fstHandle> FstData::getMemoryHandles(std::string name) {
|
||||
dict<int,fstHandle> FstData::getMemoryHandles(std::string name) {
|
||||
if (memory_to_handle.find(name) != memory_to_handle.end())
|
||||
return memory_to_handle[name];
|
||||
else
|
||||
else
|
||||
return dict<int,fstHandle>();
|
||||
};
|
||||
|
||||
dict<int,fstHandle> FstData::getArrayHandles(std::string name) {
|
||||
if (array_to_handle.find(name) != array_to_handle.end())
|
||||
return array_to_handle[name];
|
||||
else
|
||||
return dict<int,fstHandle>();
|
||||
};
|
||||
|
||||
|
|
@ -219,7 +226,7 @@ void FstData::extractVarNames()
|
|||
// Check it's an array index (no colon), not a bit range
|
||||
if (index_str.find(':') == std::string::npos) {
|
||||
int array_index = std::stoi(index_str);
|
||||
memory_to_handle[var.scope+"."+clean_name][array_index] = var.id;
|
||||
array_to_handle[var.scope+"."+clean_name][array_index] = var.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class FstData
|
|||
std::string valueOf(fstHandle signal);
|
||||
fstHandle getHandle(std::string name);
|
||||
dict<int,fstHandle> getMemoryHandles(std::string name);
|
||||
dict<int,fstHandle> getArrayHandles(std::string name);
|
||||
double getTimescale() { return timescale; }
|
||||
const char *getTimescaleString() { return timescale_str.c_str(); }
|
||||
int getWidth(fstHandle signal);
|
||||
|
|
@ -67,6 +68,7 @@ private:
|
|||
std::map<fstHandle, FstVar> handle_to_var;
|
||||
std::map<std::string, fstHandle> name_to_handle;
|
||||
std::map<std::string, dict<int, fstHandle>> memory_to_handle;
|
||||
std::map<std::string, dict<int, fstHandle>> array_to_handle;
|
||||
std::map<fstHandle, std::string> last_data;
|
||||
uint64_t last_time;
|
||||
std::map<fstHandle, std::string> past_data;
|
||||
|
|
|
|||
|
|
@ -230,43 +230,22 @@ struct SimInstance
|
|||
|
||||
// Helper function to detect and retrieve array element handles
|
||||
// Returns non-empty dict if wire is a multi-dimensional array split in VCD
|
||||
dict<int, fstHandle> tryGetArrayHandles(FstData* fst, const std::string& scope,
|
||||
Wire* wire, bool debug_mode)
|
||||
dict<int, fstHandle> tryGetArrayHandles(FstData* fst, const std::string& scope, Wire* wire)
|
||||
{
|
||||
std::string wire_name = scope + "." + RTLIL::unescape_id(wire->name);
|
||||
fstHandle id = fst->getHandle(wire_name);
|
||||
dict<int, fstHandle> array_handles = fst->getArrayHandles(wire_name);
|
||||
|
||||
if (id != 0) {
|
||||
int fst_width = fst->getWidth(id);
|
||||
if (fst_width != wire->width) {
|
||||
// If there is a width mismatch, try to find array elements
|
||||
if (debug_mode) {
|
||||
log("Wire %s width mismatch (wire: %d, FST: %d), checking for array elements.\n",
|
||||
wire_name.c_str(), wire->width, fst_width);
|
||||
}
|
||||
|
||||
// Array elements are stored in memory_to_handle
|
||||
dict<int, fstHandle> array_handles = fst->getMemoryHandles(wire_name);
|
||||
if (!array_handles.empty()) {
|
||||
|
||||
// Calculate total width of all array elements
|
||||
int total_width = 0;
|
||||
for (auto &pair : array_handles) {
|
||||
total_width += fst->getWidth(pair.second);
|
||||
}
|
||||
|
||||
// If the total width of all array elements matches the wire, return the corresponding array handles
|
||||
if (total_width == wire->width) {
|
||||
if (debug_mode) {
|
||||
log("Found %zu array elements for wire %s, total width: %d\n",
|
||||
array_handles.size(), wire_name.c_str(), total_width);
|
||||
}
|
||||
return array_handles;
|
||||
} else if (debug_mode) {
|
||||
log_warning("Array elements total width %d doesn't match wire width %d\n",
|
||||
total_width, wire->width);
|
||||
}
|
||||
if (!array_handles.empty()) {
|
||||
int total_width = 0;
|
||||
for (auto &pair : array_handles) {
|
||||
total_width += fst->getWidth(pair.second);
|
||||
}
|
||||
if (total_width == wire->width) {
|
||||
if (shared->debug) {
|
||||
log("Found %zu array elements for wire %s, total width: %d\n",
|
||||
array_handles.size(), wire_name.c_str(), total_width);
|
||||
}
|
||||
return array_handles;
|
||||
}
|
||||
}
|
||||
return dict<int, fstHandle>();
|
||||
|
|
@ -308,7 +287,7 @@ struct SimInstance
|
|||
fstHandle id = shared->fst->getHandle(scope + "." + RTLIL::unescape_id(wire->name));
|
||||
|
||||
// Try to get array element handles if this is a multi-dimensional array
|
||||
dict<int, fstHandle> array_handles = tryGetArrayHandles(shared->fst, scope, wire, shared->debug);
|
||||
dict<int, fstHandle> array_handles = tryGetArrayHandles(shared->fst, scope, wire);
|
||||
if (!array_handles.empty()) {
|
||||
// Must be an array, store in fst_array_handles
|
||||
fst_array_handles[wire] = array_handles;
|
||||
|
|
@ -1612,7 +1591,7 @@ struct SimWorker : SimShared
|
|||
fstHandle id = fst->getHandle(scope + "." + RTLIL::unescape_id(wire->name));
|
||||
|
||||
// Try to get array element handles if this is a multi-dimensional array
|
||||
dict<int, fstHandle> array_handles = top->tryGetArrayHandles(fst, scope, wire, debug);
|
||||
dict<int, fstHandle> array_handles = top->tryGetArrayHandles(fst, scope, wire);
|
||||
if (!array_handles.empty()) {
|
||||
// Must be an array, store in fst_array_inputs
|
||||
top->fst_array_inputs[wire] = array_handles;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue