1
0
Fork 0
mirror of https://git.suyu.dev/suyu/sirit.git synced 2025-01-10 12:46:09 +00:00
sirit/src/operand.h
2018-08-27 00:29:40 -03:00

89 lines
1.7 KiB
C++

/* This file is part of the sirit project.
* Copyright (c) 2018 ReinUsesLisp
* This software may be used and distributed according to the terms of the GNU
* Lesser General Public License version 2.1 or any later version.
*/
#pragma once
#include "stream.h"
namespace Sirit {
enum class OperandType {
Invalid,
Op,
Number,
String
};
class Operand {
public:
Operand();
virtual ~Operand();
virtual void Fetch(Stream& stream) const;
virtual u16 GetWordCount() const;
virtual bool operator==(const Operand& other) const;
bool operator!=(const Operand& other) const;
OperandType GetType() const;
protected:
OperandType operand_type{};
};
class LiteralNumber : public Operand {
public:
LiteralNumber(u32 number);
LiteralNumber(s32 number);
LiteralNumber(f32 number);
LiteralNumber(u64 number);
LiteralNumber(s64 number);
LiteralNumber(f64 number);
~LiteralNumber();
virtual void Fetch(Stream& stream) const;
virtual u16 GetWordCount() const;
virtual bool operator==(const Operand& other) const;
private:
LiteralNumber();
enum class NumberType {
U32,
S32,
F32,
U64,
S64,
F64
} type;
union {
u64 raw{};
u32 uint32;
s32 int32;
u64 uint64;
s64 int64;
f32 float32;
f64 float64;
};
};
class LiteralString : public Operand {
public:
LiteralString(const std::string& string);
~LiteralString();
virtual void Fetch(Stream& stream) const;
virtual u16 GetWordCount() const;
virtual bool operator==(const Operand& other) const;
private:
std::string string;
};
} // namespace Sirit