-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemulator.cpp
More file actions
39 lines (38 loc) · 1.16 KB
/
Copy pathemulator.cpp
File metadata and controls
39 lines (38 loc) · 1.16 KB
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
#include "vm.h"
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <type_traits>
#include <vector>
int main(int argc, char const **argv) {
assert(argc == 2);
VM vm;
std::ifstream input(*++argv, std::ios::binary);
for (auto i = vm.memory; input.read(reinterpret_cast<char *>(i), sizeof(uint32_t)); i += sizeof(uint32_t))
;
std::vector<regular::Register> registers;
std::transform(regular::register_names.begin(), regular::register_names.end(), std::back_inserter(registers), [](auto &&pair) {
return pair.first;
});
std::sort(registers.begin(), registers.end(), [](auto register1, auto register2) {
return static_cast<std::underlying_type_t<decltype(register1)>>(register1) <
static_cast<std::underlying_type_t<decltype(register2)>>(register2);
});
while (true) {
std::visit([](auto &&instruction) {
std::cout << "Executing: " << instruction << std::endl;
},
vm.step());
int i = 0;
for (auto r : registers) {
std::printf("%3s = 0x%08x ", regular::register_names[r], vm.registers[r]);
if (!(++i % 4)) {
std::cout << std::endl;
}
}
std::cout << std::endl;
}
return 0;
}