mirror of
https://github.com/verilator/verilator.git
synced 2025-01-19 12:54:02 +00:00
Internals: Refactor VerilatorSerialize to remove intermediate class. No functional change intended.
This commit is contained in:
parent
ac4690d74b
commit
13c91f5fce
@ -441,7 +441,7 @@ static inline IData VL_EXTENDSIGN_I(int lbits, IData lhs) { return (-((lhs)&(VL
|
|||||||
static inline QData VL_EXTENDSIGN_Q(int lbits, QData lhs) { return (-((lhs)&(VL_ULL(1)<<(lbits-1)))); }
|
static inline QData VL_EXTENDSIGN_Q(int lbits, QData lhs) { return (-((lhs)&(VL_ULL(1)<<(lbits-1)))); }
|
||||||
|
|
||||||
// Debugging prints
|
// Debugging prints
|
||||||
void _VL_DEBUG_PRINT_W(int lbits, WDataInP iwp);
|
extern void _VL_DEBUG_PRINT_W(int lbits, WDataInP iwp);
|
||||||
|
|
||||||
//=========================================================================
|
//=========================================================================
|
||||||
// Pli macros
|
// Pli macros
|
||||||
|
@ -27,31 +27,30 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
// VerilatedSerialBase - internal base class for common code between VerilatedSerialize and VerilatedDeserialize
|
// VerilatedSerialize - convert structures to a stream representation
|
||||||
|
|
||||||
class VerilatedSerialBase {
|
class VerilatedSerialize {
|
||||||
protected:
|
protected:
|
||||||
// MEMBERS
|
// MEMBERS
|
||||||
// For speed, keep m_cp as the first member of this structure
|
// For speed, keep m_cp as the first member of this structure
|
||||||
vluint8_t* m_cp; ///< Current pointer into m_bufp buffer
|
vluint8_t* m_cp; ///< Current pointer into m_bufp buffer
|
||||||
vluint8_t* m_bufp; ///< Output buffer
|
vluint8_t* m_bufp; ///< Output buffer
|
||||||
bool m_isOpen; ///< True indicates open file/stream
|
bool m_isOpen; ///< True indicates open file/stream
|
||||||
std::string m_filename;
|
std::string m_filename; ///< Filename, for error messages
|
||||||
|
|
||||||
inline static size_t bufferSize() { return 256*1024; } // See below for slack calculation
|
inline static size_t bufferSize() { return 256*1024; } // See below for slack calculation
|
||||||
inline static size_t bufferInsertSize() { return 16*1024; }
|
inline static size_t bufferInsertSize() { return 16*1024; }
|
||||||
|
|
||||||
|
void header();
|
||||||
|
void trailer();
|
||||||
|
public:
|
||||||
// CREATORS
|
// CREATORS
|
||||||
VerilatedSerialBase() {
|
VerilatedSerialize() {
|
||||||
m_isOpen = false;
|
m_isOpen = false;
|
||||||
m_bufp = new vluint8_t [bufferSize()];
|
m_bufp = new vluint8_t [bufferSize()];
|
||||||
m_cp = m_bufp;
|
m_cp = m_bufp;
|
||||||
}
|
}
|
||||||
private:
|
virtual ~VerilatedSerialize() {
|
||||||
VerilatedSerialBase(const VerilatedSerialBase& ); ///< N/A, no copy constructor
|
|
||||||
public:
|
|
||||||
// CREATORS
|
|
||||||
virtual ~VerilatedSerialBase() {
|
|
||||||
close();
|
close();
|
||||||
if (m_bufp) { delete m_bufp; m_bufp=NULL; }
|
if (m_bufp) { delete m_bufp; m_bufp=NULL; }
|
||||||
}
|
}
|
||||||
@ -60,30 +59,6 @@ public:
|
|||||||
std::string filename() const { return m_filename; }
|
std::string filename() const { return m_filename; }
|
||||||
virtual void close() { flush(); }
|
virtual void close() { flush(); }
|
||||||
virtual void flush() {}
|
virtual void flush() {}
|
||||||
};
|
|
||||||
|
|
||||||
//=============================================================================
|
|
||||||
// VerilatedSerialize - convert structures to a stream representation
|
|
||||||
|
|
||||||
class VerilatedSerialize : public VerilatedSerialBase {
|
|
||||||
protected:
|
|
||||||
virtual void close() { flush(); }
|
|
||||||
virtual void flush() {}
|
|
||||||
void header();
|
|
||||||
void trailer();
|
|
||||||
public:
|
|
||||||
// CREATORS
|
|
||||||
VerilatedSerialize() {}
|
|
||||||
virtual ~VerilatedSerialize() { close(); }
|
|
||||||
// METHODS
|
|
||||||
VerilatedSerialize& bufferCheck() {
|
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
return *this; // For function chaining
|
|
||||||
}
|
|
||||||
inline VerilatedSerialize& write (const void* __restrict datap, size_t size) {
|
inline VerilatedSerialize& write (const void* __restrict datap, size_t size) {
|
||||||
const vluint8_t* __restrict dp = (const vluint8_t* __restrict)datap;
|
const vluint8_t* __restrict dp = (const vluint8_t* __restrict)datap;
|
||||||
while (size) {
|
while (size) {
|
||||||
@ -95,22 +70,54 @@ public:
|
|||||||
}
|
}
|
||||||
return *this; // For function chaining
|
return *this; // For function chaining
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
VerilatedSerialize(const VerilatedSerialize& ); ///< N/A, no copy constructor
|
||||||
|
VerilatedSerialize& bufferCheck() {
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
return *this; // For function chaining
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
// VerilatedDeserial - load structures from a stream representation
|
// VerilatedDeserial - load structures from a stream representation
|
||||||
|
|
||||||
class VerilatedDeserialize : public VerilatedSerialBase {
|
class VerilatedDeserialize {
|
||||||
protected:
|
protected:
|
||||||
|
// MEMBERS
|
||||||
|
// For speed, keep m_cp as the first member of this structure
|
||||||
|
vluint8_t* m_cp; ///< Current pointer into m_bufp buffer
|
||||||
|
vluint8_t* m_bufp; ///< Output buffer
|
||||||
vluint8_t* m_endp; ///< Last valid byte in m_bufp buffer
|
vluint8_t* m_endp; ///< Last valid byte in m_bufp buffer
|
||||||
|
bool m_isOpen; ///< True indicates open file/stream
|
||||||
|
std::string m_filename; ///< Filename, for error messages
|
||||||
|
|
||||||
|
inline static size_t bufferSize() { return 256*1024; } // See below for slack calculation
|
||||||
|
inline static size_t bufferInsertSize() { return 16*1024; }
|
||||||
|
|
||||||
virtual void fill() = 0;
|
virtual void fill() = 0;
|
||||||
void header();
|
void header();
|
||||||
void trailer();
|
void trailer();
|
||||||
public:
|
public:
|
||||||
// CREATORS
|
// CREATORS
|
||||||
VerilatedDeserialize() { m_endp = NULL; }
|
VerilatedDeserialize() {
|
||||||
virtual ~VerilatedDeserialize() { close(); }
|
m_isOpen = false;
|
||||||
|
m_bufp = new vluint8_t [bufferSize()];
|
||||||
|
m_cp = m_bufp;
|
||||||
|
m_endp = NULL;
|
||||||
|
}
|
||||||
|
virtual ~VerilatedDeserialize() {
|
||||||
|
close();
|
||||||
|
if (m_bufp) { delete m_bufp; m_bufp=NULL; }
|
||||||
|
}
|
||||||
// METHODS
|
// METHODS
|
||||||
|
bool isOpen() const { return m_isOpen; }
|
||||||
|
std::string filename() const { return m_filename; }
|
||||||
|
virtual void close() { flush(); }
|
||||||
|
virtual void flush() {}
|
||||||
inline VerilatedDeserialize& read (void* __restrict datap, size_t size) {
|
inline VerilatedDeserialize& read (void* __restrict datap, size_t size) {
|
||||||
vluint8_t* __restrict dp = (vluint8_t* __restrict)datap;
|
vluint8_t* __restrict dp = (vluint8_t* __restrict)datap;
|
||||||
while (size) {
|
while (size) {
|
||||||
@ -126,6 +133,8 @@ public:
|
|||||||
bool readDiffers (const void* __restrict datap, size_t size);
|
bool readDiffers (const void* __restrict datap, size_t size);
|
||||||
VerilatedDeserialize& readAssert (const void* __restrict datap, size_t size);
|
VerilatedDeserialize& readAssert (const void* __restrict datap, size_t size);
|
||||||
VerilatedDeserialize& readAssert (vluint64_t data) { return readAssert(&data, sizeof(data)); }
|
VerilatedDeserialize& readAssert (vluint64_t data) { return readAssert(&data, sizeof(data)); }
|
||||||
|
private:
|
||||||
|
VerilatedDeserialize(const VerilatedDeserialize& ); ///< N/A, no copy constructor
|
||||||
VerilatedDeserialize& bufferCheck() {
|
VerilatedDeserialize& bufferCheck() {
|
||||||
// Flush the write buffer if there's not enough space left for new information
|
// 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
|
// We only call this once per vector, so we need enough slop for a very wide "b###" line
|
||||||
|
@ -39,9 +39,9 @@
|
|||||||
#define VL_SC_BV_DATAP(bv) (VlScBvExposer::sp_datap(bv))
|
#define VL_SC_BV_DATAP(bv) (VlScBvExposer::sp_datap(bv))
|
||||||
class VlScBvExposer : public sc_bv_base {
|
class VlScBvExposer : public sc_bv_base {
|
||||||
public:
|
public:
|
||||||
static vluint32_t* sp_datap(const sc_bv_base& base) {
|
static const vluint32_t* sp_datap(const sc_bv_base& base) {
|
||||||
return static_cast<const VlScBvExposer*>(&base)->sp_datatp(); }
|
return static_cast<const VlScBvExposer*>(&base)->sp_datatp(); }
|
||||||
vluint32_t* sp_datatp() const { return reinterpret_cast<vluint32_t*>(m_data); }
|
const vluint32_t* sp_datatp() const { return reinterpret_cast<vluint32_t*>(m_data); }
|
||||||
// Above reads this protected element in sc_bv_base:
|
// Above reads this protected element in sc_bv_base:
|
||||||
// sc_digit* m_data; // data array
|
// sc_digit* m_data; // data array
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user