1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Template Instruction on its content size.

This commit is contained in:
Thomas Harte 2022-02-21 12:36:03 -05:00
parent 1934c7faa2
commit 76814588b8
4 changed files with 11 additions and 9 deletions

View File

@ -15,7 +15,7 @@
using namespace InstructionSet::x86;
template <Model model>
std::pair<int, InstructionSet::x86::Instruction> Decoder<model>::decode(const uint8_t *source, size_t length) {
std::pair<int, typename Decoder<model>::InstructionT> Decoder<model>::decode(const uint8_t *source, size_t length) {
const uint8_t *const end = source + length;
// MARK: - Prefixes (if present) and the opcode.
@ -80,7 +80,7 @@ std::pair<int, InstructionSet::x86::Instruction> Decoder<model>::decode(const ui
operand_size_ = 1; \
#define undefined() { \
const auto result = std::make_pair(consumed_, Instruction()); \
const auto result = std::make_pair(consumed_, InstructionT()); \
reset_parsing(); \
return result; \
}
@ -681,7 +681,7 @@ std::pair<int, InstructionSet::x86::Instruction> Decoder<model>::decode(const ui
}
} else {
// Provide a genuine measure of further bytes required.
return std::make_pair(-(outstanding_bytes - bytes_to_consume), Instruction());
return std::make_pair(-(outstanding_bytes - bytes_to_consume), InstructionT());
}
}
@ -690,7 +690,7 @@ std::pair<int, InstructionSet::x86::Instruction> Decoder<model>::decode(const ui
if(phase_ == Phase::ReadyToPost) {
const auto result = std::make_pair(
consumed_,
Instruction(
InstructionT(
operation_,
source_,
destination_,
@ -707,7 +707,7 @@ std::pair<int, InstructionSet::x86::Instruction> Decoder<model>::decode(const ui
}
// i.e. not done yet.
return std::make_pair(0, Instruction());
return std::make_pair(0, InstructionT());
}
// Ensure all possible decoders are built.

View File

@ -29,8 +29,10 @@ enum class Model {
This is an experimental implementation; it has not yet undergone significant testing.
*/
template <Model> class Decoder {
template <Model model> class Decoder {
public:
using InstructionT = Instruction<model >= Model::i80386>;
/*!
@returns an @c Instruction plus a size; a positive size to indicate successful decoding; a
negative size specifies the [negatived] number of further bytes the caller should ideally
@ -38,7 +40,7 @@ template <Model> class Decoder {
instruction in response, and the decoder may still not be able to complete decoding
even if given that number of bytes.
*/
std::pair<int, Instruction> decode(const uint8_t *source, size_t length);
std::pair<int, InstructionT> decode(const uint8_t *source, size_t length);
private:
enum class Phase {

View File

@ -415,7 +415,7 @@ struct SourceSIB {
ScaleIndexBase sib;
};
class Instruction {
template<bool is_32bit> class Instruction {
public:
Operation operation = Operation::Invalid;

View File

@ -14,7 +14,7 @@
namespace {
using Operation = InstructionSet::x86::Operation;
using Instruction = InstructionSet::x86::Instruction;
using Instruction = InstructionSet::x86::Instruction<false>;
using Source = InstructionSet::x86::Source;
using Size = InstructionSet::x86::Size;
using ScaleIndexBase = InstructionSet::x86::ScaleIndexBase;