File size: 5,051 Bytes
d1be154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#ifndef OT_HEADERDEF_HPP_
#define OT_HEADERDEF_HPP_

#include <iostream>
#include <iomanip>
#include <fstream>
#include <thread>
#include <sstream>
#include <mutex>
#include <shared_mutex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <chrono>
#include <dirent.h>
#include <vector>
#include <cstring>
#include <string_view>
#include <memory>
#include <map>
#include <future>
#include <atomic>
#include <list>
#include <forward_list>
#include <unordered_map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <functional>
#include <cstddef>
#include <type_traits>
#include <algorithm>
#include <cassert>
#include <random>
#include <regex>
#include <ratio>
#include <filesystem>
#include <optional>
#include <unistd.h>
#include <sys/wait.h>

// Clang mis-interprets variant's get as a non-friend of variant and cannot
// get compiled correctly. We use the patch: 
// https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=258854
// to get rid of this.
#if defined(__clang__)
#if __clang_major__ > 12
  #include <variant>
#else
  #include <ot/patch/clang_variant.hpp>
#endif
#else
  #include <variant>
#endif

// third-party include
#include <ot/taskflow/taskflow.hpp>
#include <ot/json/json.hpp>
#include <ot/parser-spef/parser-spef.hpp>
#include <ot/unit/units.hpp>

// Top header declaration.
#include <ot/config.hpp>

namespace ot {

using Json = nlohmann::json;

// --------------------------------------------------------

using namespace std::chrono_literals;
using namespace std::literals::string_literals;

enum Split {
  MIN = 0,
  MAX = 1
};

enum Tran {
  RISE = 0,
  FALL = 1
};

constexpr int MAX_SPLIT = 2;
constexpr int MAX_TRAN = 2;

// Function: to_string
inline auto to_string(Split m) {
  switch(m) {
    case MIN:
      return "min"s;
    break;

    case MAX:
      return "max"s;
    break;

    default:
      return "unknown split"s;
    break;
  };
}

// Function: to_string
inline auto to_string(Tran t) {
  switch(t) {
    case RISE:
      return "rise"s;
    break;

    case FALL:
      return "fall"s;
    break;

    default:
      return "unknown tran"s;
    break;
  };
}

inline std::ostream& operator << (std::ostream& os, Split t) {
  switch(t) {
    case MIN:
      os << "min";
    break;

    case MAX:
      os << "max";
    break;

    default:
      os << "unknown split";
    break;
  };
  return os;
}

inline std::ostream& operator << (std::ostream& os, Tran t) {
  switch(t) {
    case RISE:
      os << "rise";
    break;

    case FALL:
      os << "fall";
    break;

    default:
      os << "unknown tran";
    break;
  };
  return os;
}

// Function: to_string
inline auto to_string(Tran from, Tran to) {
  return to_string(from) + "->" + to_string(to);
}

// ------------------------------------------------------------------------------------------------  

constexpr std::initializer_list<Split> SPLIT = {MIN, MAX};

constexpr std::initializer_list<Tran> TRAN = {RISE, FALL};

constexpr std::initializer_list<std::pair<Split, Tran>> SPLIT_TRAN = { 
  {MIN, RISE},
  {MIN, FALL},
  {MAX, RISE},
  {MAX, FALL} 
};

constexpr std::initializer_list<std::pair<Tran, Tran>> TRANX2 = {
  {RISE, RISE},
  {RISE, FALL},
  {FALL, RISE},
  {FALL, FALL}
};

constexpr std::initializer_list<std::tuple<Split, Tran, Tran>> SPLIT_TRANx2 = {
  {MIN, RISE, RISE},
  {MIN, RISE, FALL},
  {MIN, FALL, RISE},
  {MIN, FALL, FALL},
  {MAX, RISE, RISE},
  {MAX, RISE, FALL},
  {MAX, FALL, RISE},
  {MAX, FALL, FALL}
};

// ------------------------------------------------------------------------------------------------  

#define FOR_EACH_EL(el) for(auto el : SPLIT)
#define FOR_EACH_RF(rf) for(auto rf : TRAN)
#define FOR_EACH_RF_RF(irf, orf) for(auto [irf, orf] : TRANX2)
#define FOR_EACH_EL_RF(el, rf) for(auto [el, rf] : SPLIT_TRAN)
#define FOR_EACH_EL_RF_RF(el, rf1, rf2) for(auto [el, rf1, rf2] : SPLIT_TRANx2)

#define FOR_EACH_EL_IF(el, c) for(auto el : SPLIT) if(c)
#define FOR_EACH_RF_IF(rf, c) for(auto rf : TRAN) if(c)
#define FOR_EACH_RF_RF_IF(irf, orf, c) for(auto [irf, orf] : TRANX2) if(c)
#define FOR_EACH_EL_RF_IF(el, rf, c) for(auto [el, rf] : SPLIT_TRAN) if(c)
#define FOR_EACH_EL_RF_RF_IF(el, rf1, rf2, c) for(auto [el, rf1, rf2] : SPLIT_TRANx2) if(c)

#define FOR_EACH(i, C) for(auto& i : C)
#define FOR_EACH_IF(i, C, s) for(auto& i : C) if(s)

// ------------------------------------------------------------------------------------------------  

// TimingData
template <typename, size_t ...>
struct TimingDataHelper;

template <typename T, size_t D0, size_t ... Ds>
struct TimingDataHelper<T, D0, Ds...> { 
  using type = std::array<typename TimingDataHelper<T, Ds...>::type, D0>; 
};

template <typename T>
struct TimingDataHelper<T>{ 
  using type = T; 
};

template <typename T, size_t ... Ds>
using TimingData = typename TimingDataHelper<T, Ds...>::type;




};  // End of namespace ot. -----------------------------------------------------------------------


#endif