summaryrefslogtreecommitdiffhomepage
path: root/asm/assembler.h
blob: 42b5f8d02f9553347f654036ce8f2a0382ececba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once

//#include "chunk.h"
//#include "segment.h"

#include <any>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include <unordered_map>

using AsmArgs = std::vector<std::any>;
using FactoryFunction = std::function<std::shared_ptr<Op>(AsmArgs&)>;

// 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<Op> makeOp(const std::string& mnemonic, AsmArgs& args);

// overload for empty list of arguments
std::shared_ptr<Op> makeOp(const std::string& mnemonic);

template<typename T>
std::string mangleNameOne(const std::string& s)
{
 return s + "_" + typeid(T).name();
}

template<typename T, typename... Targs>
std::string mangleName(const std::string& s)
{
 if constexpr (sizeof...(Targs) == 0)
  return mangleNameOne<T>(s);
 else
  return mangleName<Targs...>(s + "_" + typeid(T).name());
}

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;}

private:
 uint8_t m_value;
};