mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-22 09:30:32 +00:00
Make 6502 symbols code a little more like normal C++
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
95968cb000
commit
003cea0d64
@ -10,28 +10,27 @@ namespace EightBit {
|
||||
public:
|
||||
Symbols(std::string path = "") noexcept;
|
||||
|
||||
const std::map<uint16_t, std::string>& getLabels() const { return labels; }
|
||||
const std::map<uint16_t, std::string>& getConstants() const { return constants; }
|
||||
const std::map<std::string, uint16_t>& getScopes() const { return scopes; }
|
||||
const std::map<std::string, uint64_t>& getAddresses() const { return addresses; }
|
||||
const std::map<uint16_t, std::string>& labels() const { return m_labels; }
|
||||
const std::map<uint16_t, std::string>& constants() const { return m_constants; }
|
||||
const std::map<std::string, uint16_t>& scopes() const { return m_scopes; }
|
||||
const std::map<std::string, uint64_t>& addresses() const { return m_addresses; }
|
||||
|
||||
private:
|
||||
void AssignScopes();
|
||||
void AssignSymbols();
|
||||
static std::vector<std::string> split(const std::string& input, const std::string& regex);
|
||||
|
||||
void Parse(std::string path);
|
||||
void assignScopes();
|
||||
void assignSymbols();
|
||||
|
||||
std::map<uint16_t, std::string> labels;
|
||||
std::map<uint16_t, std::string> constants;
|
||||
std::map<std::string, uint16_t> scopes;
|
||||
std::map<std::string, uint64_t> addresses;
|
||||
void parse(std::string path);
|
||||
|
||||
std::map<uint16_t, std::string> m_labels;
|
||||
std::map<uint16_t, std::string> m_constants;
|
||||
std::map<std::string, uint16_t> m_scopes;
|
||||
std::map<std::string, uint64_t> m_addresses;
|
||||
|
||||
struct kv_pair_t {
|
||||
std::map<std::string, std::string> element;
|
||||
};
|
||||
|
||||
static std::vector<std::string> split(const std::string& input, const std::string& regex);
|
||||
|
||||
std::map<std::string, std::map<std::string, kv_pair_t>> parsed;
|
||||
std::map<std::string, std::map<std::string, kv_pair_t>> m_parsed;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<std::string, kv_pair_t>();
|
||||
if (m_parsed.find(type) == m_parsed.end())
|
||||
m_parsed[type] = std::map<std::string, kv_pair_t>();
|
||||
auto id = data.element["id"];
|
||||
data.element.erase("id");
|
||||
parsed[type][id] = data;
|
||||
m_parsed[type][id] = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user