HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
vcd_serializer.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include <QObject>
29 #include <QList>
30 #include <QVector>
31 #include <QMap>
32 #include <QFile>
33 #include <QDir>
34 
35 #include <unordered_map>
36 #include "hal_core/defines.h"
37 
38 namespace hal {
39 
40  class Net;
41  class WaveData;
42  class WaveSaleaeData;
43  class SaleaeOutputFile;
44  class SaleaeWriter;
45 
50  {
51  int mIndex;
52  const WaveData* mData;
53  u64 mTime;
54  int mValue;
55  public:
56  VcdSerializerElement(int inx, const WaveData* wd);
57  u64 time() const {return mTime; }
58  int value() const { return mValue; }
59  void setEvent(u64 t, int val) { mTime = t; mValue = val; }
60  bool hasData() const;
61  void reset();
62  QString name() const;
63  QByteArray charCode() const;
64  };
65 
69  class VcdSerializer : public QObject
70  {
71  Q_OBJECT
72  int mTime;
73  u64 mFirstTimestamp;
74  u64 mLastTimestamp;
75  u64 mTimeShift;
77  SaleaeWriter* mSaleaeWriter;
78  QList<VcdSerializerElement*> mWriteElements;
79  QString mWorkdir;
80  QString mSaleaeDirectoryFilename;
81  QMap<QString,QString> mAbbrevByName;
82  QVector<int> mLastValue;
83  int mErrorCount[9];
84  bool mSaleae;
85  int mLastProgress;
86 
87  bool parseVcdDataline(char* buf, int len);
88  bool parseVcdDataNonDecimal(const QByteArray& line, int base);
89  void storeValue(int val, const QByteArray& abrev);
90  bool parseCsvHeader(char* buf);
91  bool parseCsvDataline(char* buf, int dataLineIndex);
92  bool parseVcdInternal(QFile& ff, const QList<const Net *>& onlyNets);
93  bool parseCsvInternal(QFile& ff, const QList<const Net *>& onlyNets);
94 
95  void writeVcdEvent(QFile& of);
96 
97  void deleteFiles();
98  void createSaleaeDirectory();
99  void emitProgress(double step, double max);
100  void emitImportDone();
101 
102  public:
103  VcdSerializer(const QString& workdir=QString(), bool saleae_cli=false, QObject* parent = nullptr);
104  std::string get_saleae_directory_filename() const { return mSaleaeDirectoryFilename.toStdString(); }
105  bool exportVcd(const QString& filename, const QList<const WaveData*>& waves, u32 startTime, u32 endTime, u32 timeShift=0);
106  bool exportCsv(const QString& filename, const QList<const WaveData*>& waves);
107  bool importVcd(const QString& vcdFilename, const QString& workdir=QString(), const QList<const Net*>& onlyNets = QList<const Net*>());
108  bool importCsv(const QString& csvFilename, const QString& workdir=QString(), const QList<const Net*>& onlyNets = QList<const Net*>(), u64 timeScale = 1000000000);
109  bool importSaleae(const QString& saleaeDirecotry, const std::unordered_map<Net*,int>& lookupTable, const QString& workdir=QString(), u64 timeScale = 1000000000);
110 // QList<WaveData*> waveList() const { return mWaves.values(); }
111  u64 maxTime() const { return mTime; }
112  };
113 
114 }
The SaleaeWriter class is a helper class which provides utility methods when importing data to SALEAE...
Definition: saleae_writer.h:42
void setEvent(u64 t, int val)
QByteArray charCode() const
VcdSerializerElement(int inx, const WaveData *wd)
std::string get_saleae_directory_filename() const
bool importSaleae(const QString &saleaeDirecotry, const std::unordered_map< Net *, int > &lookupTable, const QString &workdir=QString(), u64 timeScale=1000000000)
VcdSerializer(const QString &workdir=QString(), bool saleae_cli=false, QObject *parent=nullptr)
bool exportVcd(const QString &filename, const QList< const WaveData * > &waves, u32 startTime, u32 endTime, u32 timeShift=0)
bool importCsv(const QString &csvFilename, const QString &workdir=QString(), const QList< const Net * > &onlyNets=QList< const Net * >(), u64 timeScale=1000000000)
bool exportCsv(const QString &filename, const QList< const WaveData * > &waves)
bool importVcd(const QString &vcdFilename, const QString &workdir=QString(), const QList< const Net * > &onlyNets=QList< const Net * >())
uint64_t u64
Definition: defines.h:42
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
Q_OBJECTQ_OBJECT
QObject * parent() const const
std::string toStdString() const const