From 8a8ddfec22adda55f96b5a72d209035231986b54 Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+weebdatahoarder@users.noreply.github.com> Date: Tue, 3 Aug 2021 18:47:13 +0200 Subject: [PATCH] Added .reserve to allocate static registers in scratch space without specifying hardcoded values (set to none or 0) --- src/Parser.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index 608b530..ce3cd38 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -230,12 +230,29 @@ void Parser::parse() { } if (!currentDeclaration.tokens.empty()) { - if (currentDeclaration.tokens.size() >= 3 && - currentDeclaration.tokens.at(0).getType() == Token::Type::Directive) { - + if (currentDeclaration.tokens.size() >= 2 && currentDeclaration.tokens.at(0).getType() == Token::Type::Directive && currentDeclaration.tokens.at(0).getTextValue() == ".reserve") { if (currentDeclaration.tokens.at(0).getTextValue() == ".reserve") { - if(reservations.find(currentDeclaration.tokens.at(2).getNumericValue()) == reservations.end()){ - uint32_t addr = currentDeclaration.tokens.at(2).getNumericValue(); + uint32_t addr; + bool foundValue = false; + + if(currentDeclaration.tokens.size() == 2 || currentDeclaration.tokens.at(2).getNumericValue() == 0){ + uint32_t scratchSize = (uint32_t) MgmtRegisters::BSM_SCRATCH_END - (uint32_t) MgmtRegisters::BSM_SCRATCH_START; + addr = 0; + for(; addr <= scratchSize; ++addr){ + if(reservations.find(addr) == reservations.end()){ + //Found value! + foundValue = true; + break; + } + } + }else{ + addr = currentDeclaration.tokens.at(2).getNumericValue(); + foundValue = true; + } + + if(!foundValue){ + throw std::runtime_error("Could not find reservation " + currentDeclaration.tokens.at(1).getTextValue() + " for value " + std::to_string(addr)); + }else if(reservations.find(addr) == reservations.end()){ reservations[addr] = currentDeclaration.tokens.at(1).getTextValue(); variables[currentDeclaration.tokens.at(1).getTextValue()] = {Token(Token::Type::RegisterLocation, std::to_string((uint32_t) MgmtRegisters::BSM_SCRATCH_START + addr), (uint32_t) MgmtRegisters::BSM_SCRATCH_START + addr)}; }else{ @@ -244,6 +261,9 @@ void Parser::parse() { } } + currentDeclaration = Declaration(); + currentStateIndex = 0; + }else if (currentDeclaration.tokens.size() >= 3 && currentDeclaration.tokens.at(0).getType() == Token::Type::Directive) { if (currentDeclaration.tokens.at(0).getTextValue() == ".constant") { std::vector tokens; for (auto it = currentDeclaration.tokens.begin() + 2;