blob: 8cb302e567dbee8903ce4109916509484b47ce88 (
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
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
|
#pragma once
#include <coroutine>
#include <cstdint>
#include <iostream>
#include <optional>
#include <utility>
#include <vector>
#include "aisa/coroutine.h"
namespace aisa {
using regnum_t = std::uint_fast64_t;
using regval_t = std::uint64_t;
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();
}
}
};
struct Step {
const std::optional<std::pair<regnum_t, regval_t>> predicate;
const std::vector<regnum_t> source_regs;
const std::vector<regnum_t> destination_regs;
std::optional<regnum_t> predicate_reg() const
{
if (predicate.has_value())
return predicate->first;
return {};
}
std::optional<regnum_t> expected_predicate_val() const
{
if (predicate.has_value())
return predicate->second;
return {};
}
template<typename State> task<void> evaluate(State &state) const
{
if (predicate.has_value()) {
std::cout << "checking predicate...\n";
std::cout << "\texpect " << predicate->second << "\n";
regval_t pval = co_await state.async_load_reg(predicate->first);
std::cout << "\tgot " << pval << "\n";
if (pval != predicate->second) {
std::cout << "\tpredicate skipped\n";
co_return;
} else {
std::cout << "\tpredicate not skipped\n";
}
}
std::cout << "reading sources...\n";
std::vector<regval_t> source_vals;
source_vals.reserve(source_regs.size());
for (unsigned int i = 0; i < source_regs.size(); ++i) {
std::cout << "\tgetting source " << i << "...\n";
source_vals.emplace_back(co_await state.async_load_reg(source_regs[i]));
std::cout << "\t\tgot " << source_vals.back() << "\n";
}
std::cout << "sources:";
for (unsigned int i = 0; i < source_regs.size(); ++i)
std::cout << " " << source_regs[i] << "=" << source_vals[i];
std::cout << "\n";
std::cout << "done with evaluate\n";
}
};
}
|