reordering and ProgramLoader basic functionality

This commit is contained in:
black
2025-07-06 18:54:20 +02:00
parent 5e45b71b8e
commit 3326227bb1
6 changed files with 119 additions and 76 deletions

57
src/ProgramLoader.h Normal file
View File

@@ -0,0 +1,57 @@
//
// Created by black on 06.07.25.
//
#ifndef PROGRAMLOADER_H
#define PROGRAMLOADER_H
#include <fstream>
#include <map>
#include <string>
#include <vector>
/// Der ProgramLoader, zuständig für das Lesen und Parsen des Quellcodes
class ProgramLoader {
private:
/**
* Der private Konstruktor für ProgramLoader
*
* @param path Der Pfad zur .txt Quelldatei des Programmes
*/
explicit ProgramLoader(const std::string &path);
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;
/**
* Gibt die Singleton Instanz des ProgramLoaders zurück
*
* @param program_path Der Pfad zur .txt Quelldatei des Programmes
* @return ProgramLoader Instanz
*/
static ProgramLoader *getInstance(const std::string &program_path);
/**
* Parst eine Zeile des Assembly Codes und gibt diese als sortierten Vektor zurück
*
* @param input Eine Zeile aus dem Assembly Code
* @return Ein Vektor mit Befehl und dessen Argumenten
*/
static std::vector<std::string> parseLine(const std::string &input);
/**
* Durchscucht das aktuelle Programm nach Labeln und speichert diese zusammen mit den Zeilennummern in einer Map
*/
void indexFile();
};
#endif //PROGRAMLOADER_H