// Helper Functions for assembling #pragma once #include "chunk.h" #include #include #include #include #include #include #include #include namespace Asm { class Args: public std::vector { public: Args(){} Args(const std::vector& args): std::vector(args){} class Immediate8 { public: Immediate8(uint8_t value): m_value(value) {} uint8_t value() {return m_value;} std::vector getCode() {return {m_value};}; private: uint8_t m_value; }; class Immediate32 { public: Immediate32(uint32_t value): m_value(value) {} uint32_t value() { return m_value; } std::vector getCode() { std::vector result(size_t(4)); *(reinterpret_cast(result.data())) = boost::endian::native_to_little(m_value); return result; }; private: uint32_t m_value; }; class Register8 { public: Register8(const std::string& name): m_name(name) {} std::string name() { return m_name; } private: std::string m_name; }; class Register32 { public: Register32(const std::string& name): m_name(name) {} std::string name() { return m_name; } private: std::string m_name; }; class Register64 { public: Register64(const std::string& name): m_name(name) {} std::string name() { return m_name; } private: std::string m_name; }; class Label { public: Label(const std::string& name): m_name(name) {} std::string name() { return m_name; } private: std::string m_name; }; }; // class Args } // namespace Asm using FactoryFunction = std::function(Asm::Args&)>; // mnemonic: mnemonic including argument types bool registerOp(const std::string& mnemonic, FactoryFunction f); // Create Op from a registered mnemonic // mnemonic: just the mnemonic name std::shared_ptr makeOp(const std::string& mnemonic, Asm::Args& args); // overload for empty list of arguments std::shared_ptr makeOp(const std::string& mnemonic); std::shared_ptr