blob: 60b8348c820972394c5782130b7529632e221794 (
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
|
#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;
}
|