File size: 4,111 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 | #include <ot/tau/tau15.hpp>
#include <ot/timer/timer.hpp>
namespace ot::tau15 {
// Procedure: read
void Timing::read(const std::filesystem::path& path) {
std::string line, token, pin;
// ------------------------------------------------------
// Read timing file.
// ------------------------------------------------------
std::ifstream tfs(path);
if(!tfs.good()) {
OT_LOGE("can't open timing assertions ", path);
return;
}
while(std::getline(tfs, line)) {
std::istringstream ss(line);
ss >> token;
if(token == "clock") {
Clock clock;
ss >> clock.pin >> clock.period;
assertions.push_back(std::move(clock));
}
else if(token == "at") {
AT at;
ss >> at.pin
>> at.value[ot::MIN][ot::RISE] >> at.value[ot::MIN][ot::FALL]
>> at.value[ot::MAX][ot::RISE] >> at.value[ot::MAX][ot::FALL];
assertions.push_back(std::move(at));
}
else if(token == "slew") {
Slew slew;
ss >> slew.pin
>> slew.value[ot::MIN][ot::RISE] >> slew.value[ot::MIN][ot::FALL]
>> slew.value[ot::MAX][ot::RISE] >> slew.value[ot::MAX][ot::FALL];
assertions.push_back(std::move(slew));
}
else if(token == "rat") {
RAT rat;
ss >> rat.pin
>> rat.value[ot::MIN][ot::RISE] >> rat.value[ot::MIN][ot::FALL]
>> rat.value[ot::MAX][ot::RISE] >> rat.value[ot::MAX][ot::FALL];
assertions.push_back(std::move(rat));
}
else if(token == "load") {
Load load;
ss >> load.pin >> load.value;
assertions.push_back(std::move(load));
}
else {
OT_LOGF("unknown keyword ", token);
}
}
}
}; // end of namespace ot::tau15. ----------------------------------------------------------------
namespace ot {
// Function: read_timing
Timer& Timer::read_timing(std::filesystem::path path) {
auto timing = std::make_shared<tau15::Timing>();
std::scoped_lock lock(_mutex);
auto parser = _taskflow.emplace([path=std::move(path), timing] () {
OT_LOGI("loading timing ", path, " ...");
timing->read(path);
});
auto reader = _taskflow.emplace([this, timing] () {
OT_LOGI("add ", timing->assertions.size(), " timing assertions");
_timing(*timing);
});
// Reader -> modifier
parser.precede(reader);
_add_to_lineage(reader);
return *this;
}
// Procedure: _timing
void Timer::_timing(tau15::Timing& timing) {
for(auto& ast : timing.assertions) {
std::visit(Functors{
[&] (tau15::Clock& clock) {
if(auto itr = _pins.find(clock.pin); itr != _pins.end()) {
_create_clock(itr->first, itr->second, clock.period);
}
else {
OT_LOGE("can't create clock (pin ", clock.pin, " not found)");
}
},
[&] (tau15::AT& a) {
if(auto itr = _pis.find(a.pin); itr != _pis.end()) {
FOR_EACH_EL_RF(el, rf) {
_set_at(itr->second, el, rf, a.value[el][rf]);
}
}
else {
OT_LOGE("can't set arrival time (PI ", a.pin, " not found)");
}
},
[&] (tau15::Slew& s) {
if(auto itr = _pis.find(s.pin); itr != _pis.end()) {
FOR_EACH_EL_RF(el, rf) {
_set_slew(itr->second, el, rf, s.value[el][rf]);
}
}
else {
OT_LOGE("can't set slew (PI ", s.pin, " not found)");
}
},
[&] (tau15::RAT& r) {
if(auto itr = _pos.find(r.pin); itr != _pos.end()) {
FOR_EACH_EL_RF(el, rf) {
_set_rat(itr->second, el, rf, r.value[el][rf]);
}
}
else {
OT_LOGE("can't set rat (PO ", r.pin, " not found)");
}
},
[&] (tau15::Load& l) {
if(auto itr = _pos.find(l.pin); itr != _pos.end()) {
FOR_EACH_EL_RF(el, rf) {
_set_load(itr->second, el, rf, l.value);
}
}
else {
OT_LOGE("can't set load (PO ", l.pin, " not found)");
}
}
}, ast);
}
}
}; // end of namespace ot ------------------------------------------------------------------------
|