From f86999e137f43372236f2dccd1fe3572a85c0dcd Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 17 Oct 2020 14:16:46 +0200 Subject: Separate-out assembler --- asm/segment.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 asm/segment.cpp (limited to 'asm/segment.cpp') 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(chunk).name() == label) { + return address; + } + } + } + + throw std::runtime_error("Bad label: "s + label); + } -- cgit v1.2.3