From f73ddb3381aabac0030a1d2955ce550362e68bd2 Mon Sep 17 00:00:00 2001 From: James Cherry Date: Wed, 26 Oct 2022 11:00:40 -0700 Subject: [PATCH] read_vcd var scope Signed-off-by: James Cherry --- search/ReadVcd.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/search/ReadVcd.cc b/search/ReadVcd.cc index 217fdc4c..ca2120e0 100644 --- a/search/ReadVcd.cc +++ b/search/ReadVcd.cc @@ -39,6 +39,7 @@ class VcdVar; class VcdValue; typedef vector VcdValues; typedef int64_t VarTime; +typedef vector VcdScope; // Very imprecise syntax definition // https://en.wikipedia.org/wiki/Value_change_dump#Structure.2FSyntax @@ -85,6 +86,7 @@ private: map id_values_map_; VarTime time_; VarTime time_max_; + VcdScope scope_; }; class VcdVar @@ -236,7 +238,20 @@ VcdReader::parseVar() int width = stoi(tokens[1]); string id = tokens[2]; - string name = tokens[3]; + string name; + + int level = 0; + for (string &context : scope_) { + // Skip the first 2 levels of scope. + // -test bench module + // -design instance + if (level > 1) { + name += context; + name += '/'; + } + level++; + } + name += tokens[3]; // iverilog separates bus base name from bit range. if (tokens.size() == 5) name += tokens[4]; @@ -252,13 +267,16 @@ VcdReader::parseVar() void VcdReader::parseScope() { - readStmtTokens(); + vector tokens = readStmtTokens(); + string &scope = tokens[1]; + scope_.push_back(scope); } void VcdReader::parseUpscope() { readStmtTokens(); + scope_.pop_back(); } // Make entries for each ID used by variables.