mirror of
https://git.suyu.dev/suyu/sirit.git
synced 2024-12-22 20:22:02 +00:00
literal_number: Drop usage of RTTI
This commit is contained in:
parent
de91660f3c
commit
cff0a41416
2 changed files with 7 additions and 10 deletions
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
|
||||||
LiteralNumber::LiteralNumber(std::type_index type) : type(type) {
|
LiteralNumber::LiteralNumber(u64 raw, bool is_32) : raw{raw}, is_32{is_32} {
|
||||||
operand_type = OperandType::Number;
|
operand_type = OperandType::Number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ u16 LiteralNumber::GetWordCount() const {
|
||||||
bool LiteralNumber::operator==(const Operand& other) const {
|
bool LiteralNumber::operator==(const Operand& other) const {
|
||||||
if (operand_type == other.GetType()) {
|
if (operand_type == other.GetType()) {
|
||||||
const auto& o{static_cast<const LiteralNumber&>(other)};
|
const auto& o{static_cast<const LiteralNumber&>(other)};
|
||||||
return o.type == type && o.raw == raw;
|
return o.raw == raw && o.is_32 == is_32;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <typeindex>
|
|
||||||
#include "operand.h"
|
#include "operand.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ namespace Sirit {
|
||||||
|
|
||||||
class LiteralNumber : public Operand {
|
class LiteralNumber : public Operand {
|
||||||
public:
|
public:
|
||||||
LiteralNumber(std::type_index type);
|
explicit LiteralNumber(u64 raw, bool is_32);
|
||||||
~LiteralNumber() override;
|
~LiteralNumber() override;
|
||||||
|
|
||||||
void Fetch(Stream& stream) const override;
|
void Fetch(Stream& stream) const override;
|
||||||
|
@ -28,16 +27,14 @@ public:
|
||||||
static std::unique_ptr<LiteralNumber> Create(T value) {
|
static std::unique_ptr<LiteralNumber> Create(T value) {
|
||||||
static_assert(sizeof(T) == 4 || sizeof(T) == 8);
|
static_assert(sizeof(T) == 4 || sizeof(T) == 8);
|
||||||
|
|
||||||
auto number = std::make_unique<LiteralNumber>(std::type_index(typeid(T)));
|
u64 raw{};
|
||||||
number->is_32 = sizeof(T) == 4;
|
std::memcpy(&raw, &value, sizeof(T));
|
||||||
std::memcpy(&number->raw, &value, sizeof(T));
|
return std::make_unique<LiteralNumber>(raw, sizeof(T) == 4);
|
||||||
return number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::type_index type;
|
|
||||||
bool is_32{};
|
|
||||||
u64 raw{};
|
u64 raw{};
|
||||||
|
bool is_32{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Sirit
|
} // namespace Sirit
|
||||||
|
|
Loading…
Reference in a new issue