-
Notifications
You must be signed in to change notification settings - Fork 1
/
executable.hpp
69 lines (53 loc) · 1.21 KB
/
executable.hpp
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
#ifndef EXECUTABLE_HPP
#define EXECUTABLE_HPP
#include <vector>
#include <string>
#include <fstream>
#include <cstdint>
#include <exception>
/*
* Executable.
*/
class Executable {
public:
/*
* All opcodes and operands are 32-bit.
* Random values are specified by 0 if applicable.
*/
typedef std::uint32_t Word;
typedef std::vector<Word> Bytecode;
enum {
InsnEat,
InsnGo,
InsnClon,
InsnStr,
InsnLeft,
InsnRight,
InsnBack,
InsnTurn,
InsnJG,
InsnJL,
InsnJ,
InsnJE,
InsnMax = InsnJE
};
Executable() {}
Executable(const std::string &path);
const Bytecode &getBytecode() const {return bytecode;}
std::size_t size() const {return bytecode.size();}
Word operator[](std::size_t i) const {return bytecode[i];}
private:
Bytecode bytecode;
};
/*
* ExecutableError.
*/
class ExecutableError : public std::exception {
private:
std::string reason;
public:
ExecutableError(const std::string &path, int line);
virtual const char *what() const noexcept {return reason.c_str();}
};
const std::string &DisasmOpcode(Executable::Word opcode);
#endif