Refactor main.cpp functions into separate class
This commit is contained in:
13
include/configuration.hpp
Normal file
13
include/configuration.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct Configuration
|
||||
{
|
||||
unsigned memorySize;
|
||||
std::vector<std::pair<unsigned, std::string>> strings;
|
||||
|
||||
void PrepareMemory(std::vector<std::uint8_t> & memory) const;
|
||||
Configuration();
|
||||
};
|
||||
@@ -9,12 +9,10 @@ namespace Execute
|
||||
{
|
||||
unsigned currentStatement;
|
||||
unsigned nextStatement;
|
||||
std::unordered_map<std::string, unsigned> const & labelStatementIndice;
|
||||
std::vector<InterruptFn> const interrupts;
|
||||
std::unordered_map<std::string, unsigned> const * labelStatementIndice;
|
||||
std::vector<InterruptFn> interrupts;
|
||||
std::vector<std::uint8_t> memory;
|
||||
unsigned stackPointer;
|
||||
bool terminated;
|
||||
|
||||
State(std::unordered_map<std::string, unsigned> const & labelStatementIndice, unsigned const memorySize);
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <configuration.hpp>
|
||||
#include <execute/flags.hpp>
|
||||
#include <execute/registers.hpp>
|
||||
#include <execute/state.hpp>
|
||||
#include <interpret/code.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
@@ -11,17 +13,16 @@ namespace Execute
|
||||
Flags flags;
|
||||
Registers registers;
|
||||
State state;
|
||||
bool terminated;
|
||||
|
||||
Interpret::Code const & code;
|
||||
std::unique_ptr<Interpret::Code const> codePtr;
|
||||
|
||||
void Step();
|
||||
|
||||
VirtualMachine(Interpret::Code const & code, unsigned const memorySize);
|
||||
|
||||
public:
|
||||
void Run();
|
||||
void SingleStep();
|
||||
void LoadConfiguration(Configuration const & c);
|
||||
void LoadCode(std::unique_ptr<Interpret::Code> code);
|
||||
|
||||
Flags const & GetFlags() const;
|
||||
Registers const & GetRegisters() const;
|
||||
@@ -30,6 +31,6 @@ namespace Execute
|
||||
|
||||
bool IsTerminated() const;
|
||||
|
||||
static VirtualMachine CreateFromCode(Interpret::Code const & code);
|
||||
VirtualMachine();
|
||||
};
|
||||
}
|
||||
@@ -12,5 +12,10 @@ namespace Interpret
|
||||
std::vector<std::unique_ptr<Statement>> statements;
|
||||
std::unordered_map<std::string, unsigned> labelStatementIndice;
|
||||
std::unordered_map<std::string, int> declarations;
|
||||
|
||||
Code() = default;
|
||||
~Code() = default;
|
||||
Code(const Code&) = delete;
|
||||
Code& operator=(const Code&) = delete;
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <token/registertype.hpp>
|
||||
#include <token/tokentype.hpp>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace Token
|
||||
{
|
||||
@@ -46,4 +47,6 @@ namespace Token
|
||||
|
||||
void DebugPrint() const;
|
||||
};
|
||||
|
||||
void PrintTokens(std::vector<Token> const & tokens);
|
||||
}
|
||||
|
||||
22
include/wassembler.hpp
Normal file
22
include/wassembler.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <configuration.hpp>
|
||||
#include <execute/virtualmachine.hpp>
|
||||
#include <preprocessor/preprocessor.hpp>
|
||||
#include <interpret/interpreter.hpp>
|
||||
#include <token/tokenizer.hpp>
|
||||
|
||||
class Wassembler
|
||||
{
|
||||
private:
|
||||
Execute::VirtualMachine vm;
|
||||
|
||||
bool LoadLinesFromFile(std::string const & filePath, std::vector<std::string> & lines) const;
|
||||
bool LoadTokens(std::vector<std::string> const & lines, std::vector<Token::Token> & tokens) const;
|
||||
|
||||
public:
|
||||
bool LoadFromFile(std::string const & filePath);
|
||||
|
||||
void Run();
|
||||
|
||||
Wassembler() = default;
|
||||
};
|
||||
Reference in New Issue
Block a user