Xbyak::CastTo is removed

This commit is contained in:
MITSUNARI Shigeo 2018-10-21 17:23:26 +09:00
parent b011aca4b4
commit afdb9fe9ff
6 changed files with 16 additions and 20 deletions

View File

@ -198,7 +198,7 @@ int main(int argc, char *argv[])
Brainfuck bf(ifs); Brainfuck bf(ifs);
if (mode == 0) { if (mode == 0) {
static int stack[128 * 1024]; static int stack[128 * 1024];
bf.getCode<void (*)(void*, void*, int *)>()(Xbyak::CastTo<void*>(putchar), Xbyak::CastTo<void*>(getchar), stack); bf.getCode<void (*)(const void*, const void*, int *)>()(reinterpret_cast<const void*>(putchar), reinterpret_cast<const void*>(getchar), stack);
} else { } else {
dump(bf.getCode(), bf.getSize()); dump(bf.getCode(), bf.getSize());
} }

View File

@ -32,7 +32,7 @@ struct Code : Xbyak::CodeGenerator {
inline int add(int a, int b) inline int add(int a, int b)
{ {
return Xbyak::CastTo<int (*)(int,int)>(buf)(a, b); return reinterpret_cast<int (*)(int, int)>(buf)(a, b);
} }
int main() int main()

View File

@ -77,7 +77,7 @@ public:
#ifdef XBYAK_VARIADIC_TEMPLATE #ifdef XBYAK_VARIADIC_TEMPLATE
call(atoi); call(atoi);
#else #else
call(Xbyak::CastTo<void*>(atoi)); call(reinterpret_cast<const void*>(atoi));
#endif #endif
add(esp, 4); add(esp, 4);
#endif #endif
@ -96,7 +96,7 @@ public:
mov(rax, (size_t)atoi); mov(rax, (size_t)atoi);
jmp(rax); jmp(rax);
#else #else
jmp(Xbyak::CastTo<void*>(atoi)); jmp(reinterpret_cast<const void*>(atoi));
#endif #endif
} }
int (*get() const)(const char *) { return getCode<int (*)(const char *)>(); } int (*get() const)(const char *) { return getCode<int (*)(const char *)>(); }
@ -171,8 +171,9 @@ int main()
return 1; return 1;
} }
int (*func)(int) = s.getCode<int (*)(int)>(); int (*func)(int) = s.getCode<int (*)(int)>();
if (Xbyak::CastTo<uint8*>(func) != p) { const uint8 *funcp = reinterpret_cast<const uint8*>(func);
fprintf(stderr, "internal error %p %p\n", p, Xbyak::CastTo<uint8*>(func)); if (funcp != p) {
fprintf(stderr, "internal error %p %p\n", p, funcp);
return 1; return 1;
} }
printf("0 + ... + %d = %d\n", 100, func(100)); printf("0 + ... + %d = %d\n", 100, func(100));

View File

@ -204,7 +204,7 @@ public:
push(reg[r]); push(reg[r]);
push('A' + r); push('A' + r);
push((int)str); push((int)str);
call(Xbyak::CastTo<void*>(printf)); call(reinterpret_cast<const void*>(printf));
add(esp, 4 * 4); add(esp, 4 * 4);
pop(ecx); pop(ecx);
pop(edx); pop(edx);

View File

@ -222,19 +222,19 @@ void verify(const Xbyak::uint8 *f, int pNum)
{ {
switch (pNum) { switch (pNum) {
case 0: case 0:
check(1, Xbyak::CastTo<int (*)()>(f)()); check(1, reinterpret_cast<int (*)()>(f)());
return; return;
case 1: case 1:
check(11, Xbyak::CastTo<int (*)(int)>(f)(10)); check(11, reinterpret_cast<int (*)(int)>(f)(10));
return; return;
case 2: case 2:
check(111, Xbyak::CastTo<int (*)(int, int)>(f)(10, 100)); check(111, reinterpret_cast<int (*)(int, int)>(f)(10, 100));
return; return;
case 3: case 3:
check(1111, Xbyak::CastTo<int (*)(int, int, int)>(f)(10, 100, 1000)); check(1111, reinterpret_cast<int (*)(int, int, int)>(f)(10, 100, 1000));
return; return;
case 4: case 4:
check(11111, Xbyak::CastTo<int (*)(int, int, int, int)>(f)(10, 100, 1000, 10000)); check(11111, reinterpret_cast<int (*)(int, int, int, int)>(f)(10, 100, 1000, 10000));
return; return;
default: default:
printf("ERR pNum=%d\n", pNum); printf("ERR pNum=%d\n", pNum);

View File

@ -275,11 +275,6 @@ inline void AlignedFree(void *p)
#endif #endif
} }
template<class To, class From>
inline const To CastTo(From p) throw()
{
return (const To)(size_t)(p);
}
namespace inner { namespace inner {
static const size_t ALIGN_PAGE_SIZE = 4096; static const size_t ALIGN_PAGE_SIZE = 4096;
@ -925,10 +920,10 @@ public:
void dq(uint64 code) { db(code, 8); } void dq(uint64 code) { db(code, 8); }
const uint8 *getCode() const { return top_; } const uint8 *getCode() const { return top_; }
template<class F> template<class F>
const F getCode() const { return CastTo<F>(top_); } const F getCode() const { return reinterpret_cast<F>(top_); }
const uint8 *getCurr() const { return &top_[size_]; } const uint8 *getCurr() const { return &top_[size_]; }
template<class F> template<class F>
const F getCurr() const { return CastTo<F>(&top_[size_]); } const F getCurr() const { return reinterpret_cast<F>(&top_[size_]); }
size_t getSize() const { return size_; } size_t getSize() const { return size_; }
void setSize(size_t size) void setSize(size_t size)
{ {
@ -2200,7 +2195,7 @@ public:
// call(function pointer) // call(function pointer)
#ifdef XBYAK_VARIADIC_TEMPLATE #ifdef XBYAK_VARIADIC_TEMPLATE
template<class Ret, class... Params> template<class Ret, class... Params>
void call(Ret(*func)(Params...)) { call(CastTo<const void*>(func)); } void call(Ret(*func)(Params...)) { call(reinterpret_cast<const void*>(func)); }
#endif #endif
void call(const void *addr) { opJmpAbs(addr, T_NEAR, 0, 0xE8); } void call(const void *addr) { opJmpAbs(addr, T_NEAR, 0, 0xE8); }