"jal" command fixes
This commit is contained in:
@@ -59,3 +59,15 @@ void Manager::init(const std::string &program_path) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::streampos Manager::getNextStreamLineOffset() {
|
||||
/// Speichert das aktuelle stream offset
|
||||
const auto positionBefore = m_programFile.tellg();
|
||||
/// Geht eine Zeile nach vorne zum nächsten Befehl (PC+4) und speichert den offset
|
||||
std::string line;
|
||||
std::getline(m_programFile, line);
|
||||
const auto positionAfter = m_programFile.tellg();
|
||||
/// Geht zum offset vom Anfang zurück und gibt die nächste Adresse (PC+4) zurück
|
||||
m_programFile.seekg(positionBefore);
|
||||
return positionAfter;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,13 @@ public:
|
||||
* @param program_path Der Pfad zur Quellcode .txt
|
||||
*/
|
||||
void init(const std::string &program_path);
|
||||
|
||||
/**
|
||||
* Gibt das stream offset für den nächsten Befehl (PC+4) zurück
|
||||
*
|
||||
* @return Die stream offset Position ("Zeilennummer") des nächsten Befehls
|
||||
*/
|
||||
std::streampos getNextStreamLineOffset();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -130,12 +130,14 @@ void Alu::calculate(const std::vector<std::string> &commandVector) {
|
||||
}
|
||||
} else if (command == "jal") {
|
||||
/// Jump and link Befehl
|
||||
/// !!! Funktioniert nicht bei großen Daten aufgrund des casts des stream offsets zu int
|
||||
const auto pos = static_cast<int>(Manager::getInstance()->getStreamPosition().operator std::streamoff());
|
||||
/// !!! Aufgrund des casts des stream offsets zu int funktioniert das nicht bei großen Quellcode Dateien
|
||||
/// und führt zu undefiniertem Verhalten !!!
|
||||
const auto pos = static_cast<int>(Manager::getInstance()->getNextStreamLineOffset().operator std::streamoff());
|
||||
const auto &label = commandVector.at(2);
|
||||
const auto streamPos = ProgramLoader::getInstance()->getStreamPosition(label);
|
||||
Register::getInstance().setRegister(arg1, pos);
|
||||
Manager::getInstance()->setStreamPosition(streamPos);
|
||||
} else if (command == "jalr") {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user