ProgramLoader reordering
This commit is contained in:
@@ -6,14 +6,24 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
Manager::Manager(std::string path): m_path(std::move(path)) {}
|
||||
Manager::Manager(std::string path): m_path(std::move(path)) {
|
||||
m_programFile.open(path);
|
||||
}
|
||||
|
||||
Manager * Manager::getInstance(const std::string &program_path) {
|
||||
Manager::~Manager() {
|
||||
m_programFile.close();
|
||||
}
|
||||
|
||||
Manager *Manager::getInstance(const std::string &program_path) {
|
||||
static Manager instance{program_path};
|
||||
return &instance;
|
||||
}
|
||||
|
||||
int Manager::run() {
|
||||
ProgramLoader::getInstance(m_path)->indexFile();
|
||||
std::string line;
|
||||
ProgramLoader::getInstance()->indexFile(m_programFile);
|
||||
while (std::getline(m_programFile, line)) {
|
||||
auto lineVector = ProgramLoader::parseLine(line);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -15,16 +15,22 @@ class Manager {
|
||||
private:
|
||||
/// Die Instanz des Managers soll mit einem immutable path zum Programm erstellt werden
|
||||
explicit Manager(std::string path);
|
||||
|
||||
std::string m_path;
|
||||
std::map<std::string, int> m_labels;
|
||||
std::ifstream m_programFile;
|
||||
|
||||
public:
|
||||
/// Singleton Logik
|
||||
Manager(const Manager &) = delete;
|
||||
|
||||
Manager(const Manager &&) = delete;
|
||||
|
||||
Manager &operator=(const Manager &) = delete;
|
||||
|
||||
Manager &operator=(const Manager &&) = delete;
|
||||
~Manager() = default;
|
||||
|
||||
~Manager();
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -37,5 +43,4 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //MANAGER_H
|
||||
|
||||
@@ -5,16 +5,8 @@
|
||||
#include "ProgramLoader.h"
|
||||
#include <sstream>
|
||||
|
||||
ProgramLoader::ProgramLoader(const std::string &path){
|
||||
m_programFile.open(path);
|
||||
}
|
||||
|
||||
ProgramLoader::~ProgramLoader() {
|
||||
m_programFile.close();
|
||||
}
|
||||
|
||||
ProgramLoader * ProgramLoader::getInstance(const std::string &program_path) {
|
||||
static ProgramLoader instance{program_path};
|
||||
ProgramLoader *ProgramLoader::getInstance() {
|
||||
static ProgramLoader instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
@@ -30,7 +22,7 @@ ProgramLoader * ProgramLoader::getInstance(const std::string &program_path) {
|
||||
if (out.empty()) break;
|
||||
/// Stoppe, sobald ein Kommentar im Source Code vorkommt
|
||||
if (out.at(0) != '#') {
|
||||
if (out.at(out.length() -1) == ',') {
|
||||
if (out.at(out.length() - 1) == ',') {
|
||||
out.erase(out.length() - 1);
|
||||
}
|
||||
output.push_back(out);
|
||||
@@ -41,19 +33,17 @@ ProgramLoader * ProgramLoader::getInstance(const std::string &program_path) {
|
||||
return output;
|
||||
}
|
||||
|
||||
void ProgramLoader::indexFile() {
|
||||
if (m_programFile.is_open()) {
|
||||
std::string line;
|
||||
int lineNumber = 1;
|
||||
/// Parse Zeile für Zeile
|
||||
while (std::getline(m_programFile, line)) {
|
||||
auto lineVector = parseLine(line);
|
||||
const auto first = lineVector.begin();
|
||||
/// Sobald ein Label gefunden wurde, speichere die Zeile
|
||||
if (first->at(first->length() - 1) == ':') {
|
||||
m_labels[first->substr(0, first->length() - 1)] = lineNumber;
|
||||
}
|
||||
lineNumber++;
|
||||
void ProgramLoader::indexFile(std::ifstream &m_programFile) {
|
||||
std::string line;
|
||||
int lineNumber = 1;
|
||||
/// Parse Zeile für Zeile
|
||||
while (std::getline(m_programFile, line)) {
|
||||
auto lineVector = parseLine(line);
|
||||
const auto first = lineVector.begin();
|
||||
/// Sobald ein Label gefunden wurde, speichere die Zeile
|
||||
if (first->at(first->length() - 1) == ':') {
|
||||
m_labels[first->substr(0, first->length() - 1)] = lineNumber;
|
||||
}
|
||||
lineNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,18 +18,19 @@ private:
|
||||
*
|
||||
* @param path Der Pfad zur .txt Quelldatei des Programmes
|
||||
*/
|
||||
explicit ProgramLoader(const std::string &path);
|
||||
explicit ProgramLoader() = default;
|
||||
|
||||
std::ifstream m_programFile;
|
||||
std::map<std::string, int> m_labels;
|
||||
|
||||
public:
|
||||
/// Singleton Logik
|
||||
ProgramLoader(const ProgramLoader&) = delete;
|
||||
ProgramLoader(const ProgramLoader&&) = delete;
|
||||
ProgramLoader& operator=(const ProgramLoader&) = delete;
|
||||
ProgramLoader& operator=(const ProgramLoader&&) = delete;
|
||||
~ProgramLoader();
|
||||
ProgramLoader(const ProgramLoader &) = delete;
|
||||
|
||||
ProgramLoader(const ProgramLoader &&) = delete;
|
||||
|
||||
ProgramLoader &operator=(const ProgramLoader &) = delete;
|
||||
|
||||
ProgramLoader &operator=(const ProgramLoader &&) = delete;
|
||||
|
||||
/**
|
||||
* Gibt die Singleton Instanz des ProgramLoaders zurück
|
||||
@@ -37,7 +38,7 @@ public:
|
||||
* @param program_path Der Pfad zur .txt Quelldatei des Programmes
|
||||
* @return ProgramLoader Instanz
|
||||
*/
|
||||
static ProgramLoader *getInstance(const std::string &program_path);
|
||||
static ProgramLoader *getInstance();
|
||||
|
||||
/**
|
||||
* Parst eine Zeile des Assembly Codes und gibt diese als sortierten Vektor zurück
|
||||
@@ -50,9 +51,8 @@ public:
|
||||
/**
|
||||
* Durchscucht das aktuelle Programm nach Labeln und speichert diese zusammen mit den Zeilennummern in einer Map
|
||||
*/
|
||||
void indexFile();
|
||||
void indexFile(std::ifstream &m_programFile);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //PROGRAMLOADER_H
|
||||
|
||||
Reference in New Issue
Block a user