2018-10-02 22:42:53 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
//=============================================================================
|
|
|
|
//
|
2021-03-20 21:46:00 +00:00
|
|
|
// Code available from: https://verilator.org
|
2018-10-02 22:42:53 +00:00
|
|
|
//
|
2022-01-01 13:26:40 +00:00
|
|
|
// Copyright 2001-2022 by Wilson Snyder. This program is free software; you
|
2020-03-21 15:24:24 +00:00
|
|
|
// 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
|
2018-10-02 22:42:53 +00:00
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
///
|
|
|
|
/// \file
|
2021-03-20 21:46:00 +00:00
|
|
|
/// \brief Verilated tracing in FST format header
|
|
|
|
///
|
|
|
|
/// User wrapper code should use this header when creating FST traces.
|
2018-10-02 22:42:53 +00:00
|
|
|
///
|
|
|
|
//=============================================================================
|
|
|
|
|
2021-03-04 02:57:07 +00:00
|
|
|
#ifndef VERILATOR_VERILATED_FST_C_H_
|
|
|
|
#define VERILATOR_VERILATED_FST_C_H_
|
2018-10-02 22:42:53 +00:00
|
|
|
|
|
|
|
#include "verilated.h"
|
2020-04-19 22:57:36 +00:00
|
|
|
#include "verilated_trace.h"
|
2018-10-14 17:43:24 +00:00
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
#include "gtkwave/fstapi.h"
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2018-10-14 11:04:18 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-10-02 22:42:53 +00:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// VerilatedFst
|
2021-03-07 13:28:13 +00:00
|
|
|
// Base class to create a Verilator FST dump
|
|
|
|
// This is an internally used class - see VerilatedFstC for what to call from applications
|
2018-10-02 22:42:53 +00:00
|
|
|
|
2020-11-19 02:32:16 +00:00
|
|
|
class VerilatedFst final : public VerilatedTrace<VerilatedFst> {
|
2020-04-19 22:57:36 +00:00
|
|
|
private:
|
|
|
|
// Give the superclass access to private bits (to avoid virtual functions)
|
|
|
|
friend class VerilatedTrace<VerilatedFst>;
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// FST specific internals
|
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
void* m_fst;
|
2022-03-27 19:27:40 +00:00
|
|
|
std::map<uint32_t, fstHandle> m_code2symbol;
|
2021-03-12 22:26:53 +00:00
|
|
|
std::map<int, fstEnumHandle> m_local2fstdtype;
|
2018-10-02 22:42:53 +00:00
|
|
|
std::list<std::string> m_curScope;
|
2021-03-21 01:11:53 +00:00
|
|
|
fstHandle* m_symbolp = nullptr; // same as m_code2symbol, but as an array
|
|
|
|
char* m_strbuf = nullptr; // String buffer long enough to hold maxBits() chars
|
2020-04-29 23:09:09 +00:00
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
// CONSTRUCTORS
|
|
|
|
VL_UNCOPYABLE(VerilatedFst);
|
2022-03-27 19:27:40 +00:00
|
|
|
void declare(uint32_t code, const char* name, int dtypenum, fstVarDir vardir,
|
2022-02-26 17:52:24 +00:00
|
|
|
fstVarType vartype, bool array, int arraynum, bool bussed, int msb, int lsb);
|
2020-04-04 17:45:24 +00:00
|
|
|
|
2020-04-19 22:57:36 +00:00
|
|
|
protected:
|
|
|
|
//=========================================================================
|
|
|
|
// Implementation of VerilatedTrace interface
|
|
|
|
|
|
|
|
// Implementations of protected virtual methods for VerilatedTrace
|
2022-03-27 19:27:40 +00:00
|
|
|
virtual void emitTimeChange(uint64_t timeui) override;
|
2020-04-19 22:57:36 +00:00
|
|
|
|
|
|
|
// Hooks called from VerilatedTrace
|
2020-08-15 15:44:10 +00:00
|
|
|
virtual bool preFullDump() override { return isOpen(); }
|
|
|
|
virtual bool preChangeDump() override { return isOpen(); }
|
2020-04-19 22:57:36 +00:00
|
|
|
|
2020-04-25 18:37:59 +00:00
|
|
|
// Implementations of duck-typed methods for VerilatedTrace. These are
|
|
|
|
// called from only one place (namely full*) so always inline them.
|
2022-03-27 19:27:40 +00:00
|
|
|
inline void emitBit(uint32_t code, CData newval);
|
|
|
|
inline void emitCData(uint32_t code, CData newval, int bits);
|
|
|
|
inline void emitSData(uint32_t code, SData newval, int bits);
|
|
|
|
inline void emitIData(uint32_t code, IData newval, int bits);
|
|
|
|
inline void emitQData(uint32_t code, QData newval, int bits);
|
|
|
|
inline void emitWData(uint32_t code, const WData* newvalp, int bits);
|
|
|
|
inline void emitDouble(uint32_t code, double newval);
|
2020-04-19 12:47:22 +00:00
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
public:
|
2020-04-19 22:57:36 +00:00
|
|
|
//=========================================================================
|
|
|
|
// External interface to client code
|
2021-03-07 16:01:54 +00:00
|
|
|
// (All must be threadsafe)
|
2020-04-19 22:57:36 +00:00
|
|
|
|
2020-08-15 14:12:55 +00:00
|
|
|
explicit VerilatedFst(void* fst = nullptr);
|
2020-04-08 21:54:35 +00:00
|
|
|
~VerilatedFst();
|
2020-04-19 22:57:36 +00:00
|
|
|
|
2021-03-07 13:28:13 +00:00
|
|
|
// Open the file; call isOpen() to see if errors
|
2021-03-07 16:01:54 +00:00
|
|
|
void open(const char* filename) VL_MT_SAFE_EXCLUDES(m_mutex);
|
2021-03-07 13:28:13 +00:00
|
|
|
// Close the file
|
2021-03-07 16:01:54 +00:00
|
|
|
void close() VL_MT_SAFE_EXCLUDES(m_mutex);
|
2021-03-07 13:28:13 +00:00
|
|
|
// Flush any remaining data to this file
|
2021-03-07 16:01:54 +00:00
|
|
|
void flush() VL_MT_SAFE_EXCLUDES(m_mutex);
|
2021-03-07 13:28:13 +00:00
|
|
|
// Return if file is open
|
2021-03-07 16:01:54 +00:00
|
|
|
bool isOpen() const VL_MT_SAFE { return m_fst != nullptr; }
|
2020-04-19 22:57:36 +00:00
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// Internal interface to Verilator generated code
|
|
|
|
|
2021-03-07 13:28:13 +00:00
|
|
|
// Inside dumping routines, declare a data type
|
2022-03-27 19:27:40 +00:00
|
|
|
void declDTypeEnum(int dtypenum, const char* name, uint32_t elements, unsigned int minValbits,
|
|
|
|
const char** itemNamesp, const char** itemValuesp);
|
2020-04-19 22:57:36 +00:00
|
|
|
|
2021-03-07 13:28:13 +00:00
|
|
|
// Inside dumping routines, declare a signal
|
2022-03-27 19:27:40 +00:00
|
|
|
void declBit(uint32_t code, const char* name, int dtypenum, fstVarDir vardir,
|
2020-04-19 22:57:36 +00:00
|
|
|
fstVarType vartype, bool array, int arraynum);
|
2022-03-27 19:27:40 +00:00
|
|
|
void declBus(uint32_t code, const char* name, int dtypenum, fstVarDir vardir,
|
2020-04-19 22:57:36 +00:00
|
|
|
fstVarType vartype, bool array, int arraynum, int msb, int lsb);
|
2022-03-27 19:27:40 +00:00
|
|
|
void declQuad(uint32_t code, const char* name, int dtypenum, fstVarDir vardir,
|
2020-04-19 22:57:36 +00:00
|
|
|
fstVarType vartype, bool array, int arraynum, int msb, int lsb);
|
2022-03-27 19:27:40 +00:00
|
|
|
void declArray(uint32_t code, const char* name, int dtypenum, fstVarDir vardir,
|
2020-04-19 22:57:36 +00:00
|
|
|
fstVarType vartype, bool array, int arraynum, int msb, int lsb);
|
2022-03-27 19:27:40 +00:00
|
|
|
void declDouble(uint32_t code, const char* name, int dtypenum, fstVarDir vardir,
|
2020-04-19 22:57:36 +00:00
|
|
|
fstVarType vartype, bool array, int arraynum);
|
2018-10-02 22:42:53 +00:00
|
|
|
};
|
|
|
|
|
2021-03-28 15:50:05 +00:00
|
|
|
#ifndef DOXYGEN
|
2020-04-19 22:57:36 +00:00
|
|
|
// Declare specialization here as it's used in VerilatedFstC just below
|
2022-03-27 19:27:40 +00:00
|
|
|
template <> void VerilatedTrace<VerilatedFst>::dump(uint64_t timeui);
|
2020-04-19 22:57:36 +00:00
|
|
|
template <> void VerilatedTrace<VerilatedFst>::set_time_unit(const char* unitp);
|
|
|
|
template <> void VerilatedTrace<VerilatedFst>::set_time_unit(const std::string& unit);
|
|
|
|
template <> void VerilatedTrace<VerilatedFst>::set_time_resolution(const char* unitp);
|
|
|
|
template <> void VerilatedTrace<VerilatedFst>::set_time_resolution(const std::string& unit);
|
2022-03-05 20:44:32 +00:00
|
|
|
template <> void VerilatedTrace<VerilatedFst>::dumpvars(int level, const std::string& hier);
|
2021-03-28 15:50:05 +00:00
|
|
|
#endif
|
2020-04-19 22:57:36 +00:00
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
//=============================================================================
|
|
|
|
// VerilatedFstC
|
|
|
|
/// Create a FST dump file in C standalone (no SystemC) simulations.
|
|
|
|
/// Also derived for use in SystemC simulations.
|
|
|
|
|
2021-04-06 20:18:58 +00:00
|
|
|
class VerilatedFstC VL_NOT_FINAL {
|
2021-03-21 01:11:53 +00:00
|
|
|
VerilatedFst m_sptrace; // Trace file being created
|
2018-10-02 22:42:53 +00:00
|
|
|
|
|
|
|
// CONSTRUCTORS
|
|
|
|
VL_UNCOPYABLE(VerilatedFstC);
|
2020-04-04 17:45:24 +00:00
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
public:
|
2021-03-07 13:28:13 +00:00
|
|
|
/// Construct the dump. Optional argument is ignored.
|
2020-08-15 14:12:55 +00:00
|
|
|
explicit VerilatedFstC(void* filep = nullptr)
|
2020-08-16 13:55:36 +00:00
|
|
|
: m_sptrace{filep} {}
|
2021-03-07 13:28:13 +00:00
|
|
|
/// Destruct, flush, and close the dump
|
2021-12-22 23:41:11 +00:00
|
|
|
virtual ~VerilatedFstC() { close(); }
|
2020-04-04 17:45:24 +00:00
|
|
|
|
2021-03-07 13:28:13 +00:00
|
|
|
// METHODS - User called
|
|
|
|
|
|
|
|
/// Return if file is open
|
2021-03-07 16:01:54 +00:00
|
|
|
bool isOpen() const VL_MT_SAFE { return m_sptrace.isOpen(); }
|
2018-10-02 22:42:53 +00:00
|
|
|
/// Open a new FST file
|
2021-03-07 16:01:54 +00:00
|
|
|
void open(const char* filename) VL_MT_SAFE { m_sptrace.open(filename); }
|
2018-10-02 22:42:53 +00:00
|
|
|
/// Close dump
|
2021-03-07 16:01:54 +00:00
|
|
|
void close() VL_MT_SAFE { m_sptrace.close(); }
|
2018-10-02 22:42:53 +00:00
|
|
|
/// Flush dump
|
2021-03-07 16:01:54 +00:00
|
|
|
void flush() VL_MT_SAFE { m_sptrace.flush(); }
|
2018-10-02 22:42:53 +00:00
|
|
|
/// Write one cycle of dump data
|
2021-05-13 22:56:07 +00:00
|
|
|
/// Call with the current context's time just after eval'ed,
|
|
|
|
/// e.g. ->dump(contextp->time())
|
2022-03-27 19:27:40 +00:00
|
|
|
void dump(uint64_t timeui) { m_sptrace.dump(timeui); }
|
2018-10-02 22:42:53 +00:00
|
|
|
/// Write one cycle of dump data - backward compatible and to reduce
|
2022-03-27 19:27:40 +00:00
|
|
|
/// conversion warnings. It's better to use a uint64_t time instead.
|
|
|
|
void dump(double timestamp) { dump(static_cast<uint64_t>(timestamp)); }
|
|
|
|
void dump(uint32_t timestamp) { dump(static_cast<uint64_t>(timestamp)); }
|
|
|
|
void dump(int timestamp) { dump(static_cast<uint64_t>(timestamp)); }
|
2021-03-07 13:28:13 +00:00
|
|
|
|
|
|
|
// METHODS - Internal/backward compatible
|
|
|
|
// \protectedsection
|
|
|
|
|
|
|
|
// Set time units (s/ms, defaults to ns)
|
|
|
|
// Users should not need to call this, as for Verilated models, these
|
|
|
|
// propage from the Verilated default timeunit
|
2021-03-07 16:01:54 +00:00
|
|
|
void set_time_unit(const char* unitp) VL_MT_SAFE { m_sptrace.set_time_unit(unitp); }
|
|
|
|
void set_time_unit(const std::string& unit) VL_MT_SAFE { m_sptrace.set_time_unit(unit); }
|
2021-03-07 13:28:13 +00:00
|
|
|
// Set time resolution (s/ms, defaults to ns)
|
|
|
|
// Users should not need to call this, as for Verilated models, these
|
|
|
|
// propage from the Verilated default timeprecision
|
2021-03-07 16:01:54 +00:00
|
|
|
void set_time_resolution(const char* unitp) VL_MT_SAFE {
|
|
|
|
m_sptrace.set_time_resolution(unitp);
|
|
|
|
}
|
|
|
|
void set_time_resolution(const std::string& unit) VL_MT_SAFE {
|
|
|
|
m_sptrace.set_time_resolution(unit);
|
|
|
|
}
|
2022-03-05 20:44:32 +00:00
|
|
|
// Set variables to dump, using $dumpvars format
|
|
|
|
// If level = 0, dump everything and hier is then ignored
|
|
|
|
void dumpvars(int level, const std::string& hier) VL_MT_SAFE {
|
|
|
|
m_sptrace.dumpvars(level, hier);
|
|
|
|
}
|
2018-10-02 22:42:53 +00:00
|
|
|
|
2021-03-07 13:28:13 +00:00
|
|
|
// Internal class access
|
2022-01-08 17:01:39 +00:00
|
|
|
inline VerilatedFst* spTrace() { return &m_sptrace; }
|
2018-10-02 22:42:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // guard
|