blob: 9fb7a52b6ee1ce683bc586cc7196033102e0609e (
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
|
#include "segment.h"
#include "operators.h"
using namespace std::string_literals;
size_t Segment::getAddressOfLabel(const std::string& label)
{
size_t address{0};
auto i{begin()};
while (i != end()) {
Chunk& chunk{**i};
address += chunk.size();
if (typeid(chunk) == typeid(Label)) {
if (dynamic_cast<Label&>(chunk).name() == label) {
return address;
}
}
}
throw std::runtime_error("Bad label: "s + label);
}
std::vector<uint8_t> Segment::getCode()
{
std::vector<uint8_t> result;
for (const auto& chunk: *this)
result = result + chunk->getCode();
return result;
}
void Segment::insertAddresses()
{
}
void Segment::optimize()
{
// TODO
}
|