cleanup
[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 struct FstVar
29 {
30 fstHandle id;
31 std::string name;
32 bool is_alias;
33 std::string scope;
34 int width;
35 };
36
37 class FstData
38 {
39 public:
40 FstData(std::string filename);
41 ~FstData();
42
43 uint64_t getStartTime();
44 uint64_t getEndTime();
45
46 std::vector<FstVar>& getVars() { return vars; };
47
48 void reconstruct_edges_callback(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen);
49 std::vector<uint64_t> getAllEdges(std::vector<fstHandle> &signal, uint64_t start_time, uint64_t end_time);
50
51 void reconstruct_callback_attimes(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen);
52 void reconstructAtTimes(std::vector<fstHandle> &signal,std::vector<uint64_t> time);
53 void reconstructAllAtTimes(std::vector<uint64_t> time);
54
55 std::string valueAt(fstHandle signal, uint64_t time);
56 fstHandle getHandle(std::string name);
57 double getTimescale() { return timescale; }
58 private:
59 void extractVarNames();
60
61 struct fstReaderContext *ctx;
62 std::vector<std::string> scopes;
63 std::vector<FstVar> vars;
64 std::map<fstHandle, FstVar> handle_to_var;
65 std::map<std::string, fstHandle> name_to_handle;
66 std::map<fstHandle, std::vector<std::pair<uint64_t, std::string>>> handle_to_data;
67 std::map<fstHandle, std::string> last_data;
68 std::map<fstHandle, std::map<uint64_t, size_t>> time_to_index;
69 std::vector<uint64_t> sample_times;
70 size_t sample_times_ndx;
71 double timescale;
72 uint64_t start_time;
73 uint64_t end_time;
74 std::vector<uint64_t> edges;
75 };
76
77 YOSYS_NAMESPACE_END
78
79 #endif