113245Sgabeblack@google.com/* 213245Sgabeblack@google.com * Copyright 2018 Google, Inc. 313245Sgabeblack@google.com * 413245Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 513245Sgabeblack@google.com * modification, are permitted provided that the following conditions are 613245Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 713245Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 813245Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 913245Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1013245Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1113245Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1213245Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1313245Sgabeblack@google.com * this software without specific prior written permission. 1413245Sgabeblack@google.com * 1513245Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1613245Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1713245Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1813245Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1913245Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2013245Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2113245Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2213245Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2313245Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2413245Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2513245Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2613245Sgabeblack@google.com * 2713245Sgabeblack@google.com * Authors: Gabe Black 2813245Sgabeblack@google.com */ 2913245Sgabeblack@google.com 3013245Sgabeblack@google.com#ifndef __SYSTEMC_UTILS_VCD_HH__ 3113245Sgabeblack@google.com#define __SYSTEMC_UTILS_VCD_HH__ 3213245Sgabeblack@google.com 3313245Sgabeblack@google.com#include <map> 3413245Sgabeblack@google.com 3513245Sgabeblack@google.com#include "systemc/utils/tracefile.hh" 3613245Sgabeblack@google.com 3713245Sgabeblack@google.comnamespace sc_gem5 3813245Sgabeblack@google.com{ 3913245Sgabeblack@google.com 4013245Sgabeblack@google.comclass VcdTraceValBase; 4113245Sgabeblack@google.com 4213245Sgabeblack@google.comclass VcdTraceScope 4313245Sgabeblack@google.com{ 4413245Sgabeblack@google.com private: 4513245Sgabeblack@google.com std::vector<std::pair<std::string, VcdTraceValBase *>> values; 4613245Sgabeblack@google.com std::map<std::string, VcdTraceScope *> scopes; 4713245Sgabeblack@google.com 4813245Sgabeblack@google.com public: 4913245Sgabeblack@google.com void addValue(const std::string &name, VcdTraceValBase *value); 5013245Sgabeblack@google.com void output(const std::string &name, std::ostream &os); 5113245Sgabeblack@google.com}; 5213245Sgabeblack@google.com 5313245Sgabeblack@google.comclass VcdTraceFile : public TraceFile 5413245Sgabeblack@google.com{ 5513245Sgabeblack@google.com private: 5613245Sgabeblack@google.com Tick lastPrintedTime; 5713245Sgabeblack@google.com uint64_t deltasAtNow; 5813245Sgabeblack@google.com 5913245Sgabeblack@google.com static const int NextNameChars = 5; 6013245Sgabeblack@google.com char _nextName[NextNameChars + 1]; 6113245Sgabeblack@google.com std::string nextSignalName(); 6213245Sgabeblack@google.com 6313245Sgabeblack@google.com bool initialized; 6413245Sgabeblack@google.com void initialize(); 6513245Sgabeblack@google.com 6613245Sgabeblack@google.com std::vector<VcdTraceValBase *> traceVals; 6713245Sgabeblack@google.com VcdTraceScope topScope; 6813245Sgabeblack@google.com 6913245Sgabeblack@google.com public: 7013245Sgabeblack@google.com VcdTraceFile(const std::string &name) : 7113245Sgabeblack@google.com TraceFile(name + ".vcd"), lastPrintedTime(0), deltasAtNow(0), 7213245Sgabeblack@google.com initialized(false) 7313245Sgabeblack@google.com { 7413245Sgabeblack@google.com _nextName[NextNameChars] = '\0'; 7513245Sgabeblack@google.com for (int i = 0; i < NextNameChars; i++) 7613245Sgabeblack@google.com _nextName[i] = 'a'; 7713245Sgabeblack@google.com } 7813245Sgabeblack@google.com ~VcdTraceFile(); 7913245Sgabeblack@google.com 8013245Sgabeblack@google.com void trace(bool delta) override; 8113245Sgabeblack@google.com 8213245Sgabeblack@google.com template<typename TV> 8313245Sgabeblack@google.com void 8413245Sgabeblack@google.com addNewTraceVal(const typename TV::TracedType *v, const std::string &name, 8513245Sgabeblack@google.com int width=1) 8613245Sgabeblack@google.com { 8713245Sgabeblack@google.com VcdTraceValBase *tv = new TV(v, nextSignalName(), width); 8813245Sgabeblack@google.com traceVals.push_back(tv); 8913245Sgabeblack@google.com topScope.addValue(name, tv); 9013245Sgabeblack@google.com } 9113245Sgabeblack@google.com 9213245Sgabeblack@google.com void addTraceVal(const bool *v, const std::string &name) override; 9313245Sgabeblack@google.com void addTraceVal(const float *v, const std::string &name) override; 9413245Sgabeblack@google.com void addTraceVal(const double *v, const std::string &name) override; 9513245Sgabeblack@google.com 9613245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_logic *v, 9713245Sgabeblack@google.com const std::string &name) override; 9813245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_int_base *v, 9913245Sgabeblack@google.com const std::string &name) override; 10013245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_uint_base *v, 10113245Sgabeblack@google.com const std::string &name) override; 10213245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_signed *v, 10313245Sgabeblack@google.com const std::string &name) override; 10413245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_unsigned *v, 10513245Sgabeblack@google.com const std::string &name) override; 10613245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_bv_base *v, 10713245Sgabeblack@google.com const std::string &name) override; 10813245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_lv_base *v, 10913245Sgabeblack@google.com const std::string &name) override; 11013245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_fxval *v, 11113245Sgabeblack@google.com const std::string &name) override; 11213245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_fxval_fast *v, 11313245Sgabeblack@google.com const std::string &name) override; 11413245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_fxnum *v, 11513245Sgabeblack@google.com const std::string &name) override; 11613245Sgabeblack@google.com void addTraceVal(const sc_dt::sc_fxnum_fast *v, 11713245Sgabeblack@google.com const std::string &name) override; 11813245Sgabeblack@google.com 11913245Sgabeblack@google.com void addTraceVal(const sc_core::sc_event *v, 12013245Sgabeblack@google.com const std::string &name) override; 12113245Sgabeblack@google.com void addTraceVal(const sc_core::sc_time *v, 12213245Sgabeblack@google.com const std::string &name) override; 12313245Sgabeblack@google.com 12413245Sgabeblack@google.com void addTraceVal(const unsigned char *v, 12513245Sgabeblack@google.com const std::string &name, int width) override; 12613245Sgabeblack@google.com void addTraceVal(const char *v, const std::string &name, 12713245Sgabeblack@google.com int width) override; 12813245Sgabeblack@google.com void addTraceVal(const unsigned short *v, 12913245Sgabeblack@google.com const std::string &name, int width) override; 13013245Sgabeblack@google.com void addTraceVal(const short *v, const std::string &name, 13113245Sgabeblack@google.com int width) override; 13213245Sgabeblack@google.com void addTraceVal(const unsigned int *v, 13313245Sgabeblack@google.com const std::string &name, int width) override; 13413245Sgabeblack@google.com void addTraceVal(const int *v, const std::string &name, 13513245Sgabeblack@google.com int width) override; 13613245Sgabeblack@google.com void addTraceVal(const unsigned long *v, 13713245Sgabeblack@google.com const std::string &name, int width) override; 13813245Sgabeblack@google.com void addTraceVal(const long *v, const std::string &name, 13913245Sgabeblack@google.com int width) override; 14013245Sgabeblack@google.com 14113245Sgabeblack@google.com void addTraceVal(const sc_dt::int64 *v, 14213245Sgabeblack@google.com const std::string &name, int width) override; 14313245Sgabeblack@google.com void addTraceVal(const sc_dt::uint64 *v, 14413245Sgabeblack@google.com const std::string &name, int width) override; 14513245Sgabeblack@google.com 14613245Sgabeblack@google.com void addTraceVal(const unsigned int *, const std::string &name, 14713245Sgabeblack@google.com const char **literals) override; 14813245Sgabeblack@google.com 14913245Sgabeblack@google.com void writeComment(const std::string &comment) override; 15013245Sgabeblack@google.com}; 15113245Sgabeblack@google.com 15213245Sgabeblack@google.com} // namespace sc_gem5 15313245Sgabeblack@google.com 15413245Sgabeblack@google.com#endif // __SYSTEMC_UTILS_VCD_HH__ 155