// Chunk data type, and derived types #pragma once #include #include #include // TODO: use it everywhere! using OP_T = std::vector; class Chunk { public: virtual ~Chunk(){} virtual std::vector getCode() = 0; virtual size_t size() = 0; ///< returns size in bytes }; // can be added via multiple inheritance to chunks with addresses struct AddressFeature { std::string label; bool relativeAddressing{true}; std::vector machine_code; size_t addr_size; size_t addr_offs; ///< offset inside code std::vector alternative_code; size_t alternative_size; size_t alternative_offs; ///< offset inside code }; class Label: public Chunk { public: Label(const std::string& name) : m_name(name) {} std::string name(){return m_name;} std::vector getCode() override { return {}; } size_t size() override { return 0; } private: std::string m_name; }; class Data: public Chunk { public: Data(const std::vector& data): m_data(data) {} virtual ~Data(){} std::vector getCode() override { return m_data; } size_t size() override { return m_data.size(); } protected: std::vector m_data; }; class Op: public Chunk { public: virtual ~Op(){}; virtual bool optimize() = 0; ///< returns true if changed }; class OpSimple: public Op { public: OpSimple(std::vector machine_code): machine_code(machine_code) {} std::vector getCode() override { return machine_code; } size_t size() override { return machine_code.size(); } bool optimize() override ///< returns true if changed { return false; } protected: std::vector machine_code; };