Initial commit
This commit is contained in:
32
instruction.h
Normal file
32
instruction.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
enum class InstType : uint8_t {
|
||||
MOV, MVI, ADD, SUB, LOAD, STORE, AND, OR, XOR, SHF, JMP, JIZ, CALL, RET, SYS, HLT
|
||||
};
|
||||
|
||||
enum class OperandType {
|
||||
ImmNone, Imm4, Imm8
|
||||
};
|
||||
|
||||
using BytecodeInstruction = uint16_t;
|
||||
|
||||
static std::unordered_map<InstType, std::vector<OperandType>> instructionOperandTypes = {
|
||||
{InstType::MOV, {OperandType::Imm4, OperandType::Imm4, OperandType::Imm4}}
|
||||
};
|
||||
|
||||
struct Instruction {
|
||||
InstType opcode = InstType::MOV;
|
||||
uint16_t arg1 = 0;
|
||||
uint16_t arg2 = 0;
|
||||
uint16_t arg3 = 0;
|
||||
|
||||
BytecodeInstruction asBytecodeInstruction() const;
|
||||
|
||||
Instruction() = default;
|
||||
Instruction(InstType opcode, uint16_t arg1, uint16_t arg2, uint16_t arg3)
|
||||
: opcode(opcode), arg1(arg1), arg2(arg2), arg3(arg3) {}
|
||||
Instruction(BytecodeInstruction bytecodeInst);
|
||||
};
|
||||
Reference in New Issue
Block a user