decrease warning for -pedantic

This commit is contained in:
MITSUNARI Shigeo 2013-01-12 18:03:39 +09:00
parent b8a31fd932
commit 921aa019ae
9 changed files with 41 additions and 29 deletions

View file

@ -24,7 +24,7 @@ endif
all: $(TARGET) all: $(TARGET)
CFLAGS_WARN=-Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith CFLAGS_WARN=-Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -pedantic
CFLAGS=-g -O2 -fomit-frame-pointer -Wall -fno-operator-names -I../ $(CFLAGS_WARN) CFLAGS=-g -O2 -fomit-frame-pointer -Wall -fno-operator-names -I../ $(CFLAGS_WARN)
@ -82,6 +82,7 @@ bf64 : bf.cpp $(XBYAK_INC)
memfunc : memfunc.cpp $(XBYAK_INC) memfunc : memfunc.cpp $(XBYAK_INC)
memfunc64 : memfunc.cpp $(XBYAK_INC) memfunc64 : memfunc.cpp $(XBYAK_INC)
toyvm : toyvm.cpp $(XBYAK_INC) toyvm : toyvm.cpp $(XBYAK_INC)
static_buf: static_buf.cpp $(XBYAK_INC)
static_buf64: static_buf.cpp $(XBYAK_INC)
test_util : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h test_util : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h
test_util2 : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h test_util2 : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h

View file

@ -191,7 +191,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];
((void (*)(void*, void*, int *))(const void*)bf.getCode())((void*)putchar, (void*)getchar, stack); bf.getCode<void (*)(void*, void*, int *)>()(Xbyak::CastTo<void*>(putchar), Xbyak::CastTo<void*>(getchar), stack);
} else { } else {
dump(bf.getCode(), bf.getSize()); dump(bf.getCode(), bf.getSize());
} }

View file

@ -192,7 +192,7 @@ int main(int argc, char *argv[])
Quantize jit(qTbl); Quantize jit(qTbl);
//printf("jit size=%d, ptr=%p\n", jit.getSize(), jit.getCode()); //printf("jit size=%d, ptr=%p\n", jit.getSize(), jit.getCode());
void (*quantize2)(uint32*, const uint32*, const uint32 *) = (void (*)(uint32*, const uint32*, const uint32 *))(const void*)jit.getCode(); void (*quantize2)(uint32*, const uint32*, const uint32 *) = jit.getCode<void (*)(uint32*, const uint32*, const uint32 *)>();
quantize(dest, src, qTbl); quantize(dest, src, qTbl);
quantize2(dest2, src, qTbl); quantize2(dest2, src, qTbl);

View file

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

View file

