From f86999e137f43372236f2dccd1fe3572a85c0dcd Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 17 Oct 2020 14:16:46 +0200 Subject: Separate-out assembler --- asm/chunk.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 asm/chunk.h (limited to 'asm/chunk.h') diff --git a/asm/chunk.h b/asm/chunk.h new file mode 100644 index 0000000..723e711 --- /dev/null +++ b/asm/chunk.h @@ -0,0 +1,79 @@ +// Chunk data type, and derived types + +#pragma once + +#include +#include +#include + +class Chunk +{ +public: + virtual ~Chunk(){} + virtual std::vector getCode() = 0; + virtual size_t size() = 0; ///< returns size in bytes +}; + +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(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; +}; + -- cgit v1.2.3