mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-27 15:29:34 +00:00
Template Instruction
on its content size.
This commit is contained in:
parent
1934c7faa2
commit
76814588b8
@ -15,7 +15,7 @@
|
|||||||
using namespace InstructionSet::x86;
|
using namespace InstructionSet::x86;
|
||||||
|
|
||||||
template <Model model>
|
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;
|
const uint8_t *const end = source + length;
|
||||||
|
|
||||||
// MARK: - Prefixes (if present) and the opcode.
|
// 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; \
|
operand_size_ = 1; \
|
||||||
|
|
||||||
#define undefined() { \
|
#define undefined() { \
|
||||||
const auto result = std::make_pair(consumed_, Instruction()); \
|
const auto result = std::make_pair(consumed_, InstructionT()); \
|
||||||
reset_parsing(); \
|
reset_parsing(); \
|
||||||
return result; \
|
return result; \
|
||||||
}
|
}
|
||||||
@ -681,7 +681,7 @@ std::pair<int, InstructionSet::x86::Instruction> Decoder<model>::decode(const ui
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Provide a genuine measure of further bytes required.
|
// 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) {
|
if(phase_ == Phase::ReadyToPost) {
|
||||||
const auto result = std::make_pair(
|
const auto result = std::make_pair(
|
||||||
consumed_,
|
consumed_,
|
||||||
Instruction(
|
InstructionT(
|
||||||
operation_,
|
operation_,
|
||||||
source_,
|
source_,
|
||||||
destination_,
|
destination_,
|
||||||
@ -707,7 +707,7 @@ std::pair<int, InstructionSet::x86::Instruction> Decoder<model>::decode(const ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
// i.e. not done yet.
|
// i.e. not done yet.
|
||||||
return std::make_pair(0, Instruction());
|
return std::make_pair(0, InstructionT());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure all possible decoders are built.
|
// Ensure all possible decoders are built.
|
||||||
|
@ -29,8 +29,10 @@ enum class Model {
|
|||||||
|
|
||||||
This is an experimental implementation; it has not yet undergone significant testing.
|
This is an experimental implementation; it has not yet undergone significant testing.
|
||||||
*/
|
*/
|
||||||
template <Model> class Decoder {
|
template <Model model> class Decoder {
|
||||||
public:
|
public:
|
||||||
|
using InstructionT = Instruction<model >= Model::i80386>;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@returns an @c Instruction plus a size; a positive size to indicate successful decoding; a
|
@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
|
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
|
instruction in response, and the decoder may still not be able to complete decoding
|
||||||
even if given that number of bytes.
|
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:
|
private:
|
||||||
enum class Phase {
|
enum class Phase {
|
||||||
|
@ -415,7 +415,7 @@ struct SourceSIB {
|
|||||||
ScaleIndexBase sib;
|
ScaleIndexBase sib;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Instruction {
|
template<bool is_32bit> class Instruction {
|
||||||
public:
|
public:
|
||||||
Operation operation = Operation::Invalid;
|
Operation operation = Operation::Invalid;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using Operation = InstructionSet::x86::Operation;
|
using Operation = InstructionSet::x86::Operation;
|
||||||
using Instruction = InstructionSet::x86::Instruction;
|
using Instruction = InstructionSet::x86::Instruction<false>;
|
||||||
using Source = InstructionSet::x86::Source;
|
using Source = InstructionSet::x86::Source;
|
||||||
using Size = InstructionSet::x86::Size;
|
using Size = InstructionSet::x86::Size;
|
||||||
using ScaleIndexBase = InstructionSet::x86::ScaleIndexBase;
|
using ScaleIndexBase = InstructionSet::x86::ScaleIndexBase;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user