@ -50,7 +50,7 @@ public:
#endif #endif
ret(); ret();
} }
int (*get() const)(int) { return (int (*)(int))(const void*)getCode(); } int (*get() const)(int) { return getCode<int(*)(int)>(); }
}; };
class CallAtoi : public Xbyak::CodeGenerator { class CallAtoi : public Xbyak::CodeGenerator {
@ -70,12 +70,12 @@ public:
#else #else
mov(eax, ptr [esp + 4]); mov(eax, ptr [esp + 4]);
push(eax); push(eax);
call((void*)atoi); call(Xbyak::CastTo<void*>(atoi));
add(esp, 4); add(esp, 4);
#endif #endif
ret(); ret();
} }
int (*get() const)(const char *) { return (int (*)(const char *))(const void*)getCode(); } int (*get() const)(const char *) { return getCode<int (*)(const char *)>(); }
}; };
class JmpAtoi : public Xbyak::CodeGenerator { class JmpAtoi : public Xbyak::CodeGenerator {
@ -88,10 +88,10 @@ public:
mov(rax, (size_t)atoi); mov(rax, (size_t)atoi);
jmp(rax); jmp(rax);
#else #else
jmp((void*)atoi); jmp(Xbyak::CastTo<void*>(atoi));
#endif #endif
} }
int (*get() const)(const char *) { return (int (*)(const char *))(const void*)getCode(); } int (*get() const)(const char *) { return getCode<int (*)(const char *)>(); }
}; };
struct Reset : public Xbyak::CodeGenerator { struct Reset : public Xbyak::CodeGenerator {
@ -116,7 +116,7 @@ void testReset()
{ {
puts("testReset"); puts("testReset");
Reset code; Reset code;
int (*f)(int) = (int (*)(int))code.getCode(); int (*f)(int) = code.getCode<int(*)(int)>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
code.init(i); code.init(i);
int v = f(i); int v = f(i);
@ -137,7 +137,7 @@ int main()
#else #else
puts("32bit"); puts("32bit");
#endif #endif
int (*func)(int) = (int (*)(int))(const void*)s.getCode(); int (*func)(int) = s.getCode<int (*)(int)>();
for (int i = 0; i <= 10; i++) { for (int i = 0; i <= 10; i++) {
printf("0 + ... + %d = %d\n", i, func(i)); printf("0 + ... + %d = %d\n", i, func(i));
} }
@ -159,9 +159,9 @@ int main()
uint8 *p = CodeArray::getAlignedAddress(buf); uint8 *p = CodeArray::getAlignedAddress(buf);
CodeArray::protect(p, codeSize, true); CodeArray::protect(p, codeSize, true);
Sample s(p, codeSize); Sample s(p, codeSize);
int (*func)(int) = (int (*)(int))(const void*)s.getCode(); int (*func)(int) = s.getCode<int (*)(int)>();
if ((uint8*)func != p) { if (Xbyak::CastTo<uint8*>(func) != p) {
fprintf(stderr, "internal error %p %p\n", p, func); fprintf(stderr, "internal error %p %p\n", p, Xbyak::CastTo<uint8*>(func));
return 1; return 1;
} }
printf("0 + ... + %d = %d\n", 100, func(100)); printf("0 + ... + %d = %d\n", 100, func(100));

View file

@ -50,7 +50,7 @@ void putCPUinfo()
if (cpu.has(Cpu::tPOPCNT)) { if (cpu.has(Cpu::tPOPCNT)) {
const int n = 0x12345678; // bitcount = 13 const int n = 0x12345678; // bitcount = 13
const int ok = 13; const int ok = 13;
int r = ((int (*)())((const void*)PopCountTest(n).getCode()))(); int r = PopCountTest(n).getCode<int (*)()>()();
if (r == ok) { if (r == ok) {
puts("popcnt ok"); puts("popcnt ok");
} else { } else {
@ -71,7 +71,7 @@ struct EipTest : public Xbyak::CodeGenerator {
void putEip() void putEip()
{ {
EipTest s; EipTest s;
int (*getEip)() = (int(*)())(const void*)s.getCode(); int (*getEip)() = s.getCode<int(*)()>();
printf("eip=%08x\n", getEip()); printf("eip=%08x\n", getEip());
} }
#endif #endif

View file

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

View file

@ -78,8 +78,9 @@ enum {
typedef unsigned __int64 uint64; typedef unsigned __int64 uint64;
typedef __int64 sint64; typedef __int64 sint64;
#else #else
typedef unsigned long long uint64; #include <stdint.h>
typedef long long sint64; typedef uint64_t uint64;
typedef int64_t sint64;
#endif #endif
typedef unsigned int uint32; typedef unsigned int uint32;
typedef unsigned short uint16; typedef unsigned short uint16;
@ -183,13 +184,19 @@ inline void AlignedFree(void *p)
free(p); free(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 {
enum { debug = 1 }; enum { debug = 1 };
static const size_t ALIGN_PAGE_SIZE = 4096; static const size_t ALIGN_PAGE_SIZE = 4096;
inline bool IsInDisp8(uint32 x) { return 0xFFFFFF80 <= x || x <= 0x7F; } inline bool IsInDisp8(uint32 x) { return 0xFFFFFF80 <= x || x <= 0x7F; }
inline bool IsInInt32(uint64 x) { return 0xFFFFFFFF80000000ULL <= x || x <= 0x7FFFFFFFU; } inline bool IsInInt32(uint64 x) { return ~uint64(0x7fffffffu) <= x || x <= 0x7FFFFFFFU; }
inline uint32 VerifyInInt32(uint64 x) inline uint32 VerifyInInt32(uint64 x)
{ {
@ -572,7 +579,11 @@ public:
void dw(uint32 code) { db(code, 2); } void dw(uint32 code) { db(code, 2); }
void dd(uint32 code) { db(code, 4); } void dd(uint32 code) { db(code, 4); }
const uint8 *getCode() const { return top_; } const uint8 *getCode() const { return top_; }
template<class F>
const F getCode() const { return CastTo<F>(top_); }
const uint8 *getCurr() const { return &top_[size_]; } const uint8 *getCurr() const { return &top_[size_]; }
template<class F>
const F getCurr() const { return CastTo<F>(&top_[size_]); }
size_t getSize() const { return size_; } size_t getSize() const { return size_; }
void dump() const void dump() const
{ {

View file

@ -233,25 +233,25 @@ self->L("@@");
int idx = out.getIdx(); int idx = out.getIdx();
switch (idx) { switch (idx) {
case Xbyak::Operand::EAX: case Xbyak::Operand::EAX:
self->call((void*)local::set_eip_to_eax); self->call(CastTo<void*>(local::set_eip_to_eax));
break; break;
case Xbyak::Operand::ECX: case Xbyak::Operand::ECX:
self->call((void*)local::set_eip_to_ecx); self->call(CastTo<void*>(local::set_eip_to_ecx));
break; break;
case Xbyak::Operand::EDX: case Xbyak::Operand::EDX:
self->call((void*)local::set_eip_to_edx); self->call(CastTo<void*>(local::set_eip_to_edx));
break; break;
case Xbyak::Operand::EBX: case Xbyak::Operand::EBX:
self->call((void*)local::set_eip_to_ebx); self->call(CastTo<void*>(local::set_eip_to_ebx));
break; break;
case Xbyak::Operand::ESI: case Xbyak::Operand::ESI:
self->call((void*)local::set_eip_to_esi); self->call(CastTo<void*>(local::set_eip_to_esi));
break; break;
case Xbyak::Operand::EDI: case Xbyak::Operand::EDI:
self->call((void*)local::set_eip_to_edi); self->call(CastTo<void*>(local::set_eip_to_edi));
break; break;
case Xbyak::Operand::EBP: case Xbyak::Operand::EBP:
self->call((void*)local::set_eip_to_ebp); self->call(CastTo<void*>(local::set_eip_to_ebp));
break; break;
default: default:
assert(0); assert(0);