38 lines
724 B
C++
38 lines
724 B
C++
#include "vcppd/vcd.h"
|
|
|
|
#include "vcppd/builder.h"
|
|
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
#include <format>
|
|
|
|
using namespace vcppd;
|
|
|
|
Vcd::Vcd(const Builder& builder) :
|
|
stream(builder.stream),
|
|
variables(builder.variables),
|
|
current_time(0)
|
|
{
|
|
}
|
|
|
|
Vcd::~Vcd() { stream << std::format("#{}", current_time) << std::endl; }
|
|
|
|
void Vcd::tick()
|
|
{
|
|
stream << std::format("#{}", current_time) << std::endl;
|
|
|
|
for (const auto& [name, entry] : variables)
|
|
{
|
|
stream << "b";
|
|
for (int i = 0; i < entry.size; i++)
|
|
{
|
|
uint8_t byte;
|
|
memcpy(&byte, static_cast<const uint8_t*>(entry.ref) + i, 1);
|
|
stream << std::format("{0:b}", byte);
|
|
}
|
|
stream << " " << name << std::endl;
|
|
}
|
|
|
|
current_time += 1;
|
|
}
|