summaryrefslogtreecommitdiffhomepage
path: root/asm/assembler.h
diff options
context:
space:
mode:
Diffstat (limited to 'asm/assembler.h')
-rw-r--r--asm/assembler.h124
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;
-};
-