59 cleanName(std::string
name)
61 for (
int i = 0;
i < name.length();
i++) {
64 else if (name[
i] ==
']')
80 const char first = orig[0];
82 if (first !=
'z' && first !=
'x' && first !=
'0')
85 const char *res = orig;
86 while (*++res == first) {}
88 if (first !=
'0' || *res !=
'1')
123 os << rep <<
vcdName() << std::endl;;
136 void vcdName(
const std::string &vcd_name) { _vcdName = vcd_name; }
138 virtual std::string
vcdType() {
return "wire"; }
140 virtual void output(std::ostream &
os) = 0;
146 size_t pos = name.find_first_of(
'.');
147 if (pos == std::string::npos) {
148 values.emplace_back(name, value);
150 std::string sname = name.substr(0, pos);
151 auto it = scopes.find(sname);
152 if (it == scopes.end())
154 it->second->addValue(name.substr(pos + 1), value);
161 os <<
"$scope module " << name <<
" $end" << std::endl;
163 for (
auto &
p: values) {
164 const std::string &name =
p.first;
169 std::string msg =
csprintf(
"'%s' has 0 bits", name);
176 std::string clean_name = cleanName(name);
178 ccprintf(os,
"$var %s % 3d %s %s $end\n",
181 ccprintf(os,
"$var %s % 3d %s %s [%d:0] $end\n",
186 for (
auto &
p: scopes)
187 p.second->output(
p.first, os);
189 os <<
"$upscope $end" << std::endl;
192 template <
typename T>
208 std::string
name(_nextName);
211 int pos = NextNameChars - 1;
213 carry = (_nextName[pos] ==
'z');
215 _nextName[pos--] =
'a';
218 }
while (carry && pos >= 0);
229 stream() <<
"$date" << std::endl;
232 struct tm *p_tm = localtime(&long_time);
233 stream() << std::put_time(p_tm,
" %b %d, %Y %H:%M:%S\n");
234 stream() <<
"$end" << std::endl << std::endl;
237 stream() <<
"$version" << std::endl;
239 stream() <<
"$end" << std::endl << std::endl;
242 stream() <<
"$timescale" << std::endl;
245 stream() <<
"$end" << std::endl << std::endl;
247 for (
auto tv: traceVals)
250 topScope.output(
"SystemC", stream());
252 stream() <<
"$enddefinitions $end" << std::endl << std::endl;
256 std::string timedump_comment =
257 csprintf(
"All initial values are dumped below at time " 258 "%g sec = %g timescale units.",
260 static_cast<double>(now / timeUnitTicks));
261 writeComment(timedump_comment);
263 lastPrintedTime = now / timeUnitTicks;
265 stream() <<
"$dumpvars" << std::endl;
266 for (
auto tv: traceVals)
267 tv->output(stream());
268 stream() <<
"$end" << std::endl << std::endl;
275 for (
auto tv: traceVals)
289 uint64_t deltaOffset = deltasAtNow;
292 deltaOffset = deltasAtNow++;
294 if (_traceDeltas != delta)
304 if (now <= lastPrintedTime) {
309 bool time_printed =
false;
310 for (
auto tv: traceVals) {
313 lastPrintedTime = now;
318 tv->output(stream());
322 stream() << std::endl;
333 printVal(os, this->value() ?
"1" :
"0");
340 addNewTraceVal<VcdTraceValBool>(
v,
name);
343 template <
typename T>
349 std::string
vcdType()
override {
return "real"; }
361 addNewTraceVal<VcdTraceValFloat<float>>(
v,
name);
366 addNewTraceVal<VcdTraceValFloat<double>>(
v,
name);
388 addNewTraceVal<VcdTraceValScLogic>(
v,
name);
391 template <
typename T>
401 this->
_width = this->value().length();
408 const int w = this->
width();
411 for (
int i = w - 1;
i >= 0;
i--)
412 str += this->value()[
i].to_bool() ?
'1' :
'0';
420 const std::string &name)
422 addNewTraceVal<VcdTraceValFinite<sc_dt::sc_int_base>>(
v,
name);
426 const std::string &name)
428 addNewTraceVal<VcdTraceValFinite<sc_dt::sc_uint_base>>(
v,
name);
434 addNewTraceVal<VcdTraceValFinite<sc_dt::sc_signed>>(
v,
name);
438 const std::string &name)
440 addNewTraceVal<VcdTraceValFinite<sc_dt::sc_unsigned>>(
v,
name);
443 template <
typename T>
453 this->
_width = this->value().length();
466 addNewTraceVal<VcdTraceValLogic<::sc_dt::sc_bv_base>>(
v,
name);
471 addNewTraceVal<VcdTraceValLogic<::sc_dt::sc_lv_base>>(
v,
name);
474 template <
typename T>
480 std::string
vcdType()
override {
return "real"; }
486 this->value().to_double(), this->
vcdName());
493 addNewTraceVal<VcdTraceValFxval<sc_dt::sc_fxval>>(
v,
name);
497 const std::string &name)
499 addNewTraceVal<VcdTraceValFxval<sc_dt::sc_fxval_fast>>(
v,
name);
502 template <
typename T>
512 const int w = this->
width();
515 for (
int i = w - 1;
i >= 0;
i--)
516 str += this->value()[
i] ?
'1' :
'0';
525 addNewTraceVal<VcdTraceValFxnum<::sc_dt::sc_fxnum>>(
v,
name);
529 const std::string &name)
531 addNewTraceVal<VcdTraceValFxnum<::sc_dt::sc_fxnum_fast>>(
v,
name);
539 std::string
vcdType()
override {
return "event"; }
554 addNewTraceVal<VcdTraceValEvent>(
v,
name);
560 static const int TimeWidth = 64;
565 std::string
vcdType()
override {
return "time"; }
577 char str[TimeWidth + 1];
578 str[TimeWidth] =
'\0';
580 const uint64_t
val = value().value();
581 for (
int i = 0;
i < TimeWidth;
i++)
582 str[
i] = ::
bits(val, TimeWidth -
i - 1) ?
'1' :
'0';
590 addNewTraceVal<VcdTraceValTime>(
v,
name);
593 template <
typename T>
602 const int w = this->
width();
607 static_cast<uint64_t
>(this->value()) & ::
mask(
sizeof(T) * 8);
610 for (
int i = 0;
i <
w;
i++)
613 for (
int i = 0;
i <
w;
i++)
614 str[
i] = ::
bits(val, w -
i - 1) ?
'1' :
'0';
625 addNewTraceVal<VcdTraceValInt<unsigned char>>(
v,
name,
width);
630 addNewTraceVal<VcdTraceValInt<char>>(
v,
name,
width);
636 addNewTraceVal<VcdTraceValInt<unsigned short>>(
v,
name,
width);
641 addNewTraceVal<VcdTraceValInt<short>>(
v,
name,
width);
647 addNewTraceVal<VcdTraceValInt<unsigned int>>(
v,
name,
width);
652 addNewTraceVal<VcdTraceValInt<int>>(
v,
name,
width);
658 addNewTraceVal<VcdTraceValInt<unsigned long>>(
v,
name,
width);
663 addNewTraceVal<VcdTraceValInt<long>>(
v,
name,
width);
670 addNewTraceVal<VcdTraceValInt<sc_dt::int64>>(
v,
name,
width);
676 addNewTraceVal<VcdTraceValInt<sc_dt::uint64>>(
v,
name,
width);
681 const char **literals)
688 while (count >> bits)
691 addNewTraceVal<VcdTraceValInt<unsigned int>>(
v,
name,
bits);
697 stream() <<
"$comment" << std::endl;
698 stream() << comment << std::endl;
699 stream() <<
"$end" << std::endl << std::endl;
void ccprintf(cp::Print &print)
void output(std::ostream &os) override
const std::string & name()
void writeComment(const std::string &comment) override
void addTraceVal(const bool *v, const std::string &name) override
const std::string & vcdName()
void addValue(const std::string &name, VcdTraceValBase *value)
double s
These variables equal the number of ticks in the unit of time they're named after in a double...
std::string nextSignalName()
void trace(bool delta) override
void output(std::ostream &os) override
void vcdName(const std::string &vcd_name)
void output(const std::string &name, std::ostream &os)
static sc_time from_value(sc_dt::uint64)
void output(std::ostream &os) override
std::string csprintf(const char *format, const Args &...args)
const char * sc_version()
char scLogicToVcdState(char in)
std::string vcdType() override
uint64_t Tick
Tick count type.
virtual void output(std::ostream &os)=0
std::string vcdType() override
const char * stripLeadingBits(const char *orig)
void output(std::ostream &os) override
void output(std::ostream &os) override
void output(std::ostream &os) override
VcdTraceVal(const T *t, const std::string &vcd_name, int width)
void printVal(std::ostream &os, const std::string &rep)
#define SC_REPORT_ERROR(msg_type, msg)
void output(std::ostream &os) override
std::string vcdType() override
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
std::string vcdType() override
virtual std::string vcdType()
void output(std::ostream &os) override
void output(std::ostream &os) override
const std::string to_string(sc_enc enc)
VcdTraceValBase(int width)
void output(std::ostream &os) override