#ifndef LIBFXOS_OPERANDS_H #define LIBFXOS_OPERANDS_H namespace FxOS { /* Data types: Registers longwords Memory aligned u8, u16, u32 User-defined structs, ... */ /* Status register does not contain too much useful stuff: (30)MD (29)RB -> Disassembler needs not understand them (9)M (8)Q -> Idem, divisions are very rare (7-4)IMASK (28)BL -> Interrupt system rarely used, even less explicitly (1)S -> ? (0)T -> Now THAT is important Disassembler should name them but needs not understand their role, except T. The T bit might just be stored outside. */ enum class DataKind { /* Base types */ Integral, /* Bit fields over integers */ BitField, /* Structures (can only reside in memory) */ Struct, /* Arrays (can only reside in memory) */ Array, }; class DataType { public: virtual DataKind kind() const noexcept = 0; }; class IntegralType: public DataType { public: IntegralType(int bitsize); DataKind kind() const noexcept override { return DataKind::Integral; } private: int m_size; }; class BitFieldType: public DataType { using Field = std::pair; public: BitFieldType(std::vector fields); DataKind kind() const noexcept override { return DataKind::BitField; } private: int m_size; std::vector m_fields; }; enum class OperandKind { /* CPU-held registers accessed with instructions */ CpuRegister, /* Standard randomly-addressable memory */ Memory, /* Memory-mapped module registers with specific access */ MappedModule, }; class Operand { public: /* Returns the operand kind (which is also the subclass identity) */ virtual OperandKind type() const noexcept = 0; /* Sring representation */ virtual std::string str() const noexcept = 0; }; class RegisterOperand: public Operand { public: RegisterOperand(std::string name): m_name(name) {} OperandKind type() const noexcept override { return OperandKind::CpuRegister; } std::string name() const noexcept { return m_name; } std::string str() const noexcept override { return this->name(); } private: /* Register name for assembler listings */ std::string m_name; }; } /* namespace FxOS */ #endif /* LIBFXOS_OPERANDS_H */