From ad48639cdd2c929a867ea046bc4612c622ebfcee Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 4 May 2022 10:41:04 +0200 Subject: Start restoring memory state from VCD/FST --- kernel/fstdata.cc | 32 +++++++++++++++++++++++++++++++- kernel/fstdata.h | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'kernel') diff --git a/kernel/fstdata.cc b/kernel/fstdata.cc index 2bec58bcf..1bf43bfdd 100644 --- a/kernel/fstdata.cc +++ b/kernel/fstdata.cc @@ -85,6 +85,13 @@ fstHandle FstData::getHandle(std::string name) { return 0; }; +dict FstData::getMemoryHandles(std::string name) { + if (memory_to_handle.find(name) != memory_to_handle.end()) + return memory_to_handle[name]; + else + return dict(); +}; + static std::string remove_spaces(std::string str) { str.erase(std::remove(str.begin(), str.end(), ' '), str.end()); @@ -126,7 +133,30 @@ 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_error("Error parsing memory address in : %s\n", clean_name.c_str()); + } + memory_to_handle[var.scope+"."+mem_cell][mem_addr] = var.id; + } + 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_error("Error parsing memory address in : %s\n", clean_name.c_str()); + } + memory_to_handle[var.scope+"."+mem_cell][mem_addr] = var.id; + } 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 getMemoryHandles(std::string name); double getTimescale() { return timescale; } const char *getTimescaleString() { return timescale_str.c_str(); } private: @@ -63,6 +64,7 @@ private: std::vector vars; std::map handle_to_var; std::map name_to_handle; + std::map> memory_to_handle; std::map last_data; uint64_t last_time; std::map past_data; -- cgit v1.2.3