blob: f97740c180c0e259bae6695c0d3707a3e957d10e (
plain) (
blame)
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
|
#pragma once
#include "aisa/aisa.h"
namespace aisa {
template<typename CRTP> struct EvalState {
CRTP & crtp() noexcept { return static_cast<CRTP &>(*this); }
task<regval_t> async_load_reg(regnum_t rn)
{
while (true) {
if (auto rv = crtp().load_reg(rn); rv.has_value())
co_return *rv;
co_await suspend();
}
}
task<void> async_store_reg(regnum_t rn, regval_t rv)
{
while (true) {
if (crtp().store_reg(rn, rv))
co_return;
co_await suspend();
}
}
task<void> eval(const Step &step)
{
if (step.predicate.has_value()) {
regval_t pval = co_await async_load_reg(step.predicate->first);
if (pval != step.predicate->second)
co_return;
}
std::vector<regval_t> source_vals;
source_vals.reserve(step.source_regs.size());
for (unsigned int i = 0; i < step.source_regs.size(); ++i)
source_vals.emplace_back(co_await async_load_reg(step.source_regs[i]));
auto destination_vals = step.compute_destinations(source_vals);
for (unsigned int i = 0; i < step.destination_regs.size(); ++i)
co_await async_store_reg(step.destination_regs[i], destination_vals[i]);
}
};
}
|