Fix some bugs related to nested scopes

This commit is contained in:
shylie 2026-03-25 01:00:49 -04:00
parent 36e067cbf6
commit 2e89bebfe6
3 changed files with 8 additions and 1 deletions

View File

@ -11,6 +11,7 @@ namespace vcppd
template <typename T> class Scope template <typename T> class Scope
{ {
friend T; friend T;
friend Scope<Scope>;
public: public:
Scope(const Scope&) = delete; Scope(const Scope&) = delete;
@ -18,6 +19,7 @@ public:
Scope<Scope> scope(const std::string& name) Scope<Scope> scope(const std::string& name)
{ {
parent.scope(name);
return Scope<Scope>(name, *this); return Scope<Scope>(name, *this);
} }

View File

@ -27,7 +27,7 @@ void Vcd::tick()
for (int i = 0; i < entry.size; i++) for (int i = 0; i < entry.size; i++)
{ {
uint8_t byte; uint8_t byte;
memcpy(&byte, static_cast<const uint8_t*>(entry.ref), 1); memcpy(&byte, static_cast<const uint8_t*>(entry.ref) + i, 1);
stream << std::format("{0:b}", byte); stream << std::format("{0:b}", byte);
} }
stream << " " << name << std::endl; stream << " " << name << std::endl;

View File

@ -4,11 +4,15 @@ int main(int argc, char** argv)
{ {
uint8_t eae = 0; uint8_t eae = 0;
uint8_t eae2 = 0; uint8_t eae2 = 0;
uint16_t eae3 = 1;
auto vcd = vcppd::Builder(std::cout) auto vcd = vcppd::Builder(std::cout)
.scope("TOP") .scope("TOP")
.trace("eae", eae) .trace("eae", eae)
.trace("eae2", eae2) .trace("eae2", eae2)
.scope("MIDDLE")
.trace("eae3", eae3)
.unscope()
.unscope() .unscope()
.build(); .build();
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
@ -16,6 +20,7 @@ int main(int argc, char** argv)
vcd.tick(); vcd.tick();
eae += 1; eae += 1;
eae2 += 2; eae2 += 2;
eae3 *= 2;
} }
return 0; return 0;