Made FASTCALL cleanup stack values, fixed Ret instruction taking m[offset] instead of m[m[offset]]
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2021-01-03 05:31:51 +01:00
parent d70d63ee24
commit 624fad1319
4 changed files with 15 additions and 6 deletions

View file

@ -78,12 +78,12 @@ namespace Instruction {
std::unique_ptr<Instruction> Ret::fromTokens(const Instruction::Instruction::parseOperatorResult &op,
const std::vector<Token> &tokens) {
return std::make_unique<Ret>(tokens.empty() ? 0 : tokens.at(0).getNumericValue());
return std::make_unique<Ret>();
}
Ret::Ret(uint32_t count) {
instructions.push_back(std::make_unique<Stack::PopImm>(count + 1));
instructions.push_back(std::make_unique<Return>(AddressWithOffset{Stack::stackOffsetRegisterAddress, 0}));
Ret::Ret() {
instructions.push_back(std::make_unique<Stack::PopImm>(1));
instructions.push_back(std::make_unique<Return>(AddressWithOffset{0, Stack::stackOffsetRegister}));
}
}

View file

@ -60,7 +60,7 @@ namespace Instruction {
std::vector<std::unique_ptr<Instruction>> instructions;
public:
explicit Ret(uint32_t count = 0);
explicit Ret();
CommandOp getCommand() const override {
return CommandOp::END;

View file

@ -46,11 +46,19 @@ namespace Instruction{
FastCall::FastCall(uint32_t address, const std::vector<Token> &data) {
initData(data);
instructions.push_back(std::make_unique<Call>(address));
takedownData(data);
}
FastCall::FastCall(const AddressWithOffset &address, const std::vector<Token> &data) {
initData(data);
instructions.push_back(std::make_unique<Call>(address));
takedownData(data);
}
void FastCall::takedownData(const std::vector<Token> &data) {
if(data.size() > 2){
instructions.push_back(std::make_unique<Stack::PopImm>(data.size() - 2));
}
}
void FastCall::initData(const std::vector<Token> &data) {

View file

@ -30,11 +30,12 @@
#include "../Instruction.h"
namespace Instruction {
//Akin to __fastcall
//Akin to __fastcall, but the caller cleans up the stack
class FastCall : public Instruction {
private:
std::vector<std::unique_ptr<Instruction>> instructions;
void initData(const std::vector<Token>& data);
void takedownData(const std::vector<Token>& data);
public:
explicit FastCall(const AddressWithOffset& address, const std::vector<Token>& data);