2018-10-02 22:42:53 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// THIS MODULE IS PUBLICLY LICENSED
|
|
|
|
//
|
2020-03-21 15:24:24 +00:00
|
|
|
// Copyright 2001-2020 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
|
2018-10-02 22:42:53 +00:00
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief C++ Tracing in FST Format
|
|
|
|
///
|
|
|
|
//=============================================================================
|
|
|
|
// SPDIFF_OFF
|
|
|
|
|
|
|
|
#ifndef _VERILATED_FST_C_H_
|
|
|
|
#define _VERILATED_FST_C_H_ 1
|
|
|
|
|
|
|
|
#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
|
|
|
|
/// Base class to create a Verilator FST dump
|
|
|
|
/// This is an internally used class - see VerilatedFstC for what to call from applications
|
|
|
|
|
2020-04-19 22:57:36 +00:00
|
|
|
class VerilatedFst : public VerilatedTrace<VerilatedFst> {
|
|
|
|
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
|
|
|
typedef std::map<vluint32_t, fstHandle> Code2SymbolType;
|
2018-10-08 11:21:22 +00:00
|
|
|
typedef std::map<int, fstEnumHandle> Local2FstDtype;
|
2020-04-04 17:45:24 +00:00
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
void* m_fst;
|
|
|
|
Code2SymbolType m_code2symbol;
|
2018-10-08 11:21:22 +00:00
|
|
|
Local2FstDtype m_local2fstdtype;
|
2018-10-02 22:42:53 +00:00
|
|
|
std::list<std::string> m_curScope;
|
2020-04-08 21:54:35 +00:00
|
|
|
fstHandle* m_symbolp; ///< same as m_code2symbol, but as an array
|
2020-04-29 23:09:09 +00:00
|
|
|
char* m_strbuf; ///< String buffer long enough to hold maxBits() chars
|
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
// CONSTRUCTORS
|
|
|
|
VL_UNCOPYABLE(VerilatedFst);
|
2020-05-03 20:55:22 +00:00
|
|
|
void declare(vluint32_t code, const char* name, int dtypenum, fstVarDir vardir,
|
|
|
|
fstVarType vartype, bool array, int arraynum, 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
|
2020-08-15 15:44:10 +00:00
|
|
|
virtual void emitTimeChange(vluint64_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.
|
2020-04-29 23:09:09 +00:00
|
|
|
inline void emitBit(vluint32_t code, CData newval);
|
|
|
|
inline void emitCData(vluint32_t code, CData newval, int bits);
|
|
|
|
inline void emitSData(vluint32_t code, SData newval, int bits);
|
|
|
|
inline void emitIData(vluint32_t code, IData newval, int bits);
|
|
|
|
inline void emitQData(vluint32_t code, QData newval, int bits);
|
|
|
|
inline void emitWData(vluint32_t code, const WData* newvalp, int bits);
|
2020-04-25 18:37:59 +00:00
|
|
|
inline void emitDouble(vluint32_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
|
|
|
|
|
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
|
|
|
|
|
|
|
/// Open the file; call isOpen() to see if errors
|
2018-10-02 22:42:53 +00:00
|
|
|
void open(const char* filename) VL_MT_UNSAFE;
|
2020-04-19 22:57:36 +00:00
|
|
|
/// Close the file
|
2020-04-21 22:49:07 +00:00
|
|
|
void close() VL_MT_UNSAFE;
|
2020-04-19 22:57:36 +00:00
|
|
|
/// Flush any remaining data to this file
|
2020-04-21 22:49:07 +00:00
|
|
|
void flush() VL_MT_UNSAFE;
|
2020-04-19 22:57:36 +00:00
|
|
|
/// Is file open?
|
2020-08-15 14:12:55 +00:00
|
|
|
bool isOpen() const { return m_fst != nullptr; }
|
2020-04-19 22:57:36 +00:00
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// Internal interface to Verilator generated code
|
|
|
|
|
2018-10-08 11:21:22 +00:00
|
|
|
/// Inside dumping routines, declare a data type
|
|
|
|
void declDTypeEnum(int dtypenum, const char* name, vluint32_t elements,
|
2020-04-13 23:13:10 +00:00
|
|
|
unsigned int minValbits, const char** itemNamesp, const char** itemValuesp);
|
2020-04-19 22:57:36 +00:00
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
/// Inside dumping routines, declare a signal
|
2020-04-13 23:13:10 +00:00
|
|
|
void declBit(vluint32_t code, const char* name, int dtypenum, fstVarDir vardir,
|
2020-04-19 22:57:36 +00:00
|
|
|
fstVarType vartype, bool array, int arraynum);
|
2020-04-13 23:13:10 +00:00
|
|
|
void declBus(vluint32_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);
|
2020-04-13 23:13:10 +00:00
|
|
|
void declQuad(vluint32_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);
|
2020-04-13 23:13:10 +00:00
|
|
|
void declArray(vluint32_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);
|
2020-04-13 23:13:10 +00:00
|
|
|
void declDouble(vluint32_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
|
|
|
};
|
|
|
|
|
2020-04-19 22:57:36 +00:00
|
|
|
// Declare specialization here as it's used in VerilatedFstC just below
|
|
|
|
template <> void VerilatedTrace<VerilatedFst>::dump(vluint64_t timeui);
|
|
|
|
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);
|
|
|
|
|
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.
|
|
|
|
/// Thread safety: Unless otherwise indicated, every function is VL_MT_UNSAFE_ONE
|
|
|
|
|
|
|
|
class VerilatedFstC {
|
|
|
|
VerilatedFst m_sptrace; ///< Trace file being created
|
|
|
|
|
|
|
|
// CONSTRUCTORS
|
|
|
|
VL_UNCOPYABLE(VerilatedFstC);
|
2020-04-04 17:45:24 +00:00
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
public:
|
2020-08-15 14:12:55 +00:00
|
|
|
explicit VerilatedFstC(void* filep = nullptr)
|
2020-04-04 17:45:24 +00:00
|
|
|
: m_sptrace(filep) {}
|
2020-03-02 02:39:23 +00:00
|
|
|
~VerilatedFstC() { close(); }
|
2020-03-02 12:43:10 +00:00
|
|
|
/// Routines can only be called from one thread; allow next call from different thread
|
|
|
|
void changeThread() { spTrace()->changeThread(); }
|
2020-04-04 17:45:24 +00:00
|
|
|
|
2018-10-02 22:42:53 +00:00
|
|
|
// ACCESSORS
|
|
|
|
/// Is file open?
|
|
|
|
bool isOpen() const { return m_sptrace.isOpen(); }
|
|
|
|
// METHODS
|
|
|
|
/// Open a new FST file
|
|
|
|
void open(const char* filename) VL_MT_UNSAFE_ONE { m_sptrace.open(filename); }
|
|
|
|
/// Close dump
|
|
|
|
void close() VL_MT_UNSAFE_ONE { m_sptrace.close(); }
|
|
|
|
/// Flush dump
|
|
|
|
void flush() VL_MT_UNSAFE_ONE { m_sptrace.flush(); }
|
|
|
|
/// Write one cycle of dump data
|
|
|
|
void dump(vluint64_t timeui) { m_sptrace.dump(timeui); }
|
|
|
|
/// Write one cycle of dump data - backward compatible and to reduce
|
|
|
|
/// conversion warnings. It's better to use a vluint64_t time instead.
|
|
|
|
void dump(double timestamp) { dump(static_cast<vluint64_t>(timestamp)); }
|
|
|
|
void dump(vluint32_t timestamp) { dump(static_cast<vluint64_t>(timestamp)); }
|
|
|
|
void dump(int timestamp) { dump(static_cast<vluint64_t>(timestamp)); }
|
|
|
|
/// Set time units (s/ms, defaults to ns)
|
2020-04-15 23:39:03 +00:00
|
|
|
/// For Verilated models, these propage from the Verilated default --timeunit
|
2019-05-12 12:19:49 +00:00
|
|
|
void set_time_unit(const char* unitp) { m_sptrace.set_time_unit(unitp); }
|
2020-04-19 22:57:36 +00:00
|
|
|
void set_time_unit(const std::string& unit) { m_sptrace.set_time_unit(unit); }
|
2018-10-02 22:42:53 +00:00
|
|
|
/// Set time resolution (s/ms, defaults to ns)
|
2020-04-15 23:39:03 +00:00
|
|
|
/// For Verilated models, these propage from the Verilated default --timeunit
|
2019-05-12 12:19:49 +00:00
|
|
|
void set_time_resolution(const char* unitp) { m_sptrace.set_time_resolution(unitp); }
|
2020-04-19 22:57:36 +00:00
|
|
|
void set_time_resolution(const std::string& unit) { m_sptrace.set_time_resolution(unit); }
|
2018-10-02 22:42:53 +00:00
|
|
|
|
|
|
|
/// Internal class access
|
|
|
|
inline VerilatedFst* spTrace() { return &m_sptrace; };
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // guard
|