FFI: Eliminate hardcoded string hashes.

This commit is contained in:
Mike Pall
2019-12-08 20:53:31 +01:00
parent 92fa45f9eb
commit 70f4b15ee4
3 changed files with 67 additions and 47 deletions

View File

@@ -720,50 +720,47 @@ LJLIB_CF(ffi_fill) LJLIB_REC(.)
return 0;
}
#define H_(le, be) LJ_ENDIAN_SELECT(0x##le, 0x##be)
/* Test ABI string. */
LJLIB_CF(ffi_abi) LJLIB_REC(.)
{
GCstr *s = lj_lib_checkstr(L, 1);
int b = 0;
switch (s->hash) {
int b = lj_cparse_case(s,
#if LJ_64
case H_(849858eb,ad35fd06): b = 1; break; /* 64bit */
"\00564bit"
#else
case H_(662d3c79,d0e22477): b = 1; break; /* 32bit */
"\00532bit"
#endif
#if LJ_ARCH_HASFPU
case H_(e33ee463,e33ee463): b = 1; break; /* fpu */
"\003fpu"
#endif
#if LJ_ABI_SOFTFP
case H_(61211a23,c2e8c81c): b = 1; break; /* softfp */
"\006softfp"
#else
case H_(539417a8,8ce0812f): b = 1; break; /* hardfp */
"\006hardfp"
#endif
#if LJ_ABI_EABI
case H_(2182df8f,f2ed1152): b = 1; break; /* eabi */
"\004eabi"
#endif
#if LJ_ABI_WIN
case H_(4ab624a8,4ab624a8): b = 1; break; /* win */
"\003win"
#endif
#if LJ_TARGET_UWP
case H_(a40f0bcb,a40f0bcb): b = 1; break; /* uwp */
"\003uwp"
#endif
#if LJ_LE
"\002le"
#else
"\002be"
#endif
case H_(3af93066,1f001464): b = 1; break; /* le/be */
#if LJ_GC64
case H_(9e89d2c9,13c83c92): b = 1; break; /* gc64 */
"\004gc64"
#endif
default:
break;
}
) >= 0;
setboolV(L->top-1, b);
setboolV(&G(L)->tmptv2, b); /* Remember for trace recorder. */
return 1;
}
#undef H_
LJLIB_PUSH(top-8) LJLIB_SET(!) /* Store reference to miscmap table. */
LJLIB_CF(ffi_metatype)