1 #ifndef OT_HEADERDEF_HPP_
2 #define OT_HEADERDEF_HPP_
3
4 #include <iostream>
5 #include <iomanip>
6 #include <fstream>
7 #include <thread>
8 #include <sstream>
9 #include <mutex>
10 #include <shared_mutex>
11 #include <cstdio>
12 #include <cstdlib>
13 #include <ctime>
14 #include <chrono>
15 #include <dirent.h>
16 #include <vector>
17 #include <cstring>
18 #include <string_view>
19 #include <memory>
20 #include <map>
21 #include <future>
22 #include <atomic>
23 #include <list>
24 #include <forward_list>
25 #include <unordered_map>
26 #include <set>
27 #include <stack>
28 #include <queue>
29 #include <deque>
30 #include <tuple>
31 #include <unordered_set>
32 #include <numeric>
33 #include <iterator>
34 #include <functional>
35 #include <cstddef>
36 #include <type_traits>
37 #include <algorithm>
38 #include <cassert>
39 #include <random>
40 #include <regex>
41 #include <ratio>
42 #include <filesystem>
43 #include <optional>
44 #include <unistd.h>
45 #include <sys/wait.h>
46
47 // Clang mis-interprets variant's get as a non-friend of variant and cannot
48 // get compiled correctly. We use the patch:
49 // https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=258854
50 // to get rid of this.
51 #if defined(__clang__)
52 #include <ot/patch/clang_variant.hpp>
53 #else
54 #include <variant>
55 #endif
56
57 // third-party include
58 #include <ot/taskflow/taskflow.hpp>
59 #include <ot/json/json.hpp>
60 #include <ot/parser-spef/parser-spef.hpp>
61 #include <ot/unit/units.hpp>
62
63 // Top header declaration.
64 #include <ot/config.hpp>
65
66 namespace ot {
67
68 using Json = nlohmann::json;
69
70 // --------------------------------------------------------
71
72 using namespace std::chrono_literals;
73 using namespace std::literals::string_literals;
74
75 enum Split {
76 MIN = 0,
77 MAX = 1
78 };
79
80 enum Tran {
81 RISE = 0,
82 FALL = 1
83 };
84
85 constexpr int MAX_SPLIT = 2;
86 constexpr int MAX_TRAN = 2;
87
88 // Function: to_string
to_string(Split m)89 inline auto to_string(Split m) {
90 switch(m) {
91 case MIN:
92 return "min"s;
93 break;
94
95 case MAX:
96 return "max"s;
97 break;
98
99 default:
100 return "unknown split"s;
101 break;
102 };
103 }
104
105 // Function: to_string
to_string(Tran t)106 inline auto to_string(Tran t) {
107 switch(t) {
108 case RISE:
109 return "rise"s;
110 break;
111
112 case FALL:
113 return "fall"s;
114 break;
115
116 default:
117 return "unknown tran"s;
118 break;
119 };
120 }
121
operator <<(std::ostream & os,Split t)122 inline std::ostream& operator << (std::ostream& os, Split t) {
123 switch(t) {
124 case MIN:
125 os << "min";
126 break;
127
128 case MAX:
129 os << "max";
130 break;
131
132 default:
133 os << "unknown split";
134 break;
135 };
136 return os;
137 }
138
operator <<(std::ostream & os,Tran t)139 inline std::ostream& operator << (std::ostream& os, Tran t) {
140 switch(t) {
141 case RISE:
142 os << "rise";
143 break;
144
145 case FALL:
146 os << "fall";
147 break;
148
149 default:
150 os << "unknown tran";
151 break;
152 };
153 return os;
154 }
155
156 // Function: to_string
to_string(Tran from,Tran to)157 inline auto to_string(Tran from, Tran to) {
158 return to_string(from) + "->" + to_string(to);
159 }
160
161 // ------------------------------------------------------------------------------------------------
162
163 constexpr std::initializer_list<Split> SPLIT = {MIN, MAX};
164
165 constexpr std::initializer_list<Tran> TRAN = {RISE, FALL};
166
167 constexpr std::initializer_list<std::pair<Split, Tran>> SPLIT_TRAN = {
168 {MIN, RISE},
169 {MIN, FALL},
170 {MAX, RISE},
171 {MAX, FALL}
172 };
173
174 constexpr std::initializer_list<std::pair<Tran, Tran>> TRANX2 = {
175 {RISE, RISE},
176 {RISE, FALL},
177 {FALL, RISE},
178 {FALL, FALL}
179 };
180
181 constexpr std::initializer_list<std::tuple<Split, Tran, Tran>> SPLIT_TRANx2 = {
182 {MIN, RISE, RISE},
183 {MIN, RISE, FALL},
184 {MIN, FALL, RISE},
185 {MIN, FALL, FALL},
186 {MAX, RISE, RISE},
187 {MAX, RISE, FALL},
188 {MAX, FALL, RISE},
189 {MAX, FALL, FALL}
190 };
191
192 // ------------------------------------------------------------------------------------------------
193
194 #define FOR_EACH_EL(el) for(auto el : SPLIT)
195 #define FOR_EACH_RF(rf) for(auto rf : TRAN)
196 #define FOR_EACH_RF_RF(irf, orf) for(auto [irf, orf] : TRANX2)
197 #define FOR_EACH_EL_RF(el, rf) for(auto [el, rf] : SPLIT_TRAN)
198 #define FOR_EACH_EL_RF_RF(el, rf1, rf2) for(auto [el, rf1, rf2] : SPLIT_TRANx2)
199
200 #define FOR_EACH_EL_IF(el, c) for(auto el : SPLIT) if(c)
201 #define FOR_EACH_RF_IF(rf, c) for(auto rf : TRAN) if(c)
202 #define FOR_EACH_RF_RF_IF(irf, orf, c) for(auto [irf, orf] : TRANX2) if(c)
203 #define FOR_EACH_EL_RF_IF(el, rf, c) for(auto [el, rf] : SPLIT_TRAN) if(c)
204 #define FOR_EACH_EL_RF_RF_IF(el, rf1, rf2, c) for(auto [el, rf1, rf2] : SPLIT_TRANx2) if(c)
205
206 #define FOR_EACH(i, C) for(auto& i : C)
207 #define FOR_EACH_IF(i, C, s) for(auto& i : C) if(s)
208
209 // ------------------------------------------------------------------------------------------------
210
211 // TimingData
212 template <typename, size_t ...>
213 struct TimingDataHelper;
214
215 template <typename T, size_t D0, size_t ... Ds>
216 struct TimingDataHelper<T, D0, Ds...> {
217 using type = std::array<typename TimingDataHelper<T, Ds...>::type, D0>;
218 };
219
220 template <typename T>
221 struct TimingDataHelper<T>{
222 using type = T;
223 };
224
225 template <typename T, size_t ... Ds>
226 using TimingData = typename TimingDataHelper<T, Ds...>::type;
227
228
229
230
231 }; // End of namespace ot. -----------------------------------------------------------------------
232
233
234 #endif
235
236