-
-
Save rightfold/a038788daf64e00bbd6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <cstddef> | |
#include <cstdint> | |
#include "instruction.hpp" | |
#include "variant.hpp" | |
namespace mill { | |
using Register = boost::variant< | |
bool, | |
std::int8_t, | |
std::int16_t, | |
std::int32_t, | |
std::int64_t, | |
std::uint8_t, | |
std::uint16_t, | |
std::uint32_t, | |
std::uint64_t, | |
float, | |
double, | |
long double | |
>; | |
class InstructionVisitor : public boost::static_visitor<> { | |
public: | |
void operator()(NoopInstruction) { } | |
void operator()(ConstInt8Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstInt16Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstInt32Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstInt64Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstUInt8Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstUInt16Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstUInt32Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstUInt64Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstBooleanInstruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstRationalInstruction) { throw "not implemented"; } | |
void operator()(ConstFloat32Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstFloat64Instruction i) { setRegister(i.op0, i.op1); } | |
void operator()(ConstFloat128Instruction i) { setRegister(i.op0, i.op1); } | |
private: | |
template<typename T> | |
void setRegister(std::size_t index, T value) { | |
registers[index] = value; | |
} | |
template<typename T> | |
T getRegister(std::size_t index) { | |
return boost::get<T>(registers[index]); | |
} | |
Register* registers; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment