1 #include "interface/disassembler.hpp"
9 template<typename T
, bool be
> T
fetch_generic(std::function
<unsigned char()> fetchpc
)
13 for(size_t i
= 0; i
< b
; i
++) {
14 size_t bit
= 8 * (be
? (b
- i
- 1) : i
);
15 res
|= (static_cast<T
>(fetchpc()) << bit
);
21 disassembler::disassembler(const std::string
& _name
)
23 disasms()[name
= _name
] = this;
26 disassembler::~disassembler()
28 disasms().erase(name
);
31 disassembler
& disassembler::byname(const std::string
& name
)
33 if(disasms().count(name
))
34 return *disasms()[name
];
35 throw std::runtime_error("No such disassembler known");
38 std::set
<std::string
> disassembler::list()
40 std::set
<std::string
> r
;
41 for(auto& i
: disasms())
46 std::map
<std::string
, disassembler
*>& disassembler::disasms()
48 static std::map
<std::string
, disassembler
*> x
;
52 template<> int8_t disassembler::fetch_le(std::function
<unsigned char()> fetchpc
)
54 return fetch_generic
<int8_t, false>(fetchpc
);
57 template<> uint8_t disassembler::fetch_le(std::function
<unsigned char()> fetchpc
)
59 return fetch_generic
<uint8_t, false>(fetchpc
);
62 template<> int16_t disassembler::fetch_le(std::function
<unsigned char()> fetchpc
)
64 return fetch_generic
<int16_t, false>(fetchpc
);
67 template<> uint16_t disassembler::fetch_le(std::function
<unsigned char()> fetchpc
)
69 return fetch_generic
<uint16_t, false>(fetchpc
);
72 template<> int32_t disassembler::fetch_le(std::function
<unsigned char()> fetchpc
)
74 return fetch_generic
<int32_t, false>(fetchpc
);
77 template<> uint32_t disassembler::fetch_le(std::function
<unsigned char()> fetchpc
)
79 return fetch_generic
<uint32_t, false>(fetchpc
);
82 template<> int64_t disassembler::fetch_le(std::function
<unsigned char()> fetchpc
)
84 return fetch_generic
<int64_t, false>(fetchpc
);
87 template<> uint64_t disassembler::fetch_le(std::function
<unsigned char()> fetchpc
)
89 return fetch_generic
<uint64_t, false>(fetchpc
);
92 template<> int8_t disassembler::fetch_be(std::function
<unsigned char()> fetchpc
)
94 return fetch_generic
<int8_t, true>(fetchpc
);
97 template<> uint8_t disassembler::fetch_be(std::function
<unsigned char()> fetchpc
)
99 return fetch_generic
<uint8_t, true>(fetchpc
);
102 template<> int16_t disassembler::fetch_be(std::function
<unsigned char()> fetchpc
)
104 return fetch_generic
<int16_t, true>(fetchpc
);
107 template<> uint16_t disassembler::fetch_be(std::function
<unsigned char()> fetchpc
)
109 return fetch_generic
<uint16_t, true>(fetchpc
);
112 template<> int32_t disassembler::fetch_be(std::function
<unsigned char()> fetchpc
)
114 return fetch_generic
<int32_t, true>(fetchpc
);
117 template<> uint32_t disassembler::fetch_be(std::function
<unsigned char()> fetchpc
)
119 return fetch_generic
<uint32_t, true>(fetchpc
);
122 template<> int64_t disassembler::fetch_be(std::function
<unsigned char()> fetchpc
)
124 return fetch_generic
<int64_t, true>(fetchpc
);
127 template<> uint64_t disassembler::fetch_be(std::function
<unsigned char()> fetchpc
)
129 return fetch_generic
<uint64_t, true>(fetchpc
);