diff options
author | Miodrag Milanović <mmicko@gmail.com> | 2022-05-09 09:28:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-09 09:28:09 +0200 |
commit | 58b23954e89a75e726d98716d5029f148c804073 (patch) | |
tree | 7462e655ef0c7e5321b494ca17096c3aeffaf899 /kernel | |
parent | 600079e281d1dcf295c1c97616109b5ea5f3d34d (diff) | |
parent | d8adbff72f6648589d7699857ee8c65a80315033 (diff) | |
download | yosys-58b23954e89a75e726d98716d5029f148c804073.tar.gz yosys-58b23954e89a75e726d98716d5029f148c804073.tar.bz2 yosys-58b23954e89a75e726d98716d5029f148c804073.zip |
Merge pull request #3299 from YosysHQ/mmicko/sim_memory
sim pass: support for memories
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/fstdata.cc | 38 | ||||
-rw-r--r-- | kernel/fstdata.h | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/kernel/fstdata.cc b/kernel/fstdata.cc index 2bec58bcf..fea8ee3c3 100644 --- a/kernel/fstdata.cc +++ b/kernel/fstdata.cc @@ -85,6 +85,13 @@ fstHandle FstData::getHandle(std::string name) { return 0; }; +dict<int,fstHandle> FstData::getMemoryHandles(std::string name) { + if (memory_to_handle.find(name) != memory_to_handle.end()) + return memory_to_handle[name]; + else + return dict<int,fstHandle>(); +}; + static std::string remove_spaces(std::string str) { str.erase(std::remove(str.begin(), str.end(), ' '), str.end()); @@ -126,7 +133,36 @@ void FstData::extractVarNames() } if (clean_name[0]=='\\') clean_name = clean_name.substr(1); - + size_t pos = clean_name.find_last_of("<"); + if (pos != std::string::npos) { + std::string mem_cell = clean_name.substr(0, pos); + std::string addr = clean_name.substr(pos+1); + addr.pop_back(); // remove closing bracket + char *endptr; + int mem_addr = strtol(addr.c_str(), &endptr, 16); + if (*endptr) { + log_warning("Error parsing memory address in : %s\n", clean_name.c_str()); + } else { + memory_to_handle[var.scope+"."+mem_cell][mem_addr] = var.id; + name_to_handle[stringf("%s.%s[%d]",var.scope.c_str(),mem_cell.c_str(),mem_addr)] = h->u.var.handle; + continue; + } + } + pos = clean_name.find_last_of("["); + if (pos != std::string::npos) { + std::string mem_cell = clean_name.substr(0, pos); + std::string addr = clean_name.substr(pos+1); + addr.pop_back(); // remove closing bracket + char *endptr; + int mem_addr = strtol(addr.c_str(), &endptr, 10); + if (*endptr) { + log_warning("Error parsing memory address in : %s\n", clean_name.c_str()); + } else { + memory_to_handle[var.scope+"."+mem_cell][mem_addr] = var.id; + name_to_handle[stringf("%s.%s[%d]",var.scope.c_str(),mem_cell.c_str(),mem_addr)] = h->u.var.handle; + continue; + } + } name_to_handle[var.scope+"."+clean_name] = h->u.var.handle; break; } diff --git a/kernel/fstdata.h b/kernel/fstdata.h index d8dca5fb0..f5cf1d48d 100644 --- a/kernel/fstdata.h +++ b/kernel/fstdata.h @@ -54,6 +54,7 @@ class FstData std::string valueOf(fstHandle signal); fstHandle getHandle(std::string name); + dict<int,fstHandle> getMemoryHandles(std::string name); double getTimescale() { return timescale; } const char *getTimescaleString() { return timescale_str.c_str(); } private: @@ -63,6 +64,7 @@ private: std::vector<FstVar> vars; 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<fstHandle, std::string> last_data; uint64_t last_time; std::map<fstHandle, std::string> past_data; |