2025-01-28 14:49:44 +01:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
|
//=============================================================================
|
|
|
|
|
//
|
|
|
|
|
// Code available from: https://verilator.org
|
|
|
|
|
//
|
|
|
|
|
// Copyright 2001-2025 by Wilson Snyder. This program is free software; you
|
|
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
|
|
|
|
//
|
|
|
|
|
//=============================================================================
|
|
|
|
|
///
|
|
|
|
|
/// \file
|
|
|
|
|
/// \brief Verilated C++ tracing in SAIF format implementation code
|
|
|
|
|
///
|
|
|
|
|
/// This file must be compiled and linked against all Verilated objects
|
|
|
|
|
/// that use --trace.
|
|
|
|
|
///
|
|
|
|
|
/// Use "verilator --trace" to add this to the Makefile for the linker.
|
|
|
|
|
///
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
|
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
#include "verilated.h"
|
|
|
|
|
#include "verilated_saif_c.h"
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cerrno>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
|
|
|
|
|
# include <io.h>
|
|
|
|
|
#else
|
|
|
|
|
# include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef O_LARGEFILE // WIN32 headers omit this
|
|
|
|
|
# define O_LARGEFILE 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef O_NONBLOCK // WIN32 headers omit this
|
|
|
|
|
# define O_NONBLOCK 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef O_CLOEXEC // WIN32 headers omit this
|
|
|
|
|
# define O_CLOEXEC 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Specialization of the generics for this trace format
|
|
|
|
|
|
|
|
|
|
#define VL_SUB_T VerilatedSaif
|
|
|
|
|
#define VL_BUF_T VerilatedSaifBuffer
|
|
|
|
|
#include "verilated_trace_imp.h"
|
|
|
|
|
#undef VL_SUB_T
|
|
|
|
|
#undef VL_BUF_T
|
|
|
|
|
|
2025-02-27 10:21:22 +01:00
|
|
|
//=============================================================================
|
|
|
|
|
//=============================================================================
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// ActivityVar
|
|
|
|
|
|
2025-02-27 12:20:18 +01:00
|
|
|
VL_ATTR_ALWINLINE
|
|
|
|
|
void ActivityVar::emitBit(uint64_t time, CData newval) {
|
|
|
|
|
assert(m_lastTime <= time);
|
|
|
|
|
m_bits[0].aggregateVal(time - m_lastTime, newval);
|
|
|
|
|
updateLastTime(time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VL_ATTR_ALWINLINE
|
|
|
|
|
void ActivityVar::emitWData(uint64_t time, const WData* newvalp, uint32_t bits) {
|
|
|
|
|
assert(m_lastTime <= time);
|
|
|
|
|
uint64_t dt = time - m_lastTime;
|
|
|
|
|
for (std::size_t i = 0; i < std::min(m_width, bits); ++i) {
|
|
|
|
|
size_t wordIndex = i / VL_EDATASIZE;
|
|
|
|
|
m_bits[i].aggregateVal(dt, (newvalp[wordIndex] >> VL_BITBIT_E(i)) & 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateLastTime(time);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
ActivityBit& ActivityVar::getBit(std::size_t index) {
|
2025-02-27 11:31:20 +01:00
|
|
|
assert(index < m_width);
|
2025-02-27 10:21:22 +01:00
|
|
|
return m_bits[index];
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-28 14:49:44 +01:00
|
|
|
//=============================================================================
|
|
|
|
|
//=============================================================================
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// VerilatedSaifFile
|
|
|
|
|
|
|
|
|
|
bool VerilatedSaifFile::open(const std::string& name) VL_MT_UNSAFE {
|
2025-02-27 14:15:04 +01:00
|
|
|
m_fd = ::open(name.c_str(),
|
|
|
|
|
O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE | O_NONBLOCK | O_CLOEXEC, 0666);
|
2025-01-28 14:49:44 +01:00
|
|
|
return m_fd >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaifFile::close() VL_MT_UNSAFE { ::close(m_fd); }
|
|
|
|
|
|
|
|
|
|
ssize_t VerilatedSaifFile::write(const char* bufp, ssize_t len) VL_MT_UNSAFE {
|
|
|
|
|
return ::write(m_fd, bufp, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
//=============================================================================
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Opening/Closing
|
|
|
|
|
|
|
|
|
|
VerilatedSaif::VerilatedSaif(VerilatedSaifFile* filep) {
|
|
|
|
|
// Not in header to avoid link issue if header is included without this .cpp file
|
|
|
|
|
m_fileNewed = (filep == nullptr);
|
|
|
|
|
m_filep = m_fileNewed ? new VerilatedSaifFile : filep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaif::open(const char* filename) VL_MT_SAFE_EXCLUDES(m_mutex) {
|
|
|
|
|
const VerilatedLockGuard lock{m_mutex};
|
|
|
|
|
if (isOpen()) return;
|
|
|
|
|
|
|
|
|
|
// Set member variables
|
|
|
|
|
m_filename = filename; // "" is ok, as someone may overload open
|
|
|
|
|
|
|
|
|
|
openNextImp(m_rolloverSize != 0);
|
|
|
|
|
if (!isOpen()) return;
|
|
|
|
|
|
2025-02-28 10:09:21 +01:00
|
|
|
m_currentTimeOrigin = m_totalTime;
|
2025-02-27 11:31:20 +01:00
|
|
|
initializeSaifFileContents();
|
2025-01-28 14:49:44 +01:00
|
|
|
|
|
|
|
|
Super::traceInit();
|
|
|
|
|
|
|
|
|
|
// When using rollover, the first chunk contains the header only.
|
|
|
|
|
if (m_rolloverSize) openNextImp(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaif::openNext(bool incFilename) VL_MT_SAFE_EXCLUDES(m_mutex) {
|
|
|
|
|
// Open next filename in concat sequence, mangle filename if
|
|
|
|
|
// incFilename is true.
|
|
|
|
|
const VerilatedLockGuard lock{m_mutex};
|
|
|
|
|
openNextImp(incFilename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaif::openNextImp(bool incFilename) {
|
|
|
|
|
closePrev(); // Close existing
|
|
|
|
|
if (incFilename) {
|
|
|
|
|
// Find _0000.{ext} in filename
|
|
|
|
|
std::string name = m_filename;
|
|
|
|
|
const size_t pos = name.rfind('.');
|
|
|
|
|
if (pos > 8 && 0 == std::strncmp("_cat", name.c_str() + pos - 8, 4)
|
|
|
|
|
&& std::isdigit(name.c_str()[pos - 4]) && std::isdigit(name.c_str()[pos - 3])
|
|
|
|
|
&& std::isdigit(name.c_str()[pos - 2]) && std::isdigit(name.c_str()[pos - 1])) {
|
|
|
|
|
// Increment code.
|
|
|
|
|
if ((++(name[pos - 1])) > '9') {
|
|
|
|
|
name[pos - 1] = '0';
|
|
|
|
|
if ((++(name[pos - 2])) > '9') {
|
|
|
|
|
name[pos - 2] = '0';
|
|
|
|
|
if ((++(name[pos - 3])) > '9') {
|
|
|
|
|
name[pos - 3] = '0';
|
|
|
|
|
if ((++(name[pos - 4])) > '9') { //
|
|
|
|
|
name[pos - 4] = '0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Append _cat0000
|
|
|
|
|
name.insert(pos, "_cat0000");
|
|
|
|
|
}
|
|
|
|
|
m_filename = name;
|
|
|
|
|
}
|
|
|
|
|
if (VL_UNCOVERABLE(m_filename[0] == '|')) {
|
|
|
|
|
assert(0); // LCOV_EXCL_LINE // Not supported yet.
|
|
|
|
|
} else {
|
|
|
|
|
// cppcheck-suppress duplicateExpression
|
|
|
|
|
if (!m_filep->open(m_filename)) {
|
|
|
|
|
// User code can check isOpen()
|
|
|
|
|
m_isOpen = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_isOpen = true;
|
|
|
|
|
constDump(true); // First dump must containt the const signals
|
|
|
|
|
fullDump(true); // First dump must be full
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
void VerilatedSaif::initializeSaifFileContents() {
|
2025-03-04 13:26:55 +01:00
|
|
|
printStr("// Generated by verilated_saif\n");
|
2025-02-27 11:31:20 +01:00
|
|
|
printStr("(SAIFILE\n");
|
|
|
|
|
printStr("(SAIFVERSION \"2.0\")\n");
|
|
|
|
|
printStr("(DIRECTION \"backward\")\n");
|
|
|
|
|
printStr("(PROGRAM_NAME \"Verilator\")\n");
|
|
|
|
|
printStr("(DIVIDER / )\n");
|
|
|
|
|
printStr("(TIMESCALE ");
|
2025-02-28 08:50:51 +01:00
|
|
|
printStr(timeResStr());
|
2025-02-27 11:31:20 +01:00
|
|
|
printStr(")\n");
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-28 14:49:44 +01:00
|
|
|
bool VerilatedSaif::preChangeDump() {
|
2025-02-26 11:55:30 +01:00
|
|
|
if (VL_UNLIKELY(m_rolloverSize)) openNextImp(true);
|
2025-01-28 14:49:44 +01:00
|
|
|
return isOpen();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 10:09:21 +01:00
|
|
|
void VerilatedSaif::emitTimeChange(uint64_t timeui) { m_totalTime = timeui; }
|
2025-01-28 14:49:44 +01:00
|
|
|
|
|
|
|
|
VerilatedSaif::~VerilatedSaif() {
|
|
|
|
|
close();
|
|
|
|
|
if (m_filep && m_fileNewed) VL_DO_CLEAR(delete m_filep, m_filep = nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaif::closePrev() {
|
|
|
|
|
// This function is on the flush() call path
|
|
|
|
|
if (!isOpen()) return;
|
|
|
|
|
|
|
|
|
|
Super::flushBase();
|
|
|
|
|
m_isOpen = false;
|
|
|
|
|
m_filep->close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaif::closeErr() {
|
|
|
|
|
// This function is on the flush() call path
|
|
|
|
|
// Close due to an error. We might abort before even getting here,
|
|
|
|
|
// depending on the definition of vl_fatal.
|
|
|
|
|
if (!isOpen()) return;
|
|
|
|
|
|
|
|
|
|
// No buffer flush, just fclose
|
|
|
|
|
m_isOpen = false;
|
|
|
|
|
m_filep->close(); // May get error, just ignore it
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaif::close() VL_MT_SAFE_EXCLUDES(m_mutex) {
|
2025-02-27 11:31:20 +01:00
|
|
|
// This function is on the flush() call path
|
|
|
|
|
const VerilatedLockGuard lock{m_mutex};
|
|
|
|
|
if (!isOpen()) return;
|
|
|
|
|
|
|
|
|
|
finalizeSaifFileContents();
|
|
|
|
|
clearCurrentlyCollectedData();
|
|
|
|
|
|
|
|
|
|
closePrev();
|
|
|
|
|
// closePrev() called Super::flush(), so we just
|
|
|
|
|
// need to shut down the tracing thread here.
|
|
|
|
|
Super::closeBase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaif::finalizeSaifFileContents() {
|
2025-01-28 14:49:44 +01:00
|
|
|
printStr("(DURATION ");
|
2025-02-28 10:09:21 +01:00
|
|
|
printStr(std::to_string(getCurrentTime()));
|
2025-01-28 14:49:44 +01:00
|
|
|
printStr(")\n");
|
2025-02-10 13:15:05 +01:00
|
|
|
|
2025-02-19 13:18:39 +01:00
|
|
|
incrementIndent();
|
2025-02-27 14:15:04 +01:00
|
|
|
for (int32_t topScopeIndex : m_topScopes) { recursivelyPrintScopes(topScopeIndex); }
|
2025-02-19 13:18:39 +01:00
|
|
|
decrementIndent();
|
2025-02-27 14:15:04 +01:00
|
|
|
|
|
|
|
|
printStr(")\n"); // SAIFILE
|
2025-02-19 13:18:39 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-20 08:51:10 +01:00
|
|
|
void VerilatedSaif::recursivelyPrintScopes(uint32_t scopeIndex) {
|
2025-02-27 11:31:20 +01:00
|
|
|
const ActivityScope& scope = m_scopes.at(scopeIndex);
|
|
|
|
|
|
2025-02-28 08:50:51 +01:00
|
|
|
openInstanceScope(scope.getName());
|
2025-02-19 13:18:39 +01:00
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
printScopeActivities(scope);
|
|
|
|
|
|
|
|
|
|
for (uint32_t childScopeIndex : scope.getChildScopesIndices()) {
|
|
|
|
|
recursivelyPrintScopes(childScopeIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeInstanceScope();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 08:50:51 +01:00
|
|
|
void VerilatedSaif::openInstanceScope(const std::string& instanceName) {
|
2025-02-19 13:18:39 +01:00
|
|
|
printIndent();
|
|
|
|
|
printStr("(INSTANCE ");
|
2025-02-27 11:31:20 +01:00
|
|
|
printStr(instanceName);
|
2025-02-19 13:18:39 +01:00
|
|
|
printStr("\n");
|
|
|
|
|
incrementIndent();
|
2025-02-27 11:31:20 +01:00
|
|
|
}
|
2025-02-19 13:18:39 +01:00
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
void VerilatedSaif::closeInstanceScope() {
|
|
|
|
|
decrementIndent();
|
|
|
|
|
printIndent();
|
|
|
|
|
printStr(")\n");
|
|
|
|
|
}
|
2025-02-20 08:51:10 +01:00
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
void VerilatedSaif::printScopeActivities(const ActivityScope& scope) {
|
|
|
|
|
bool anyNetValid{false};
|
|
|
|
|
for (auto& childSignal : scope.getChildActivities()) {
|
2025-02-26 11:27:49 +01:00
|
|
|
uint32_t code = childSignal.first;
|
|
|
|
|
const char* name = childSignal.second.c_str();
|
2025-02-27 11:31:20 +01:00
|
|
|
anyNetValid = printActivityStats(code, name, anyNetValid);
|
|
|
|
|
}
|
2025-02-26 11:27:49 +01:00
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
if (anyNetValid) { closeNetScope(); }
|
2025-02-27 11:31:20 +01:00
|
|
|
}
|
2025-02-27 10:21:22 +01:00
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
void VerilatedSaif::openNetScope() {
|
|
|
|
|
printIndent();
|
|
|
|
|
printStr("(NET\n");
|
|
|
|
|
incrementIndent();
|
|
|
|
|
}
|
2025-02-27 10:21:22 +01:00
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
void VerilatedSaif::closeNetScope() {
|
|
|
|
|
decrementIndent();
|
|
|
|
|
printIndent();
|
|
|
|
|
printStr(")\n");
|
|
|
|
|
}
|
2025-02-27 10:21:22 +01:00
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
bool VerilatedSaif::printActivityStats(uint32_t activityCode, const char* activityName,
|
|
|
|
|
bool anyNetValid) {
|
2025-02-27 11:31:20 +01:00
|
|
|
ActivityVar& activity = m_activity.at(activityCode);
|
|
|
|
|
for (size_t i = 0; i < activity.getWidth(); i++) {
|
|
|
|
|
ActivityBit& bit = activity.getBit(i);
|
2025-02-19 13:18:39 +01:00
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
if (bit.getToggleCount() <= 0) {
|
|
|
|
|
// Skip bits with no toggles
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-02-20 08:51:10 +01:00
|
|
|
|
2025-02-28 10:09:21 +01:00
|
|
|
bit.aggregateVal(getCurrentTime() - activity.getLastUpdateTime(), bit.getBitValue());
|
2025-02-26 11:45:37 +01:00
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
if (!anyNetValid) {
|
|
|
|
|
openNetScope();
|
|
|
|
|
anyNetValid = true;
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
2025-02-27 11:31:20 +01:00
|
|
|
|
2025-02-20 08:51:10 +01:00
|
|
|
printIndent();
|
2025-02-27 11:31:20 +01:00
|
|
|
printStr("(");
|
|
|
|
|
printStr(activityName);
|
|
|
|
|
if (activity.getWidth() > 1) {
|
|
|
|
|
printStr("\\[");
|
2025-02-28 08:50:51 +01:00
|
|
|
printStr(std::to_string(i));
|
2025-02-27 11:31:20 +01:00
|
|
|
printStr("\\]");
|
|
|
|
|
}
|
2025-02-19 13:18:39 +01:00
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
// We only have two-value logic so TZ, TX and TB will always be 0
|
|
|
|
|
printStr(" (T0 ");
|
2025-02-28 10:09:21 +01:00
|
|
|
printStr(std::to_string(getCurrentTime() - bit.getHighTime()));
|
2025-02-27 11:31:20 +01:00
|
|
|
printStr(") (T1 ");
|
2025-02-28 08:50:51 +01:00
|
|
|
printStr(std::to_string(bit.getHighTime()));
|
2025-02-27 11:31:20 +01:00
|
|
|
printStr(") (TZ 0) (TX 0) (TB 0) (TC ");
|
2025-02-28 08:50:51 +01:00
|
|
|
printStr(std::to_string(bit.getToggleCount()));
|
2025-02-27 11:31:20 +01:00
|
|
|
printStr("))\n");
|
2025-02-19 13:18:39 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-28 10:09:21 +01:00
|
|
|
activity.updateLastTime(getCurrentTime());
|
2025-02-27 12:20:18 +01:00
|
|
|
|
2025-02-27 11:31:20 +01:00
|
|
|
return anyNetValid;
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
void VerilatedSaif::clearCurrentlyCollectedData() {
|
2025-02-25 14:20:03 +01:00
|
|
|
m_currentScope = -1;
|
|
|
|
|
m_scopes.clear();
|
|
|
|
|
m_topScopes.clear();
|
|
|
|
|
m_activity.clear();
|
|
|
|
|
m_activityArena.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-28 14:53:11 +01:00
|
|
|
void VerilatedSaif::printStr(const char* str) { m_filep->write(str, strlen(str)); }
|
2025-01-28 14:49:44 +01:00
|
|
|
|
2025-02-28 08:50:51 +01:00
|
|
|
void VerilatedSaif::printStr(const std::string& str) { m_filep->write(str.c_str(), str.size()); }
|
|
|
|
|
|
2025-01-28 14:49:44 +01:00
|
|
|
//=============================================================================
|
|
|
|
|
// Definitions
|
|
|
|
|
|
2025-02-26 11:55:30 +01:00
|
|
|
void VerilatedSaif::flush() VL_MT_SAFE_EXCLUDES(m_mutex) {
|
|
|
|
|
const VerilatedLockGuard lock{m_mutex};
|
|
|
|
|
Super::flushBase();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
void VerilatedSaif::incrementIndent() { m_indent += 1; }
|
2025-02-19 13:18:39 +01:00
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
void VerilatedSaif::decrementIndent() { m_indent -= 1; }
|
2025-02-19 13:18:39 +01:00
|
|
|
|
|
|
|
|
void VerilatedSaif::printIndent() {
|
|
|
|
|
for (int i = 0; i < m_indent; ++i) printStr(" ");
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-28 14:49:44 +01:00
|
|
|
void VerilatedSaif::pushPrefix(const std::string& name, VerilatedTracePrefixType type) {
|
|
|
|
|
std::string pname = name;
|
2025-03-03 15:24:06 +01:00
|
|
|
|
|
|
|
|
if (m_prefixStack.back().second == VerilatedTracePrefixType::ROOTIO_MODULE) popPrefix();
|
2025-03-04 08:26:01 +01:00
|
|
|
if (pname.empty()) {
|
2025-03-03 15:24:06 +01:00
|
|
|
pname = "$rootio";
|
|
|
|
|
type = VerilatedTracePrefixType::ROOTIO_MODULE;
|
|
|
|
|
}
|
2025-02-19 13:18:39 +01:00
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
if (type != VerilatedTracePrefixType::ARRAY_UNPACKED
|
|
|
|
|
&& type != VerilatedTracePrefixType::ARRAY_PACKED) {
|
2025-02-20 15:50:59 +01:00
|
|
|
int32_t newScopeIndex = m_scopes.size();
|
|
|
|
|
if (m_currentScope >= 0) {
|
2025-02-27 10:21:22 +01:00
|
|
|
m_scopes.at(m_currentScope).addChildScopeIndex(newScopeIndex);
|
2025-02-21 11:07:20 +01:00
|
|
|
} else {
|
|
|
|
|
m_topScopes.emplace_back(newScopeIndex);
|
2025-02-20 15:50:59 +01:00
|
|
|
}
|
2025-02-27 10:21:22 +01:00
|
|
|
m_scopes.emplace_back(lastWord(m_prefixStack.back().first + pname), m_currentScope);
|
2025-02-20 15:50:59 +01:00
|
|
|
m_currentScope = newScopeIndex;
|
2025-02-19 13:18:39 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-28 14:49:44 +01:00
|
|
|
std::string newPrefix = m_prefixStack.back().first + pname;
|
2025-02-27 14:15:04 +01:00
|
|
|
if (type != VerilatedTracePrefixType::ARRAY_UNPACKED
|
|
|
|
|
&& type != VerilatedTracePrefixType::ARRAY_PACKED) {
|
2025-01-28 14:49:44 +01:00
|
|
|
newPrefix += ' ';
|
|
|
|
|
}
|
2025-02-27 14:15:04 +01:00
|
|
|
|
2025-01-28 14:49:44 +01:00
|
|
|
m_prefixStack.emplace_back(newPrefix, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaif::popPrefix() {
|
2025-02-27 14:15:04 +01:00
|
|
|
if (m_prefixStack.back().second != VerilatedTracePrefixType::ARRAY_UNPACKED
|
2025-03-03 15:24:06 +01:00
|
|
|
&& m_prefixStack.back().second != VerilatedTracePrefixType::ARRAY_PACKED
|
|
|
|
|
&& m_currentScope >= 0) {
|
2025-02-27 10:21:22 +01:00
|
|
|
m_currentScope = m_scopes.at(m_currentScope).getParentScopeIndex();
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
2025-02-19 13:18:39 +01:00
|
|
|
|
2025-02-20 15:50:59 +01:00
|
|
|
m_prefixStack.pop_back();
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VerilatedSaif::declare(uint32_t code, const char* name, const char* wirep, bool array,
|
2025-01-28 14:53:11 +01:00
|
|
|
int arraynum, bool bussed, int msb, int lsb) {
|
2025-01-28 14:49:44 +01:00
|
|
|
const int bits = ((msb > lsb) ? (msb - lsb) : (lsb - msb)) + 1;
|
|
|
|
|
|
2025-02-19 13:18:39 +01:00
|
|
|
std::string hierarchicalName = m_prefixStack.back().first + name;
|
2025-01-28 14:49:44 +01:00
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
if (!Super::declCode(code, hierarchicalName, bits)) { return; }
|
2025-01-28 14:49:44 +01:00
|
|
|
|
|
|
|
|
const size_t block_size = 1024;
|
2025-02-27 14:15:04 +01:00
|
|
|
if (m_activityArena.empty()
|
|
|
|
|
|| m_activityArena.back().size() + bits > m_activityArena.back().capacity()) {
|
2025-01-28 14:49:44 +01:00
|
|
|
m_activityArena.emplace_back();
|
|
|
|
|
m_activityArena.back().reserve(block_size);
|
|
|
|
|
}
|
|
|
|
|
size_t bitsIdx = m_activityArena.back().size();
|
|
|
|
|
m_activityArena.back().resize(m_activityArena.back().size() + bits);
|
2025-02-07 13:57:24 +01:00
|
|
|
|
2025-02-13 08:37:33 +01:00
|
|
|
std::string finalName = lastWord(hierarchicalName);
|
|
|
|
|
if (array) {
|
|
|
|
|
finalName += '[';
|
|
|
|
|
finalName += std::to_string(arraynum);
|
|
|
|
|
finalName += ']';
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-20 15:48:09 +01:00
|
|
|
assert(m_currentScope >= 0);
|
2025-02-27 10:21:22 +01:00
|
|
|
m_scopes.at(m_currentScope).addActivityVar(code, std::move(finalName));
|
2025-02-20 15:48:09 +01:00
|
|
|
|
2025-02-28 07:58:32 +01:00
|
|
|
m_activity.emplace(
|
|
|
|
|
code, ActivityVar{static_cast<uint32_t>(bits), m_activityArena.back().data() + bitsIdx});
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
void VerilatedSaif::declEvent(uint32_t code, uint32_t fidx, const char* name, int dtypenum,
|
|
|
|
|
VerilatedTraceSigDirection, VerilatedTraceSigKind,
|
|
|
|
|
VerilatedTraceSigType, bool array, int arraynum) {
|
2025-01-28 14:49:44 +01:00
|
|
|
declare(code, name, "event", array, arraynum, false, 0, 0);
|
|
|
|
|
}
|
2025-02-11 15:09:20 +01:00
|
|
|
|
2025-02-27 14:15:04 +01:00
|
|
|
void VerilatedSaif::declBit(uint32_t code, uint32_t fidx, const char* name, int dtypenum,
|
|
|
|
|
VerilatedTraceSigDirection, VerilatedTraceSigKind,
|
|
|
|
|
VerilatedTraceSigType, bool array, int arraynum) {
|
2025-01-28 14:49:44 +01:00
|
|
|
declare(code, name, "wire", array, arraynum, false, 0, 0);
|
|
|
|
|
}
|
2025-02-27 14:15:04 +01:00
|
|
|
void VerilatedSaif::declBus(uint32_t code, uint32_t fidx, const char* name, int dtypenum,
|
|
|
|
|
VerilatedTraceSigDirection, VerilatedTraceSigKind,
|
|
|
|
|
VerilatedTraceSigType, bool array, int arraynum, int msb, int lsb) {
|
2025-01-28 14:49:44 +01:00
|
|
|
declare(code, name, "wire", array, arraynum, true, msb, lsb);
|
|
|
|
|
}
|
2025-02-27 14:15:04 +01:00
|
|
|
void VerilatedSaif::declQuad(uint32_t code, uint32_t fidx, const char* name, int dtypenum,
|
|
|
|
|
VerilatedTraceSigDirection, VerilatedTraceSigKind,
|
|
|
|
|
VerilatedTraceSigType, bool array, int arraynum, int msb, int lsb) {
|
2025-01-28 14:49:44 +01:00
|
|
|
declare(code, name, "wire", array, arraynum, true, msb, lsb);
|
|
|
|
|
}
|
2025-02-27 14:15:04 +01:00
|
|
|
void VerilatedSaif::declArray(uint32_t code, uint32_t fidx, const char* name, int dtypenum,
|
|
|
|
|
VerilatedTraceSigDirection, VerilatedTraceSigKind,
|
|
|
|
|
VerilatedTraceSigType, bool array, int arraynum, int msb, int lsb) {
|
2025-01-28 14:53:11 +01:00
|
|
|
declare(code, name, "wire", array, arraynum, true, msb, lsb);
|
|
|
|
|
}
|
2025-02-27 14:15:04 +01:00
|
|
|
void VerilatedSaif::declDouble(uint32_t code, uint32_t fidx, const char* name, int dtypenum,
|
|
|
|
|
VerilatedTraceSigDirection, VerilatedTraceSigKind,
|
|
|
|
|
VerilatedTraceSigType, bool array, int arraynum) {
|
2025-01-28 14:49:44 +01:00
|
|
|
declare(code, name, "real", array, arraynum, false, 63, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Get/commit trace buffer
|
|
|
|
|
|
2025-01-28 14:53:11 +01:00
|
|
|
VerilatedSaif::Buffer* VerilatedSaif::getTraceBuffer(uint32_t fidx) { return new Buffer{*this}; }
|
2025-01-28 14:49:44 +01:00
|
|
|
|
2025-01-28 14:53:11 +01:00
|
|
|
void VerilatedSaif::commitTraceBuffer(VerilatedSaif::Buffer* bufp) { delete bufp; }
|
2025-01-28 14:49:44 +01:00
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// VerilatedSaifBuffer implementation
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// emit* trace routines
|
|
|
|
|
|
|
|
|
|
// Note: emit* are only ever called from one place (full* in
|
|
|
|
|
// verilated_trace_imp.h, which is included in this file at the top),
|
|
|
|
|
// so always inline them.
|
|
|
|
|
|
|
|
|
|
VL_ATTR_ALWINLINE
|
2025-02-10 13:15:05 +01:00
|
|
|
void VerilatedSaifBuffer::emitEvent(uint32_t code) {
|
2025-02-11 15:09:49 +01:00
|
|
|
// Noop
|
2025-02-10 13:15:05 +01:00
|
|
|
}
|
2025-01-28 14:49:44 +01:00
|
|
|
|
|
|
|
|
VL_ATTR_ALWINLINE
|
|
|
|
|
void VerilatedSaifBuffer::emitBit(uint32_t code, CData newval) {
|
2025-02-11 12:32:48 +01:00
|
|
|
assert(m_owner.m_activity.count(code) && "Activity must be declared earlier");
|
2025-02-26 11:59:24 +01:00
|
|
|
ActivityVar& activity = m_owner.m_activity.at(code);
|
2025-02-28 10:09:21 +01:00
|
|
|
activity.emitBit(m_owner.getCurrentTime(), newval);
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VL_ATTR_ALWINLINE
|
|
|
|
|
void VerilatedSaifBuffer::emitCData(uint32_t code, CData newval, int bits) {
|
2025-02-11 12:32:48 +01:00
|
|
|
assert(m_owner.m_activity.count(code) && "Activity must be declared earlier");
|
2025-02-26 11:59:24 +01:00
|
|
|
ActivityVar& activity = m_owner.m_activity.at(code);
|
2025-02-28 10:09:21 +01:00
|
|
|
activity.emitData<CData>(m_owner.getCurrentTime(), newval, bits);
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VL_ATTR_ALWINLINE
|
|
|
|
|
void VerilatedSaifBuffer::emitSData(uint32_t code, SData newval, int bits) {
|
2025-02-11 12:32:48 +01:00
|
|
|
assert(m_owner.m_activity.count(code) && "Activity must be declared earlier");
|
2025-02-26 11:59:24 +01:00
|
|
|
ActivityVar& activity = m_owner.m_activity.at(code);
|
2025-02-28 10:09:21 +01:00
|
|
|
activity.emitData<SData>(m_owner.getCurrentTime(), newval, bits);
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VL_ATTR_ALWINLINE
|
|
|
|
|
void VerilatedSaifBuffer::emitIData(uint32_t code, IData newval, int bits) {
|
2025-02-11 12:32:48 +01:00
|
|
|
assert(m_owner.m_activity.count(code) && "Activity must be declared earlier");
|
2025-02-26 11:59:24 +01:00
|
|
|
ActivityVar& activity = m_owner.m_activity.at(code);
|
2025-02-28 10:09:21 +01:00
|
|
|
activity.emitData<IData>(m_owner.getCurrentTime(), newval, bits);
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VL_ATTR_ALWINLINE
|
|
|
|
|
void VerilatedSaifBuffer::emitQData(uint32_t code, QData newval, int bits) {
|
2025-02-11 12:32:48 +01:00
|
|
|
assert(m_owner.m_activity.count(code) && "Activity must be declared earlier");
|
2025-02-26 11:59:24 +01:00
|
|
|
ActivityVar& activity = m_owner.m_activity.at(code);
|
2025-02-28 10:09:21 +01:00
|
|
|
activity.emitData<QData>(m_owner.getCurrentTime(), newval, bits);
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VL_ATTR_ALWINLINE
|
|
|
|
|
void VerilatedSaifBuffer::emitWData(uint32_t code, const WData* newvalp, int bits) {
|
2025-02-11 12:32:48 +01:00
|
|
|
assert(m_owner.m_activity.count(code) && "Activity must be declared earlier");
|
2025-02-26 11:59:24 +01:00
|
|
|
ActivityVar& activity = m_owner.m_activity.at(code);
|
2025-02-28 10:09:21 +01:00
|
|
|
activity.emitWData(m_owner.getCurrentTime(), newvalp, bits);
|
2025-01-28 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VL_ATTR_ALWINLINE
|
2025-02-10 13:15:05 +01:00
|
|
|
void VerilatedSaifBuffer::emitDouble(uint32_t code, double newval) {
|
2025-02-11 15:09:49 +01:00
|
|
|
// Noop
|
2025-02-10 13:15:05 +01:00
|
|
|
}
|