Start restoring memory state from VCD/FST
[yosys.git] / kernel / fstdata.h
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2022 Miodrag Milanovic <micko@yosyshq.com>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20 #ifndef FSTDATA_H
21 #define FSTDATA_H
22
23 #include "kernel/yosys.h"
24 #include "libs/fst/fstapi.h"
25
26 YOSYS_NAMESPACE_BEGIN
27
28 typedef std::function<void(uint64_t)> CallbackFunction;
29 struct fst_end_of_data_exception { };
30
31 struct FstVar
32 {
33 fstHandle id;
34 std::string name;
35 bool is_alias;
36 bool is_reg;
37 std::string scope;
38 int width;
39 };
40
41 class FstData
42 {
43 public:
44 FstData(std::string filename);
45 ~FstData();
46
47 uint64_t getStartTime();
48 uint64_t getEndTime();
49
50 std::vector<FstVar>& getVars() { return vars; };
51
52 void reconstruct_callback_attimes(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen);
53 void reconstructAllAtTimes(std::vector<fstHandle> &signal, uint64_t start_time, uint64_t end_time, CallbackFunction cb);
54
55 std::string valueOf(fstHandle signal);
56 fstHandle getHandle(std::string name);
57 dict<int,fstHandle> getMemoryHandles(std::string name);
58 double getTimescale() { return timescale; }
59 const char *getTimescaleString() { return timescale_str.c_str(); }
60 private:
61 void extractVarNames();
62
63 struct fstReaderContext *ctx;
64 std::vector<FstVar> vars;
65 std::map<fstHandle, FstVar> handle_to_var;
66 std::map<std::string, fstHandle> name_to_handle;
67 std::map<std::string, dict<int, fstHandle>> memory_to_handle;
68 std::map<fstHandle, std::string> last_data;
69 uint64_t last_time;
70 std::map<fstHandle, std::string> past_data;
71 uint64_t past_time;
72 double timescale;
73 std::string timescale_str;
74 uint64_t start_time;
75 uint64_t end_time;
76 CallbackFunction callback;
77 std::vector<fstHandle> clk_signals;
78 bool all_samples;
79 std::string tmp_file;
80 };
81
82 YOSYS_NAMESPACE_END
83
84 #endif