Format with clang
This commit is contained in:
@@ -1,37 +1,34 @@
|
||||
#pragma once
|
||||
#include <variant>
|
||||
#include <execute/bytecode.hpp>
|
||||
#include <execute/error.hpp>
|
||||
#include <execute/state.hpp>
|
||||
#include <stdexcept>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
enum class ArgumentType
|
||||
{
|
||||
Immediate,
|
||||
Register,
|
||||
Memory
|
||||
};
|
||||
enum class ArgumentType
|
||||
{
|
||||
Immediate,
|
||||
Register,
|
||||
Memory
|
||||
};
|
||||
|
||||
class ArgumentValue
|
||||
{
|
||||
private:
|
||||
ArgumentType type;
|
||||
ArgumentType memoryValueType;
|
||||
std::variant<RegisterByte, int> data;
|
||||
class ArgumentValue {
|
||||
private:
|
||||
ArgumentType type;
|
||||
ArgumentType memoryValueType;
|
||||
std::variant<RegisterByte, int> data;
|
||||
|
||||
int & GetRegister(State & state) const;
|
||||
std::uint8_t * GetMemory(State & state) const;
|
||||
int & GetRegister(State & state) const;
|
||||
std::uint8_t * GetMemory(State & state) const;
|
||||
|
||||
public:
|
||||
void Write(int const value, State & state) const;
|
||||
int Read(State & state) const;
|
||||
public:
|
||||
void Write(int const value, State & state) const;
|
||||
int Read(State & state) const;
|
||||
|
||||
// Returns the size of the argument in bytes
|
||||
std::size_t Parse(
|
||||
std::vector<std::uint8_t> const & memory,
|
||||
std::size_t const pos);
|
||||
};
|
||||
// Returns the size of the argument in bytes
|
||||
std::size_t Parse(std::vector<std::uint8_t> const & memory, std::size_t const pos);
|
||||
};
|
||||
}
|
||||
@@ -3,41 +3,41 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
enum class InstructionByte : std::uint8_t
|
||||
{
|
||||
NOOP = 0,
|
||||
/* Integer functions */
|
||||
ADD_INTEGER,
|
||||
SUBTRACT_INTEGER,
|
||||
DIVIDE_INTEGER,
|
||||
MULTIPLY_INTEGER,
|
||||
SHIFT_LEFT_INTEGER,
|
||||
SHIFT_RIGHT_INTEGER,
|
||||
SET_INTEGER,
|
||||
/* Control flow */
|
||||
JUMP,
|
||||
INTERRUPT,
|
||||
CALL,
|
||||
RETURN,
|
||||
EXIT,
|
||||
LESS_THAN_INTEGER,
|
||||
GREATER_THAN_INTEGER,
|
||||
EQUALS_INTEGER,
|
||||
/* Memory */
|
||||
POP_INTEGER,
|
||||
PUSH_INTEGER,
|
||||
/* Values */
|
||||
IMMEDIATE_INTEGER,
|
||||
REGISTER,
|
||||
MEMORY_OP,
|
||||
LABEL,
|
||||
};
|
||||
enum class InstructionByte : std::uint8_t
|
||||
{
|
||||
NOOP = 0,
|
||||
/* Integer functions */
|
||||
ADD_INTEGER,
|
||||
SUBTRACT_INTEGER,
|
||||
DIVIDE_INTEGER,
|
||||
MULTIPLY_INTEGER,
|
||||
SHIFT_LEFT_INTEGER,
|
||||
SHIFT_RIGHT_INTEGER,
|
||||
SET_INTEGER,
|
||||
/* Control flow */
|
||||
JUMP,
|
||||
INTERRUPT,
|
||||
CALL,
|
||||
RETURN,
|
||||
EXIT,
|
||||
LESS_THAN_INTEGER,
|
||||
GREATER_THAN_INTEGER,
|
||||
EQUALS_INTEGER,
|
||||
/* Memory */
|
||||
POP_INTEGER,
|
||||
PUSH_INTEGER,
|
||||
/* Values */
|
||||
IMMEDIATE_INTEGER,
|
||||
REGISTER,
|
||||
MEMORY_OP,
|
||||
LABEL,
|
||||
};
|
||||
|
||||
enum class RegisterByte : std::uint8_t
|
||||
{
|
||||
A = 1,
|
||||
B,
|
||||
C,
|
||||
D
|
||||
};
|
||||
enum class RegisterByte : std::uint8_t
|
||||
{
|
||||
A = 1,
|
||||
B,
|
||||
C,
|
||||
D
|
||||
};
|
||||
}
|
||||
@@ -3,48 +3,40 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
class RuntimeError
|
||||
{
|
||||
protected:
|
||||
std::string message;
|
||||
std::size_t byteLocation;
|
||||
class RuntimeError {
|
||||
protected:
|
||||
std::string message;
|
||||
std::size_t byteLocation;
|
||||
|
||||
public:
|
||||
std::string const & GetMessage() const;
|
||||
public:
|
||||
std::string const & GetMessage() const;
|
||||
|
||||
RuntimeError();
|
||||
RuntimeError(std::string const & what, std::size_t const byteLocation);
|
||||
};
|
||||
RuntimeError();
|
||||
RuntimeError(std::string const & what, std::size_t const byteLocation);
|
||||
};
|
||||
|
||||
class InterruptIndexOutOfRange : public RuntimeError
|
||||
{
|
||||
public:
|
||||
InterruptIndexOutOfRange(std::size_t const location, int const index);
|
||||
};
|
||||
class InterruptIndexOutOfRange : public RuntimeError {
|
||||
public:
|
||||
InterruptIndexOutOfRange(std::size_t const location, int const index);
|
||||
};
|
||||
|
||||
class AttemptedWriteToImmediate : public RuntimeError
|
||||
{
|
||||
public:
|
||||
AttemptedWriteToImmediate(std::size_t const location);
|
||||
};
|
||||
class AttemptedWriteToImmediate : public RuntimeError {
|
||||
public:
|
||||
AttemptedWriteToImmediate(std::size_t const location);
|
||||
};
|
||||
|
||||
class NonExecutableInstruction : public RuntimeError
|
||||
{
|
||||
public:
|
||||
NonExecutableInstruction(std::size_t const location);
|
||||
};
|
||||
class NonExecutableInstruction : public RuntimeError {
|
||||
public:
|
||||
NonExecutableInstruction(std::size_t const location);
|
||||
};
|
||||
|
||||
class NonArgumentByte : public RuntimeError
|
||||
{
|
||||
public:
|
||||
NonArgumentByte(std::size_t const location);
|
||||
};
|
||||
class NonArgumentByte : public RuntimeError {
|
||||
public:
|
||||
NonArgumentByte(std::size_t const location);
|
||||
};
|
||||
|
||||
class OutOfMemory : public RuntimeError
|
||||
{
|
||||
public:
|
||||
OutOfMemory(
|
||||
std::size_t const requiredMemorySize,
|
||||
std::size_t const actualMemorySize);
|
||||
};
|
||||
class OutOfMemory : public RuntimeError {
|
||||
public:
|
||||
OutOfMemory(std::size_t const requiredMemorySize, std::size_t const actualMemorySize);
|
||||
};
|
||||
}
|
||||
@@ -5,8 +5,5 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
void ExecuteInterrupt(
|
||||
int const id,
|
||||
Execute::Registers & registers,
|
||||
std::vector<std::uint8_t> & memory);
|
||||
void ExecuteInterrupt(int const id, Execute::Registers & registers, std::vector<std::uint8_t> & memory);
|
||||
}
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
struct Registers
|
||||
{
|
||||
int A, B, C, D;
|
||||
std::size_t programCounter;
|
||||
std::size_t stackPointer;
|
||||
struct Registers
|
||||
{
|
||||
int A, B, C, D;
|
||||
std::size_t programCounter;
|
||||
std::size_t stackPointer;
|
||||
|
||||
// TODO status registers?
|
||||
};
|
||||
// TODO status registers?
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
struct State
|
||||
{
|
||||
bool terminated;
|
||||
Registers registers;
|
||||
std::vector<std::uint8_t> memory;
|
||||
struct State
|
||||
{
|
||||
bool terminated;
|
||||
Registers registers;
|
||||
std::vector<std::uint8_t> memory;
|
||||
|
||||
void PushToStack(int const value);
|
||||
int PopFromStack();
|
||||
};
|
||||
void PushToStack(int const value);
|
||||
int PopFromStack();
|
||||
};
|
||||
}
|
||||
@@ -6,42 +6,35 @@
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
class VirtualMachine
|
||||
{
|
||||
private:
|
||||
State state;
|
||||
class VirtualMachine {
|
||||
private:
|
||||
State state;
|
||||
|
||||
void DoArithmatic(
|
||||
InstructionByte const instruction,
|
||||
std::array<ArgumentValue, 3> & arguments);
|
||||
void SetInteger(std::array<ArgumentValue, 3> & arguments);
|
||||
void ExecuteJump(std::array<ArgumentValue, 3> & arguments);
|
||||
void ExecuteInterrupt(std::array<ArgumentValue, 3> & arguments);
|
||||
void ExecuteCall(
|
||||
std::array<ArgumentValue, 3> & arguments,
|
||||
std::size_t const returnByte);
|
||||
void ExecuteReturn();
|
||||
void DoBooleanLogic(
|
||||
InstructionByte const instruction,
|
||||
std::array<ArgumentValue, 3> & arguments,
|
||||
std::size_t const nextInstruction);
|
||||
void ExecutePop(std::array<ArgumentValue, 3> & arguments);
|
||||
void ExecutePush(std::array<ArgumentValue, 3> & arguments);
|
||||
void DoArithmatic(InstructionByte const instruction, std::array<ArgumentValue, 3> & arguments);
|
||||
void SetInteger(std::array<ArgumentValue, 3> & arguments);
|
||||
void ExecuteJump(std::array<ArgumentValue, 3> & arguments);
|
||||
void ExecuteInterrupt(std::array<ArgumentValue, 3> & arguments);
|
||||
void ExecuteCall(std::array<ArgumentValue, 3> & arguments, std::size_t const returnByte);
|
||||
void ExecuteReturn();
|
||||
void DoBooleanLogic(
|
||||
InstructionByte const instruction,
|
||||
std::array<ArgumentValue, 3> & arguments,
|
||||
std::size_t const nextInstruction);
|
||||
void ExecutePop(std::array<ArgumentValue, 3> & arguments);
|
||||
void ExecutePush(std::array<ArgumentValue, 3> & arguments);
|
||||
|
||||
void Step();
|
||||
void Step();
|
||||
|
||||
public:
|
||||
void Run();
|
||||
void SingleStep();
|
||||
public:
|
||||
void Run();
|
||||
void SingleStep();
|
||||
|
||||
void SetMemorySize(std::size_t const size);
|
||||
void LoadCode(
|
||||
std::vector<std::uint8_t> const & byteCode,
|
||||
bool const printDecodedBytes);
|
||||
void SetMemorySize(std::size_t const size);
|
||||
void LoadCode(std::vector<std::uint8_t> const & byteCode, bool const printDecodedBytes);
|
||||
|
||||
State const & GetState() const;
|
||||
Execute::InstructionByte GetCurrentInstruction() const;
|
||||
State const & GetState() const;
|
||||
Execute::InstructionByte GetCurrentInstruction() const;
|
||||
|
||||
bool IsTerminated() const;
|
||||
};
|
||||
bool IsTerminated() const;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user