diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-10-17 14:16:46 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-10-17 14:16:46 +0200 |
commit | f86999e137f43372236f2dccd1fe3572a85c0dcd (patch) | |
tree | fedfeec810d22dde57073c5b51ecf1a4253a9c61 /asm/segment.cpp | |
parent | 85e9768c6a083165ef8376d2924f5d82ce91d118 (diff) |
Separate-out assembler
Diffstat (limited to 'asm/segment.cpp')
-rw-r--r-- | asm/segment.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/asm/segment.cpp b/asm/segment.cpp new file mode 100644 index 0000000..db83941 --- /dev/null +++ b/asm/segment.cpp @@ -0,0 +1,20 @@ +#include "segment.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); + } |