From 003cea0d64e2ad01422dc49529117b9880ab6c95 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sun, 4 Nov 2018 13:27:43 +0000 Subject: [PATCH] Make 6502 symbols code a little more like normal C++ Signed-off-by: Adrian Conlon --- M6502/inc/Symbols.h | 31 +++++++++++++++---------------- M6502/src/Disassembly.cpp | 16 ++++++++-------- M6502/src/Profiler.cpp | 8 ++++---- M6502/src/Symbols.cpp | 30 +++++++++++++++--------------- 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/M6502/inc/Symbols.h b/M6502/inc/Symbols.h index fee91da..40fe6b9 100644 --- a/M6502/inc/Symbols.h +++ b/M6502/inc/Symbols.h @@ -10,28 +10,27 @@ namespace EightBit { public: Symbols(std::string path = "") noexcept; - const std::map& getLabels() const { return labels; } - const std::map& getConstants() const { return constants; } - const std::map& getScopes() const { return scopes; } - const std::map& getAddresses() const { return addresses; } + const std::map& labels() const { return m_labels; } + const std::map& constants() const { return m_constants; } + const std::map& scopes() const { return m_scopes; } + const std::map& addresses() const { return m_addresses; } private: - void AssignScopes(); - void AssignSymbols(); + static std::vector split(const std::string& input, const std::string& regex); - void Parse(std::string path); + void assignScopes(); + void assignSymbols(); - std::map labels; - std::map constants; - std::map scopes; - std::map addresses; + void parse(std::string path); + + std::map m_labels; + std::map m_constants; + std::map m_scopes; + std::map m_addresses; struct kv_pair_t { std::map element; }; - - static std::vector split(const std::string& input, const std::string& regex); - - std::map> parsed; + std::map> m_parsed; }; -} \ No newline at end of file +} diff --git a/M6502/src/Disassembly.cpp b/M6502/src/Disassembly.cpp index bf1caa0..efd7230 100644 --- a/M6502/src/Disassembly.cpp +++ b/M6502/src/Disassembly.cpp @@ -495,8 +495,8 @@ std::string EightBit::Disassembly::dump_Word(uint16_t address) { //// std::string EightBit::Disassembly::convertAddress(uint16_t address) const { - auto label = symbols.getLabels().find(address); - if (label != symbols.getLabels().end()) + auto label = symbols.labels().find(address); + if (label != symbols.labels().end()) return label->second; std::ostringstream output; output << "$" << dump_WordValue(address); @@ -504,8 +504,8 @@ std::string EightBit::Disassembly::convertAddress(uint16_t address) const { } std::string EightBit::Disassembly::convertAddress(uint8_t address) const { - auto label = symbols.getLabels().find(address); - if (label != symbols.getLabels().end()) + auto label = symbols.labels().find(address); + if (label != symbols.labels().end()) return label->second; std::ostringstream output; output << "$" << dump_ByteValue(address); @@ -513,15 +513,15 @@ std::string EightBit::Disassembly::convertAddress(uint8_t address) const { } std::string EightBit::Disassembly::convertConstant(uint16_t constant) { - auto label = symbols.getConstants().find(constant); - if (label != symbols.getConstants().end()) + auto label = symbols.constants().find(constant); + if (label != symbols.constants().end()) return label->second; return dump_DByte(constant); } std::string EightBit::Disassembly::convertConstant(uint8_t constant) const { - auto label = symbols.getConstants().find(constant); - if (label != symbols.getConstants().end()) + auto label = symbols.constants().find(constant); + if (label != symbols.constants().end()) return label->second; return dump_ByteValue(constant); } diff --git a/M6502/src/Profiler.cpp b/M6502/src/Profiler.cpp index df5e98a..206d5fd 100644 --- a/M6502/src/Profiler.cpp +++ b/M6502/src/Profiler.cpp @@ -44,7 +44,7 @@ void EightBit::Profiler::EmitProfileInformation() { for (auto& scopeCycle : scopeCycles) { auto name = scopeCycle.first; auto cycles = scopeCycle.second; - auto namedAddress = (size_t)symbols.getAddresses().find(name)->second; + auto namedAddress = (size_t)symbols.addresses().find(name)->second; auto count = addressCounts[namedAddress]; EmitScope.fire(ProfileScopeEventArgs(name, cycles, count)); } @@ -70,11 +70,11 @@ void EightBit::Profiler::addAddress(uint16_t address, int cycles) { } void EightBit::Profiler::BuildAddressScopes() { - for (auto& label : symbols.getLabels()) { + for (auto& label : symbols.labels()) { auto address = label.first; auto key = label.second; - auto scope = symbols.getScopes().find(key); - if (scope != symbols.getScopes().end()) { + auto scope = symbols.scopes().find(key); + if (scope != symbols.scopes().end()) { for (uint16_t i = address; i < address + scope->second; ++i) { addressScopes[i] = key; } diff --git a/M6502/src/Symbols.cpp b/M6502/src/Symbols.cpp index 1a4183b..c2e7623 100644 --- a/M6502/src/Symbols.cpp +++ b/M6502/src/Symbols.cpp @@ -7,25 +7,25 @@ EightBit::Symbols::Symbols(std::string path) noexcept { if (!path.empty()) { - Parse(path); - AssignSymbols(); - AssignScopes(); + parse(path); + assignSymbols(); + assignScopes(); } } -void EightBit::Symbols::AssignScopes() { - auto parsedScopes = parsed["scope"]; +void EightBit::Symbols::assignScopes() { + auto parsedScopes = m_parsed["scope"]; for(auto& parsedScopeElement : parsedScopes) { auto& parsedScope = parsedScopeElement.second.element; auto name = parsedScope["name"]; auto trimmedName = name.substr(1, name.length() - 2); auto size = parsedScope["size"]; - scopes[trimmedName] = (uint16_t)std::stoi(size); + m_scopes[trimmedName] = (uint16_t)std::stoi(size); } } -void EightBit::Symbols::AssignSymbols() { - auto symbols = parsed["sym"]; +void EightBit::Symbols::assignSymbols() { + auto symbols = m_parsed["sym"]; for(auto& symbolElement : symbols) { auto& symbol = symbolElement.second.element; auto name = symbol["name"]; @@ -34,15 +34,15 @@ void EightBit::Symbols::AssignSymbols() { auto number = (uint16_t)std::stoi(value, nullptr, 16); auto symbolType = symbol["type"]; if (symbolType == "lab") { - labels[number] = trimmedName; - addresses[trimmedName] = number; + m_labels[number] = trimmedName; + m_addresses[trimmedName] = number; } else if (symbolType == "equ") { - constants[number] = trimmedName; + m_constants[number] = trimmedName; } } } -void EightBit::Symbols::Parse(std::string path) { +void EightBit::Symbols::parse(std::string path) { std::string line; std::ifstream reader(path); while (std::getline(reader, line)) { @@ -58,11 +58,11 @@ void EightBit::Symbols::Parse(std::string path) { } if (data.element.find("id") != data.element.end()) { - if (parsed.find(type) == parsed.end()) - parsed[type] = std::map(); + if (m_parsed.find(type) == m_parsed.end()) + m_parsed[type] = std::map(); auto id = data.element["id"]; data.element.erase("id"); - parsed[type][id] = data; + m_parsed[type][id] = data; } } }