Internals: clang-format cleanups. No functional change.

This commit is contained in:
Wilson Snyder 2020-04-04 13:45:24 -04:00
parent a13eab55f5
commit e07e9390f6
10 changed files with 398 additions and 350 deletions

View File

@ -10,22 +10,14 @@ be made to a file. The following files are not yet clang-format clean:
clang-format -i include/verilated.h
clang-format -i include/verilated_dpi.h
clang-format -i include/verilated_fst_c.h
clang-format -i include/verilated_heavy.h
clang-format -i include/verilated_imp.h
clang-format -i include/verilated_save.h
clang-format -i include/verilated_sym_props.h
clang-format -i include/verilated_unordered_set_map.h
clang-format -i include/verilated_vcd_c.h
clang-format -i include/verilatedos.h
clang-format -i include/verilated.cpp
clang-format -i include/verilated_cov.cpp
clang-format -i include/verilated_dpi.cpp
clang-format -i include/verilated_fst_c.cpp
clang-format -i include/verilated_save.cpp
clang-format -i include/verilated_threads.cpp
clang-format -i include/verilated_vcd_c.cpp
clang-format -i include/verilated_vpi.cpp
clang-format -i src/V3Ast.h

View File

@ -106,18 +106,16 @@ void VerilatedFst::open(const char* filename) VL_MT_UNSAFE {
}
}
void VerilatedFst::module(const std::string& name) {
m_module = name;
}
void VerilatedFst::module(const std::string& name) { m_module = name; }
//=============================================================================
// Decl
void VerilatedFst::declDTypeEnum(int dtypenum, const char* name, vluint32_t elements,
unsigned int minValbits,
const char** itemNamesp, const char** itemValuesp) {
fstEnumHandle enumNum = fstWriterCreateEnumTable(m_fst, name, elements,
minValbits, itemNamesp, itemValuesp);
unsigned int minValbits, const char** itemNamesp,
const char** itemValuesp) {
fstEnumHandle enumNum
= fstWriterCreateEnumTable(m_fst, name, elements, minValbits, itemNamesp, itemValuesp);
m_local2fstdtype[dtypenum] = enumNum;
}
@ -143,8 +141,7 @@ void VerilatedFst::declSymbol(vluint32_t code, const char* name, int dtypenum, f
std::list<std::string>::iterator cur_it = m_curScope.begin();
std::list<std::string>::iterator new_it = tokens.begin();
while (cur_it != m_curScope.end() && new_it != tokens.end()) {
if (*cur_it != *new_it)
break;
if (*cur_it != *new_it) break;
++cur_it;
++new_it;
}

View File

@ -43,6 +43,7 @@ class VerilatedFst {
typedef std::map<vluint32_t, fstHandle> Code2SymbolType;
typedef std::map<int, fstEnumHandle> Local2FstDtype;
typedef std::vector<VerilatedFstCallInfo*> CallbackVec;
private:
void* m_fst;
VerilatedAssertOneThread m_assertOne; ///< Assert only called from single thread
@ -61,9 +62,12 @@ private:
bool array, int arraynum, vluint32_t len, vluint32_t bits);
// helpers
std::vector<char> m_valueStrBuffer;
public:
explicit VerilatedFst(void* fst = NULL);
~VerilatedFst() { if (m_fst == NULL) { fstWriterClose(m_fst); } }
~VerilatedFst() {
if (m_fst == NULL) { fstWriterClose(m_fst); }
}
void changeThread() { m_assertOne.changeThread(); }
bool isOpen() const { return m_fst != NULL; }
void open(const char* filename) VL_MT_UNSAFE;
@ -76,7 +80,7 @@ public:
void set_time_unit(const char* unitp) { fstWriterSetTimescaleFromString(m_fst, unitp); }
void set_time_unit(const std::string& unit) { set_time_unit(unit.c_str()); }
void set_time_resolution(const char* unitp) { if (unitp) {} }
void set_time_resolution(const char*) {}
void set_time_resolution(const std::string& unit) { set_time_resolution(unit.c_str()); }
// double timescaleToDouble(const char* unitp);
@ -156,18 +160,18 @@ public:
fstWriterEmitValueChangeVec32(m_fst, m_code2symbol[code], bits, newval);
}
void fullBit(vluint32_t code, const vluint32_t newval) {
chgBit(code, newval); }
void fullBit(vluint32_t code, const vluint32_t newval) { chgBit(code, newval); }
void fullBus(vluint32_t code, const vluint32_t newval, int bits) {
chgBus(code, newval, bits); }
void fullDouble(vluint32_t code, const double newval) {
chgDouble(code, newval); }
void fullFloat(vluint32_t code, const float newval) {
chgFloat(code, newval); }
chgBus(code, newval, bits);
}
void fullDouble(vluint32_t code, const double newval) { chgDouble(code, newval); }
void fullFloat(vluint32_t code, const float newval) { chgFloat(code, newval); }
void fullQuad(vluint32_t code, const vluint64_t newval, int bits) {
chgQuad(code, newval, bits); }
chgQuad(code, newval, bits);
}
void fullArray(vluint32_t code, const vluint32_t* newval, int bits) {
chgArray(code, newval, bits); }
chgArray(code, newval, bits);
}
void declTriBit(vluint32_t code, const char* name, int arraynum);
void declTriBus(vluint32_t code, const char* name, int arraynum, int msb, int lsb);
@ -198,12 +202,14 @@ class VerilatedFstC {
// CONSTRUCTORS
VL_UNCOPYABLE(VerilatedFstC);
public:
explicit VerilatedFstC(void* filep=NULL) : m_sptrace(filep) {}
explicit VerilatedFstC(void* filep = NULL)
: m_sptrace(filep) {}
~VerilatedFstC() { close(); }
/// Routines can only be called from one thread; allow next call from different thread
void changeThread() { spTrace()->changeThread(); }
public:
// ACCESSORS
/// Is file open?
bool isOpen() const { return m_sptrace.isOpen(); }

View File

@ -40,7 +40,8 @@
#endif
// CONSTANTS
static const char* const VLTSAVE_HEADER_STR = "verilatorsave01\n"; ///< Value of first bytes of each file
static const char* const VLTSAVE_HEADER_STR
= "verilatorsave01\n"; ///< Value of first bytes of each file
static const char* const VLTSAVE_TRAILER_STR = "vltsaved"; ///< Value of last bytes of each file
//=============================================================================
@ -48,7 +49,8 @@ static const char* const VLTSAVE_TRAILER_STR = "vltsaved"; ///< Value of last b
//=============================================================================
// Searalization
bool VerilatedDeserialize::readDiffers(const void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE {
bool VerilatedDeserialize::readDiffers(const void* __restrict datap,
size_t size) VL_MT_UNSAFE_ONE {
bufferCheck();
const vluint8_t* __restrict dp = static_cast<const vluint8_t* __restrict>(datap);
vluint8_t miss = 0;
@ -62,8 +64,8 @@ VerilatedDeserialize& VerilatedDeserialize::readAssert(const void* __restrict da
size_t size) VL_MT_UNSAFE_ONE {
if (VL_UNLIKELY(readDiffers(datap, size))) {
std::string fn = filename();
std::string msg = "Can't deserialize save-restore file as was made from different model:"
+filename();
std::string msg
= "Can't deserialize save-restore file as was made from different model:" + filename();
VL_FATAL_MT(fn.c_str(), 0, "", msg.c_str());
close();
}
@ -84,8 +86,8 @@ void VerilatedDeserialize::header() VL_MT_UNSAFE_ONE {
VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below
if (VL_UNLIKELY(os.readDiffers(VLTSAVE_HEADER_STR, strlen(VLTSAVE_HEADER_STR)))) {
std::string fn = filename();
std::string msg = std::string("Can't deserialize; file has wrong header signature: ")
+filename();
std::string msg
= std::string("Can't deserialize; file has wrong header signature: ") + filename();
VL_FATAL_MT(fn.c_str(), 0, "", msg.c_str());
close();
}
@ -123,8 +125,8 @@ void VerilatedSave::open(const char* filenamep) VL_MT_UNSAFE_ONE {
assert(0); // Not supported yet.
} else {
// cppcheck-suppress duplicateExpression
m_fd = ::open(filenamep, O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK|O_CLOEXEC
, 0666);
m_fd = ::open(filenamep,
O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE | O_NONBLOCK | O_CLOEXEC, 0666);
if (m_fd < 0) {
// User code can check isOpen()
m_isOpen = false;
@ -146,8 +148,7 @@ void VerilatedRestore::open(const char* filenamep) VL_MT_UNSAFE_ONE {
assert(0); // Not supported yet.
} else {
// cppcheck-suppress duplicateExpression
m_fd = ::open(filenamep, O_CREAT|O_RDONLY|O_LARGEFILE|O_CLOEXEC
, 0666);
m_fd = ::open(filenamep, O_CREAT | O_RDONLY | O_LARGEFILE | O_CLOEXEC, 0666);
if (m_fd < 0) {
// User code can check isOpen()
m_isOpen = false;
@ -209,7 +210,7 @@ void VerilatedRestore::fill() VL_MT_UNSAFE_ONE {
if (VL_UNLIKELY(!isOpen())) return;
// Move remaining characters down to start of buffer. (No memcpy, overlaps allowed)
vluint8_t* rp = m_bufp;
for (vluint8_t* sp=m_cp; sp < m_endp;) *rp++ = *sp++; // Overlaps
for (vluint8_t* sp = m_cp; sp < m_endp; *rp++ = *sp++) {} // Overlaps
m_endp = m_bufp + (m_endp - m_cp);
m_cp = m_bufp; // Reset buffer
// Read into buffer starting at m_endp
@ -231,7 +232,9 @@ void VerilatedRestore::fill() VL_MT_UNSAFE_ONE {
} else { // got==0, EOF
// Fill buffer from here to end with NULLs so reader's don't
// need to check eof each character.
while (m_endp < m_bufp+bufferSize()) *m_endp++ = '\0';
while (m_endp < m_bufp + bufferSize()) {
*m_endp++ = '\0';
}
break;
}
}

View File

@ -46,6 +46,7 @@ protected:
// CONSTRUCTORS
VL_UNCOPYABLE(VerilatedSerialize);
public:
VerilatedSerialize() {
m_isOpen = false;
@ -65,20 +66,20 @@ public:
const vluint8_t* __restrict dp = (const vluint8_t* __restrict)datap;
while (size) {
bufferCheck();
size_t blk = size; if (blk>bufferInsertSize()) blk = bufferInsertSize();
size_t blk = size;
if (blk > bufferInsertSize()) blk = bufferInsertSize();
const vluint8_t* __restrict maxp = dp + blk;
while (dp < maxp) *m_cp++ = *dp++;
for (; dp < maxp; *m_cp++ = *dp++) {}
size -= blk;
}
return *this; // For function chaining
}
private:
VerilatedSerialize& bufferCheck() VL_MT_UNSAFE_ONE {
// Flush the write buffer if there's not enough space left for new information
// We only call this once per vector, so we need enough slop for a very wide "b###" line
if (VL_UNLIKELY(m_cp > (m_bufp+(bufferSize()-bufferInsertSize())))) {
flush();
}
if (VL_UNLIKELY(m_cp > (m_bufp + (bufferSize() - bufferInsertSize())))) flush();
return *this; // For function chaining
}
};
@ -125,12 +126,13 @@ public:
virtual void close() VL_MT_UNSAFE_ONE { flush(); }
virtual void flush() VL_MT_UNSAFE_ONE {}
inline VerilatedDeserialize& read(void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE {
vluint8_t* __restrict dp = (vluint8_t* __restrict)datap;
vluint8_t* __restrict dp = static_cast<vluint8_t* __restrict>(datap);
while (size) {
bufferCheck();
size_t blk = size; if (blk>bufferInsertSize()) blk = bufferInsertSize();
size_t blk = size;
if (blk > bufferInsertSize()) blk = bufferInsertSize();
const vluint8_t* __restrict maxp = dp + blk;
while (dp < maxp) *dp++ = *m_cp++;
for (; dp < maxp; *dp++ = *m_cp++);
size -= blk;
}
return *this; // For function chaining
@ -138,15 +140,15 @@ public:
// Read a datum and compare with expected value
VerilatedDeserialize& readAssert(const void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE;
VerilatedDeserialize& readAssert(vluint64_t data) VL_MT_UNSAFE_ONE {
return readAssert(&data, sizeof(data)); }
return readAssert(&data, sizeof(data));
}
private:
bool readDiffers(const void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE;
VerilatedDeserialize& bufferCheck() VL_MT_UNSAFE_ONE {
// Flush the write buffer if there's not enough space left for new information
// We only call this once per vector, so we need enough slop for a very wide "b###" line
if (VL_UNLIKELY((m_cp+bufferInsertSize()) > m_endp)) {
fill();
}
if (VL_UNLIKELY((m_cp + bufferInsertSize()) > m_endp)) fill();
return *this; // For function chaining
}
};
@ -187,7 +189,8 @@ public:
virtual ~VerilatedRestore() VL_OVERRIDE { close(); }
// METHODS
void open(const char* filenamep) VL_MT_UNSAFE_ONE; ///< Open the file; call isOpen() to see if errors
/// Open the file; call isOpen() to see if errors
void open(const char* filenamep) VL_MT_UNSAFE_ONE;
void open(const std::string& filename) VL_MT_UNSAFE_ONE { open(filename.c_str()); }
virtual void close() VL_OVERRIDE VL_MT_UNSAFE_ONE;
virtual void flush() VL_OVERRIDE VL_MT_UNSAFE_ONE {}

View File

@ -37,12 +37,17 @@
class VerilatedRange {
int m_left;
int m_right;
protected:
friend class VerilatedVarProps;
friend class VerilatedScope;
VerilatedRange() : m_left(0), m_right(0) {}
VerilatedRange(int left, int right) : m_left(left), m_right(right) {}
void init(int left, int right) { m_left=left; m_right=right; }
void init(int left, int right) {
m_left = left;
m_right = right;
}
public:
~VerilatedRange() {}
int left() const { return m_left; }
@ -50,7 +55,8 @@ public:
int low() const { return (m_left < m_right) ? m_left : m_right; }
int high() const { return (m_left > m_right) ? m_left : m_right; }
int elements() const {
return (VL_LIKELY(m_left>=m_right) ? (m_left-m_right+1) : (m_right-m_left+1)); }
return (VL_LIKELY(m_left >= m_right) ? (m_left - m_right + 1) : (m_right - m_left + 1));
}
int increment() const { return (m_left >= m_right) ? 1 : -1; }
};
@ -75,6 +81,7 @@ protected:
VerilatedVarProps(VerilatedVarType vltype, VerilatedVarFlags vlflags,
int pdims, int udims)
: m_magic(MAGIC), m_vltype(vltype), m_vlflags(vlflags), m_pdims(pdims), m_udims(udims) {}
public:
class Unpacked {};
// Without packed
@ -85,17 +92,23 @@ public:
Unpacked, int u0l, int u0r)
: m_magic(MAGIC), m_vltype(vltype),
m_vlflags(VerilatedVarFlags(vlflags)), m_pdims(0), m_udims(1) {
m_unpacked[0].init(u0l, u0r); }
m_unpacked[0].init(u0l, u0r);
}
VerilatedVarProps(VerilatedVarType vltype, int vlflags,
Unpacked, int u0l, int u0r, int u1l, int u1r)
: m_magic(MAGIC), m_vltype(vltype),
m_vlflags(VerilatedVarFlags(vlflags)), m_pdims(0), m_udims(2) {
m_unpacked[0].init(u0l, u0r); m_unpacked[1].init(u1l, u1r); }
m_unpacked[0].init(u0l, u0r);
m_unpacked[1].init(u1l, u1r);
}
VerilatedVarProps(VerilatedVarType vltype, int vlflags,
Unpacked, int u0l, int u0r, int u1l, int u1r, int u2l, int u2r)
: m_magic(MAGIC), m_vltype(vltype),
m_vlflags(VerilatedVarFlags(vlflags)), m_pdims(0), m_udims(3) {
m_unpacked[0].init(u0l, u0r); m_unpacked[1].init(u1l, u1r); m_unpacked[2].init(u2l, u2r); }
m_unpacked[0].init(u0l, u0r);
m_unpacked[1].init(u1l, u1r);
m_unpacked[2].init(u2l, u2r);
}
// With packed
class Packed {};
VerilatedVarProps(VerilatedVarType vltype, int vlflags,
@ -107,26 +120,34 @@ public:
Unpacked, int u0l, int u0r)
: m_magic(MAGIC), m_vltype(vltype),
m_vlflags(VerilatedVarFlags(vlflags)), m_pdims(1), m_udims(1), m_packed(pl,pr) {
m_unpacked[0].init(u0l, u0r); }
m_unpacked[0].init(u0l, u0r);
}
VerilatedVarProps(VerilatedVarType vltype, int vlflags,
Packed, int pl, int pr,
Unpacked, int u0l, int u0r, int u1l, int u1r)
: m_magic(MAGIC), m_vltype(vltype), m_vlflags(VerilatedVarFlags(vlflags)),
m_pdims(1), m_udims(2), m_packed(pl,pr) {
m_unpacked[0].init(u0l, u0r); m_unpacked[1].init(u1l, u1r); }
m_unpacked[0].init(u0l, u0r);
m_unpacked[1].init(u1l, u1r);
}
VerilatedVarProps(VerilatedVarType vltype, int vlflags,
Packed, int pl, int pr,
Unpacked, int u0l, int u0r, int u1l, int u1r, int u2l, int u2r)
: m_magic(MAGIC), m_vltype(vltype),
m_vlflags(VerilatedVarFlags(vlflags)), m_pdims(1), m_udims(3), m_packed(pl,pr) {
m_unpacked[0].init(u0l, u0r); m_unpacked[1].init(u1l, u1r); m_unpacked[2].init(u2l, u2r); }
m_unpacked[0].init(u0l, u0r);
m_unpacked[1].init(u1l, u1r);
m_unpacked[2].init(u2l, u2r);
}
public:
~VerilatedVarProps() {}
// METHODS
bool magicOk() const { return m_magic == MAGIC; }
VerilatedVarType vltype() const { return m_vltype; }
VerilatedVarFlags vldir() const {
return static_cast<VerilatedVarFlags>(static_cast<int>(m_vlflags) & VLVF_MASK_DIR); }
return static_cast<VerilatedVarFlags>(static_cast<int>(m_vlflags) & VLVF_MASK_DIR);
}
vluint32_t entSize() const;
bool isPublicRW() const { return ((m_vlflags & VLVF_PUB_RW) != 0); }
/// DPI compatible C standard layout
@ -199,7 +220,8 @@ public:
int elements(int dim) const { return m_propsp->elements(dim); }
size_t totalSize() const { return m_propsp->totalSize(); }
void* datapAdjustIndex(void* datap, int dim, int indx) const {
return m_propsp->datapAdjustIndex(datap, dim, indx); }
return m_propsp->datapAdjustIndex(datap, dim, indx);
}
};
//===========================================================================
@ -213,10 +235,12 @@ class VerilatedVar : public VerilatedVarProps {
protected:
friend class VerilatedScope;
// CONSTRUCTORS
VerilatedVar(const char* namep, void* datap,
VerilatedVarType vltype, VerilatedVarFlags vlflags, int dims)
VerilatedVar(const char* namep, void* datap, VerilatedVarType vltype,
VerilatedVarFlags vlflags, int dims)
: VerilatedVarProps(vltype, vlflags, (dims > 0 ? 1 : 0), ((dims > 1) ? dims - 1 : 0))
, m_datap(datap), m_namep(namep) {}
, m_datap(datap)
, m_namep(namep) {}
public:
~VerilatedVar() {}
// ACCESSORS

View File

@ -27,8 +27,8 @@ VL_THREAD_LOCAL VlThreadPool::ProfileTrace* VlThreadPool::t_profilep = NULL;
// VlMTaskVertex
VlMTaskVertex::VlMTaskVertex(vluint32_t upstreamDepCount)
: m_upstreamDepsDone(0),
m_upstreamDepCount(upstreamDepCount) {
: m_upstreamDepsDone(0)
, m_upstreamDepCount(upstreamDepCount) {
assert(atomic_is_lock_free(&m_upstreamDepsDone));
}
@ -52,17 +52,13 @@ VlWorkerThread::~VlWorkerThread() {
}
void VlWorkerThread::workerLoop() {
if (VL_UNLIKELY(m_profiling)) {
m_poolp->setupProfilingClientThread();
}
if (VL_UNLIKELY(m_profiling)) m_poolp->setupProfilingClientThread();
ExecRec work;
work.m_fnp = NULL;
while (true) {
if (VL_LIKELY(!work.m_fnp)) {
dequeWork(&work);
}
if (VL_LIKELY(!work.m_fnp)) dequeWork(&work);
// Do this here, not above, to avoid a race with the destructor.
if (VL_UNLIKELY(m_exiting.load(std::memory_order_acquire)))
@ -74,14 +70,10 @@ void VlWorkerThread::workerLoop() {
}
}
if (VL_UNLIKELY(m_profiling)) {
m_poolp->tearDownProfilingClientThread();
}
if (VL_UNLIKELY(m_profiling)) m_poolp->tearDownProfilingClientThread();
}
void VlWorkerThread::startWorker(VlWorkerThread* workerp) {
workerp->workerLoop();
}
void VlWorkerThread::startWorker(VlWorkerThread* workerp) { workerp->workerLoop(); }
//=============================================================================
// VlThreadPool
@ -94,7 +86,8 @@ VlThreadPool::VlThreadPool(int nThreads, bool profiling)
static int warnedOnce = 0;
if (!warnedOnce++) {
VL_PRINTF_MT("%%Warning: System has %u CPUs but model Verilated with"
" --threads %d; may run slow.\n", cpus, nThreads+1);
" --threads %d; may run slow.\n",
cpus, nThreads + 1);
}
}
// Create'em
@ -104,9 +97,7 @@ VlThreadPool::VlThreadPool(int nThreads, bool profiling)
// Set up a profile buffer for the current thread too -- on the
// assumption that it's the same thread that calls eval and may be
// donated to run mtasks during the eval.
if (VL_UNLIKELY(m_profiling)) {
setupProfilingClientThread();
}
if (VL_UNLIKELY(m_profiling)) setupProfilingClientThread();
}
VlThreadPool::~VlThreadPool() {
@ -114,9 +105,7 @@ VlThreadPool::~VlThreadPool() {
// Each ~WorkerThread will wait for its thread to exit.
delete m_workers[i];
}
if (VL_UNLIKELY(m_profiling)) {
tearDownProfilingClientThread();
}
if (VL_UNLIKELY(m_profiling)) tearDownProfilingClientThread();
}
void VlThreadPool::tearDownProfilingClientThread() {
@ -159,14 +148,11 @@ void VlThreadPool::profileDump(const char* filenamep, vluint64_t ticksElapsed) {
// TODO Perhaps merge with verilated_coverage output format, so can
// have a common merging and reporting tool, etc.
fprintf(fp, "VLPROFTHREAD 1.0 # Verilator thread profile dump version 1.0\n");
fprintf(fp, "VLPROF arg --threads %" VL_PRI64 "u\n",
vluint64_t(m_workers.size()+1));
fprintf(fp, "VLPROF arg --threads %" VL_PRI64 "u\n", vluint64_t(m_workers.size() + 1));
fprintf(fp, "VLPROF arg +verilator+prof+threads+start+%" VL_PRI64 "u\n",
Verilated::profThreadsStart());
fprintf(fp, "VLPROF arg +verilator+prof+threads+window+%u\n",
Verilated::profThreadsWindow());
fprintf(fp, "VLPROF stat yields %" VL_PRI64 "u\n",
VlMTaskVertex::yields());
fprintf(fp, "VLPROF arg +verilator+prof+threads+window+%u\n", Verilated::profThreadsWindow());
fprintf(fp, "VLPROF stat yields %" VL_PRI64 "u\n", VlMTaskVertex::yields());
vluint32_t thread_id = 0;
for (ProfileSet::const_iterator pit = m_allProfiles.begin();
@ -174,31 +160,26 @@ void VlThreadPool::profileDump(const char* filenamep, vluint64_t ticksElapsed) {
++thread_id;
bool printing = false; // False while in warmup phase
for (ProfileTrace::const_iterator eit = (*pit)->begin();
eit != (*pit)->end(); ++eit) {
for (ProfileTrace::const_iterator eit = (*pit)->begin(); eit != (*pit)->end(); ++eit) {
switch (eit->m_type) {
case VlProfileRec::TYPE_BARRIER:
printing = true;
break;
case VlProfileRec::TYPE_MTASK_RUN:
if (!printing) break;
fprintf(fp, "VLPROF mtask %d"
fprintf(fp,
"VLPROF mtask %d"
" start %" VL_PRI64 "u end %" VL_PRI64 "u elapsed %" VL_PRI64 "u"
" predict_time %u cpu %u on thread %u\n",
eit->m_mtaskId,
eit->m_startTime,
eit->m_endTime,
(eit->m_endTime - eit->m_startTime),
eit->m_predictTime,
eit->m_cpu,
eit->m_mtaskId, eit->m_startTime, eit->m_endTime,
(eit->m_endTime - eit->m_startTime), eit->m_predictTime, eit->m_cpu,
thread_id);
break;
default: assert(false); break; // LCOV_EXCL_LINE
}
}
}
fprintf(fp, "VLPROF stat ticks %" VL_PRI64 "u\n",
ticksElapsed);
fprintf(fp, "VLPROF stat ticks %" VL_PRI64 "u\n", ticksElapsed);
fclose(fp);
}

View File

@ -284,6 +284,7 @@ public:
// this once to setup profiling state:
void setupProfilingClientThread();
void tearDownProfilingClientThread();
private:
VL_UNCOPYABLE(VlThreadPool);
};

View File

@ -58,6 +58,7 @@ private:
VcdVec s_vcdVecp VL_GUARDED_BY(s_vcdMutex); ///< List of all created traces
};
static Singleton& singleton() { static Singleton s; return s; }
public:
static void pushVcd(VerilatedVcd* vcdp) VL_EXCLUDES(singleton().s_vcdMutex) {
VerilatedLockGuard lock(singleton().s_vcdMutex);
@ -65,8 +66,8 @@ public:
}
static void removeVcd(const VerilatedVcd* vcdp) VL_EXCLUDES(singleton().s_vcdMutex) {
VerilatedLockGuard lock(singleton().s_vcdMutex);
VcdVec::iterator pos = find(singleton().s_vcdVecp.begin(),
singleton().s_vcdVecp.end(), vcdp);
VcdVec::iterator pos
= find(singleton().s_vcdVecp.begin(), singleton().s_vcdVecp.end(), vcdp);
if (pos != singleton().s_vcdVecp.end()) { singleton().s_vcdVecp.erase(pos); }
}
static void flush_all() VL_EXCLUDES(singleton().s_vcdMutex) VL_MT_UNSAFE_ONE {
@ -115,13 +116,12 @@ protected:
// VerilatedVcdFile
bool VerilatedVcdFile::open(const std::string& name) VL_MT_UNSAFE {
m_fd = ::open(name.c_str(), O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK|O_CLOEXEC, 0666);
m_fd = ::open(name.c_str(),
O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE | O_NONBLOCK | O_CLOEXEC, 0666);
return m_fd >= 0;
}
void VerilatedVcdFile::close() VL_MT_UNSAFE {
::close(m_fd);
}
void VerilatedVcdFile::close() VL_MT_UNSAFE { ::close(m_fd); }
ssize_t VerilatedVcdFile::write(const char* bufp, ssize_t len) VL_MT_UNSAFE {
return ::write(m_fd, bufp, len);
@ -173,9 +173,7 @@ void VerilatedVcd::open(const char* filename) {
dumpHeader();
// Allocate space now we know the number of codes
if (!m_sigs_oldvalp) {
m_sigs_oldvalp = new vluint32_t [m_nextCode+10];
}
if (!m_sigs_oldvalp) m_sigs_oldvalp = new vluint32_t[m_nextCode + 10];
if (m_rolloverMB) {
openNext(true);
@ -204,9 +202,10 @@ void VerilatedVcd::openNext(bool incFilename) {
name[pos - 2] = '0';
if ((++(name[pos - 3])) > '9') {
name[pos - 3] = '0';
if ((++(name[pos-4])) > '9') {
name[pos-4] = '0';
}}}}
if ((++(name[pos - 4])) > '9') { name[pos - 4] = '0'; }
}
}
}
} else {
// Append _cat0000
name.insert(pos, "_cat0000");
@ -407,7 +406,7 @@ double VerilatedVcd::timescaleToDouble(const char* unitp) {
double value = strtod(unitp, &endp);
if (value == 0.0 && endp == unitp) value = 1; // On error so we allow just "ns" to return 1e-9.
unitp = endp;
while (*unitp && isspace(*unitp)) unitp++;
for (; *unitp && isspace(*unitp); unitp++) {}
switch (*unitp) {
case 's': value *= 1e1; break;
case 'm': value *= 1e-3; break;
@ -429,7 +428,8 @@ std::string VerilatedVcd::doubleToTimescale(double value) {
else if (value>=1e-12) { suffixp="ps"; value *= 1e12; }
else if (value>=1e-15) { suffixp="fs"; value *= 1e15; }
else if (value>=1e-18) { suffixp="as"; value *= 1e18; }
char valuestr[100]; sprintf(valuestr,"%3.0f%s", value, suffixp);
char valuestr[100];
sprintf(valuestr, "%3.0f%s", value, suffixp);
return valuestr; // Gets converted to string, so no ref to stack
}
@ -439,14 +439,18 @@ std::string VerilatedVcd::doubleToTimescale(double value) {
void VerilatedVcd::printIndent(int level_change) {
if (level_change < 0) m_modDepth += level_change;
assert(m_modDepth >= 0);
for (int i=0; i<m_modDepth; i++) printStr(" ");
for (int i = 0; i < m_modDepth; i++) {
printStr(" ");
}
if (level_change > 0) m_modDepth += level_change;
}
void VerilatedVcd::dumpHeader() {
printStr("$version Generated by VerilatedVcd $end\n");
time_t time_str = time(NULL);
printStr("$date "); printStr(ctime(&time_str)); printStr(" $end\n");
printStr("$date ");
printStr(ctime(&time_str));
printStr(" $end\n");
printStr("$timescale ");
const std::string& timeResStr = doubleToTimescale(m_timeRes);
@ -479,7 +483,10 @@ void VerilatedVcd::dumpHeader() {
// Skip common prefix, it must break at a space or tab
for (; *np && (*np == *lp); np++, lp++) {}
while (np!=hiername && *np && *np!=' ' && *np!='\t') { np--; lp--; }
while (np != hiername && *np && *np != ' ' && *np != '\t') {
np--;
lp--;
}
// printf("hier %s\n lp=%s\n np=%s\n",hiername,lp,np);
// Any extra spaces in last name are scope ups we need to do
@ -499,9 +506,13 @@ void VerilatedVcd::dumpHeader() {
printIndent(1);
printStr("$scope module ");
for (; *np && *np != ' ' && *np != '\t'; np++) {
if (*np=='[') printStr("(");
else if (*np==']') printStr(")");
else *m_writep++=*np;
if (*np == '[') {
printStr("(");
} else if (*np == ']') {
printStr(")");
} else {
*m_writep++ = *np;
}
}
printStr(" $end\n");
}
@ -530,8 +541,9 @@ void VerilatedVcd::module(const std::string& name) {
void VerilatedVcd::declare(vluint32_t code, const char* name, const char* wirep,
bool array, int arraynum, bool tri, bool bussed, int msb, int lsb) {
if (!code) { VL_FATAL_MT(__FILE__, __LINE__, "",
"Internal: internal trace problem, code 0 is illegal"); }
if (!code) {
VL_FATAL_MT(__FILE__, __LINE__, "", "Internal: internal trace problem, code 0 is illegal");
}
int bits = ((msb > lsb) ? (msb - lsb) : (lsb - msb)) + 1;
int codesNeeded = 1 + int(bits / 32);
@ -576,7 +588,12 @@ void VerilatedVcd::declare(vluint32_t code, const char* name, const char* wirep,
// Print reference
std::string decl = "$var ";
if (m_evcd) decl += "port"; else decl += wirep; // usually "wire"
if (m_evcd) {
decl += "port";
} else {
decl += wirep; // usually "wire"
}
char buf[1000];
sprintf(buf, " %2d ", bits);
decl += buf;
@ -646,7 +663,9 @@ void VerilatedVcd::fullDouble(vluint32_t code, const double newval) {
// Buffer can't overflow before sprintf; we sized during declaration
sprintf(m_writep, "r%.16g", newval);
m_writep += strlen(m_writep);
*m_writep++=' '; printCode(code); *m_writep++='\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void VerilatedVcd::fullFloat(vluint32_t code, const float newval) {
@ -655,7 +674,9 @@ void VerilatedVcd::fullFloat(vluint32_t code, const float newval) {
// Buffer can't overflow before sprintf; we sized during declaration
sprintf(m_writep, "r%.16g", static_cast<double>(newval));
m_writep += strlen(m_writep);
*m_writep++=' '; printCode(code); *m_writep++='\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
@ -716,9 +737,7 @@ void VerilatedVcd::dumpPrep(vluint64_t timeui) {
//======================================================================
// Static members
void VerilatedVcd::flush_all() VL_MT_UNSAFE_ONE {
VerilatedVcdSingleton::flush_all();
}
void VerilatedVcd::flush_all() VL_MT_UNSAFE_ONE { VerilatedVcdSingleton::flush_all(); }
//======================================================================
//======================================================================

View File

@ -60,6 +60,7 @@ protected:
VerilatedVcdSig(vluint32_t code, int bits)
: m_code(code)
, m_bits(bits) {}
public:
~VerilatedVcdSig() {}
};
@ -153,6 +154,7 @@ private:
// CONSTRUCTORS
VL_UNCOPYABLE(VerilatedVcd);
public:
explicit VerilatedVcd(VerilatedVcdFile* filep = NULL);
~VerilatedVcd();
@ -170,7 +172,8 @@ public:
inline bool isScopeEscape(char c) { return isspace(c) || c == m_scopeEscape; }
// METHODS
void open(const char* filename) VL_MT_UNSAFE_ONE; ///< Open the file; call isOpen() to see if errors
/// Open the file; call isOpen() to see if errors
void open(const char* filename) VL_MT_UNSAFE_ONE;
void openNext(bool incFilename); ///< Open next data-only file
void close() VL_MT_UNSAFE_ONE; ///< Close the file
/// Flush any remaining data to this file
@ -194,8 +197,7 @@ public:
/// Inside dumping routines, declare callbacks for tracings
void addCallback(VerilatedVcdCallback_t initcb, VerilatedVcdCallback_t fullcb,
VerilatedVcdCallback_t changecb,
void* userthis) VL_MT_UNSAFE_ONE;
VerilatedVcdCallback_t changecb, void* userthis) VL_MT_UNSAFE_ONE;
/// Inside dumping routines, declare a module
void module(const std::string& name);
@ -206,8 +208,10 @@ public:
void declArray(vluint32_t code, const char* name, bool array, int arraynum, int msb, int lsb);
void declTriBit(vluint32_t code, const char* name, bool array, int arraynum);
void declTriBus(vluint32_t code, const char* name, bool array, int arraynum, int msb, int lsb);
void declTriQuad( vluint32_t code, const char* name, bool array, int arraynum, int msb, int lsb);
void declTriArray(vluint32_t code, const char* name, bool array, int arraynum, int msb, int lsb);
void declTriQuad(vluint32_t code, const char* name, bool array, int arraynum, int msb,
int lsb);
void declTriArray(vluint32_t code, const char* name, bool array, int arraynum, int msb,
int lsb);
void declDouble(vluint32_t code, const char* name, bool array, int arraynum);
void declFloat(vluint32_t code, const char* name, bool array, int arraynum);
// ... other module_start for submodules (based on cell name)
@ -216,7 +220,9 @@ public:
void fullBit(vluint32_t code, const vluint32_t newval) {
// Note the &1, so we don't require clean input -- makes more common no change case faster
m_sigs_oldvalp[code] = newval;
*m_writep++=('0'+static_cast<char>(newval&1)); printCode(code); *m_writep++='\n';
*m_writep++ = ('0' + static_cast<char>(newval & 1));
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void fullBus(vluint32_t code, const vluint32_t newval, int bits) {
@ -225,7 +231,9 @@ public:
for (int bit = bits - 1; bit >= 0; --bit) {
*m_writep++ = ((newval & (1L << bit)) ? '1' : '0');
}
*m_writep++=' '; printCode(code); *m_writep++='\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void fullQuad(vluint32_t code, const vluint64_t newval, int bits) {
@ -234,7 +242,9 @@ public:
for (int bit = bits - 1; bit >= 0; --bit) {
*m_writep++ = ((newval & (VL_ULL(1) << bit)) ? '1' : '0');
}
*m_writep++=' '; printCode(code); *m_writep++='\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void fullArray(vluint32_t code, const vluint32_t* newval, int bits) {
@ -245,7 +255,9 @@ public:
for (int bit = bits - 1; bit >= 0; --bit) {
*m_writep++ = ((newval[(bit / 32)] & (1L << (bit & 0x1f))) ? '1' : '0');
}
*m_writep ++= ' '; printCode(code); *m_writep ++= '\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void fullArray(vluint32_t code, const vluint64_t* newval, int bits) {
@ -256,15 +268,17 @@ public:
for (int bit = bits - 1; bit >= 0; --bit) {
*m_writep++ = ((newval[(bit / 64)] & (VL_ULL(1) << (bit & 0x3f))) ? '1' : '0');
}
*m_writep ++= ' '; printCode(code); *m_writep ++= '\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void fullTriBit(vluint32_t code, const vluint32_t newval, const vluint32_t newtri) {
m_sigs_oldvalp[code] = newval;
m_sigs_oldvalp[code + 1] = newtri;
*m_writep++ = "01zz"[m_sigs_oldvalp[code]
| (m_sigs_oldvalp[code+1]<<1)];
printCode(code); *m_writep++='\n';
*m_writep++ = "01zz"[m_sigs_oldvalp[code] | (m_sigs_oldvalp[code + 1] << 1)];
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void fullTriBus(vluint32_t code, const vluint32_t newval, const vluint32_t newtri, int bits) {
@ -272,14 +286,14 @@ public:
m_sigs_oldvalp[code + 1] = newtri;
*m_writep++ = 'b';
for (int bit = bits - 1; bit >= 0; --bit) {
*m_writep++ = "01zz"[((newval >> bit)&1)
| (((newtri >> bit)&1)<<1)];
*m_writep++ = "01zz"[((newval >> bit) & 1) | (((newtri >> bit) & 1) << 1)];
}
*m_writep++=' '; printCode(code); *m_writep++='\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void fullTriQuad(vluint32_t code, const vluint64_t newval,
const vluint32_t newtri, int bits) {
void fullTriQuad(vluint32_t code, const vluint64_t newval, const vluint32_t newtri, int bits) {
(*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code]))) = newval;
(*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code + 1]))) = newtri;
*m_writep++ = 'b';
@ -287,11 +301,13 @@ public:
*m_writep++ = "01zz"[((newval >> bit) & VL_ULL(1))
| (((newtri >> bit) & VL_ULL(1)) << VL_ULL(1))];
}
*m_writep++=' '; printCode(code); *m_writep++='\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void fullTriArray(vluint32_t code, const vluint32_t* newvalp,
const vluint32_t* newtrip, int bits) {
void fullTriArray(vluint32_t code, const vluint32_t* newvalp, const vluint32_t* newtrip,
int bits) {
for (int word = 0; word < (((bits - 1) / 32) + 1); ++word) {
m_sigs_oldvalp[code + word * 2] = newvalp[word];
m_sigs_oldvalp[code + word * 2 + 1] = newtrip[word];
@ -302,7 +318,9 @@ public:
vluint32_t tribit = (newtrip[(bit / 32)] >> (bit & 0x1f)) & 1;
*m_writep++ = "01zz"[valbit | (tribit << 1)];
}
*m_writep++=' '; printCode(code); *m_writep++='\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
void fullDouble(vluint32_t code, const double newval);
@ -313,7 +331,9 @@ public:
/// Thus this is for special standalone applications that after calling
/// fullBitX, must when then value goes non-X call fullBit.
inline void fullBitX(vluint32_t code) {
*m_writep++='x'; printCode(code); *m_writep++='\n';
*m_writep++ = 'x';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
inline void fullBusX(vluint32_t code, int bits) {
@ -321,7 +341,9 @@ public:
for (int bit = bits - 1; bit >= 0; --bit) {
*m_writep++ = 'x';
}
*m_writep++=' '; printCode(code); *m_writep++='\n';
*m_writep++ = ' ';
printCode(code);
*m_writep++ = '\n';
bufferCheck();
}
inline void fullQuadX(vluint32_t code, int bits) { fullBusX(code, bits); }
@ -370,10 +392,8 @@ public:
}
}
}
inline void chgTriBit(vluint32_t code, const vluint32_t newval,
const vluint32_t newtri) {
vluint32_t diff = ((m_sigs_oldvalp[code] ^ newval)
| (m_sigs_oldvalp[code+1] ^ newtri));
inline void chgTriBit(vluint32_t code, const vluint32_t newval, const vluint32_t newtri) {
vluint32_t diff = ((m_sigs_oldvalp[code] ^ newval) | (m_sigs_oldvalp[code + 1] ^ newtri));
if (VL_UNLIKELY(diff)) {
// Verilator 3.510 and newer provide clean input, so the below
// is only for back compatibility
@ -382,19 +402,19 @@ public:
}
}
}
inline void chgTriBus(vluint32_t code, const vluint32_t newval,
const vluint32_t newtri, int bits) {
vluint32_t diff = ((m_sigs_oldvalp[code] ^ newval)
| (m_sigs_oldvalp[code+1] ^ newtri));
inline void chgTriBus(vluint32_t code, const vluint32_t newval, const vluint32_t newtri,
int bits) {
vluint32_t diff = ((m_sigs_oldvalp[code] ^ newval) | (m_sigs_oldvalp[code + 1] ^ newtri));
if (VL_UNLIKELY(diff)) {
if (VL_UNLIKELY(bits == 32 || (diff & ((1U << bits) - 1)))) {
fullTriBus(code, newval, newtri, bits);
}
}
}
inline void chgTriQuad(vluint32_t code, const vluint64_t newval,
const vluint32_t newtri, int bits) {
vluint64_t diff = ( ((*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code]))) ^ newval)
inline void chgTriQuad(vluint32_t code, const vluint64_t newval, const vluint32_t newtri,
int bits) {
vluint64_t diff
= (((*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code]))) ^ newval)
| ((*(reinterpret_cast<vluint64_t*>(&m_sigs_oldvalp[code + 1]))) ^ newtri));
if (VL_UNLIKELY(diff)) {
if (VL_UNLIKELY(bits == 64 || (diff & ((VL_ULL(1) << bits) - 1)))) {
@ -402,8 +422,8 @@ public:
}
}
}
inline void chgTriArray(vluint32_t code, const vluint32_t* newvalp,
const vluint32_t* newtrip, int bits) {
inline void chgTriArray(vluint32_t code, const vluint32_t* newvalp, const vluint32_t* newtrip,
int bits) {
for (int word = 0; word < (((bits - 1) / 32) + 1); ++word) {
if (VL_UNLIKELY((m_sigs_oldvalp[code + word * 2] ^ newvalp[word])
| (m_sigs_oldvalp[code + word * 2 + 1] ^ newtrip[word]))) {
@ -441,12 +461,14 @@ class VerilatedVcdC {
// CONSTRUCTORS
VL_UNCOPYABLE(VerilatedVcdC);
public:
explicit VerilatedVcdC(VerilatedVcdFile* filep = NULL)
: m_sptrace(filep) {}
~VerilatedVcdC() { close(); }
/// Routines can only be called from one thread; allow next call from different thread
void changeThread() { spTrace()->changeThread(); }
public:
// ACCESSORS
/// Is file open?