diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-10-18 16:59:54 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-10-18 16:59:54 +0200 |
commit | 8a2d1dc5c8b6639985d26d1c915048d87d52426b (patch) | |
tree | 2f3957a1c24ef35b4ec9259a6a0d97393b248a57 /asm/assembler.h | |
parent | 8f28495ab9a8ebf53868405541e907394895e51f (diff) |
Added xor, mov, jmp
Diffstat (limited to 'asm/assembler.h')
-rw-r--r-- | asm/assembler.h | 124 |
1 files changed, 77 insertions, 47 deletions
diff --git a/asm/assembler.h b/asm/assembler.h index 3d3e9a9..52c3da5 100644 --- a/asm/assembler.h +++ b/asm/assembler.h @@ -10,8 +10,84 @@ #include <memory> #include <string> #include <unordered_map> +#include <vector> + +// TODO: namespace Asm, e.g. AsmArgs -> Asm::Args + +class AsmArgs: public std::vector<std::any> +{ +public: + AsmArgs(){} + AsmArgs(const std::vector<std::any>& args): std::vector<std::any>(args){} + + class Immediate8 + { + public: + Immediate8(uint8_t value): m_value(value) {} + uint8_t value() {return m_value;} + std::vector<uint8_t> 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<uint8_t> getCode() { + std::vector<uint8_t> result(size_t(4)); + *(reinterpret_cast<uint32_t*>(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; + }; + +}; -using AsmArgs = std::vector<std::any>; using FactoryFunction = std::function<std::shared_ptr<Op>(AsmArgs&)>; // mnemonic: mnemonic including argument types @@ -44,49 +120,3 @@ std::string mangleName(const std::string& s) std::string mangleName(const std::string& s, AsmArgs& args); -class Immediate8 -{ -public: - Immediate8(uint8_t value): m_value(value) {} - uint8_t value() {return m_value;} - std::vector<uint8_t> 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<uint8_t> getCode() { - std::vector<uint8_t> result(size_t(4)); - *(reinterpret_cast<uint32_t*>(result.data())) = boost::endian::native_to_little(m_value); - return result; - }; - -private: - uint32_t m_value; -}; - -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; -}; - |