22 const std::vector<bool>::const_iterator &
endpos,
65 const std::vector<bool>::const_iterator &
endpos) {
72 const std::vector<bool>::const_iterator &
endpos) {
78 const std::vector<bool>::const_iterator &
endpos) {
82const std::vector<uint8_t>
JUMP_BIT_SIZES{5, 6, 7, 8, 9, 10, 11, 12, 13,
83 14, 15, 16, 17, 18, 19, 20, 21, 22,
84 23, 24, 25, 26, 27, 28, 29, 30};
86 const std::vector<bool>::const_iterator &
endpos) {
93 const std::vector<bool> &ip) {
94 std::vector<bool>::const_iterator pos =
asmap.begin();
95 const std::vector<bool>::const_iterator
endpos =
asmap.end();
102 if (opcode == Instruction::RETURN) {
109 }
else if (opcode == Instruction::JUMP) {
119 if (pos +
jump < pos) {
127 if (ip[ip.size() - bits]) {
131 }
else if (opcode == Instruction::MATCH) {
143 if ((ip[ip.size() - bits]) !=
149 }
else if (opcode == Instruction::DEFAULT) {
170 const std::vector<bool>::const_iterator begin =
asmap.begin(),
172 std::vector<bool>::const_iterator pos = begin;
175 std::vector<std::pair<uint32_t, int>>
jumps;
186 if (opcode == Instruction::RETURN) {
221 bits =
jumps.back().second;
225 }
else if (opcode == Instruction::JUMP) {
231 if (pos +
jump < pos) {
251 }
else if (opcode == Instruction::MATCH) {
273 }
else if (opcode == Instruction::DEFAULT) {
295 std::vector<bool> bits;
299 LogPrintf(
"Failed to open asmap file from disk\n");
304 LogPrintf(
"Opened asmap file %s (%d bytes) from disk\n",
308 for (
int i = 0; i <
length; ++i) {
315 LogPrintf(
"Sanity check of asmap file %s failed\n",
uint32_t Interpret(const std::vector< bool > &asmap, const std::vector< bool > &ip)
std::vector< bool > DecodeAsmap(fs::path path)
Read asmap from provided binary file.
bool SanityCheckASMap(const std::vector< bool > &asmap, int bits)
Non-refcounted RAII wrapper for FILE*.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static uint64_t CountBits(uint64_t x)
Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set.
static auto quoted(const std::string &s)
static std::string PathToString(const path &path)
Convert path object to byte string.
FILE * fopen(const fs::path &p, const char *mode)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...