summaryrefslogtreecommitdiffhomepage
path: root/asm/segment.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-10-17 17:37:50 +0200
committerRoland Reichwein <mail@reichwein.it>2020-10-17 17:37:50 +0200
commit7b49d17f90f26394a116348befb5edcdffcedcb6 (patch)
treec32e76a9bea5851bfac92708fa626373573e4f06 /asm/segment.cpp
parentf86999e137f43372236f2dccd1fe3572a85c0dcd (diff)
Add ret and int
Diffstat (limited to 'asm/segment.cpp')
-rw-r--r--asm/segment.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/asm/segment.cpp b/asm/segment.cpp
index db83941..60b8348 100644
--- a/asm/segment.cpp
+++ b/asm/segment.cpp
@@ -1,20 +1,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;
- }
+{
+ 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);
}
+
+ 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;
+}