blob: 723e71124daf94832bbca50fa20957cacad0303c (
plain)
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
79
|
// Chunk data type, and derived types
#pragma once
#include <cstdint>
#include <string>
#include <vector>
class Chunk
{
public:
virtual ~Chunk(){}
virtual std::vector<uint8_t> getCode() = 0;
virtual size_t size() = 0; ///< returns size in bytes
};
class Label: public Chunk
{
public:
Label(const std::string& name) : m_name(name) {}
std::string name(){return m_name;}
std::vector<uint8_t> getCode() override { return {}; }
size_t size() override { return 0; }
private:
std::string m_name;
};
class Data: public Chunk
{
public:
Data(std::vector<uint8_t> data): m_data(data) {}
virtual ~Data(){}
std::vector<uint8_t> getCode() override
{
return m_data;
}
size_t size() override
{
return m_data.size();
}
protected:
std::vector<uint8_t> m_data;
};
class Op: public Chunk
{
public:
virtual ~Op(){};
virtual bool optimize() = 0; ///< returns true if changed
};
class OpSimple: public Op
{
public:
OpSimple(std::vector<uint8_t> machine_code): machine_code(machine_code) {}
std::vector<uint8_t> getCode() override
{
return machine_code;
}
size_t size() override
{
return machine_code.size();
}
bool optimize() override ///< returns true if changed
{
return false;
}
protected:
std::vector<uint8_t> machine_code;
};
|