static void DumpCode(const Proto *f, DumpState* D) { DumpInt(f->sizecode,D); char buf[10]; int i; for (i=0; i<f->sizecode; i++) { memcpy(buf,&f->code[i],sizeof(Instruction)); MaybeByteSwap(buf,sizeof(Instruction),D); DumpBlock(buf,sizeof(Instruction),D); } }
static void DumpNumber(lua_Number x, DumpState* D) { #if defined( LUA_NUMBER_INTEGRAL ) && !defined( LUA_CROSS_COMPILER ) DumpIntWithSize(x,D->target.sizeof_lua_Number,D); #else // #if defined( LUA_NUMBER_INTEGRAL ) && !defined( LUA_CROSS_COMPILER ) if (D->target.lua_Number_integral) { if (((float)(int)x)!=x) D->status=LUA_ERR_CC_NOTINTEGER; DumpIntWithSize(x,D->target.sizeof_lua_Number,D); } else { switch(D->target.sizeof_lua_Number) { /* do we need bounds checking? */ case 4: { float y=x; MaybeByteSwap((char*)&y,4,D); DumpVar(y,D); } break; case 8: { double y=x; // ARM FPA mode: keep endianness, but swap high and low parts of the // memory representation. This is the default compilation mode for ARM // targets with non-EABI gcc if(D->target.is_arm_fpa) { char *pnum=(char*)&y, temp[4]; memcpy(temp,pnum,4); memcpy(pnum,pnum+4,4); memcpy(pnum+4,temp,4); } MaybeByteSwap((char*)&y,8,D); DumpVar(y,D); } break; default: lua_assert(0); } } #endif // #if defined( LUA_NUMBER_INTEGRAL ) && !defined( LUA_CROSS_COMPILER ) }
static void DumpIntWithSize(int x, int sizeof_int, DumpState* D) { /* dump signed integer */ switch(sizeof_int) { case 1: { if (x>0x7F || x<(-0x80)) D->status=LUA_ERR_CC_INTOVERFLOW; DumpChar(x,D); } break; case 2: { if (x>0x7FFF || x<(-0x8000)) D->status=LUA_ERR_CC_INTOVERFLOW; int16_t y=(int16_t)x; MaybeByteSwap((char*)&y,2,D); DumpVar(y,D); } break; case 4: { /* Need to reduce bounds by 1 to avoid messing 32-bit compilers up */ if (x>0x7FFFFFFE || x<(-0x7FFFFFFF)) D->status=LUA_ERR_CC_INTOVERFLOW; int32_t y=(int32_t)x; MaybeByteSwap((char*)&y,4,D); DumpVar(y,D); } break; default: lua_assert(0); } }
static void DumpSize(uint32_t x, DumpState* D) { /* dump unsigned integer */ switch(D->target.sizeof_strsize_t) { case 1: { if (x>0xFF) D->status=LUA_ERR_CC_INTOVERFLOW; DumpChar(x,D); } break; case 2: { if (x>0xFFFF) D->status=LUA_ERR_CC_INTOVERFLOW; uint16_t y=(uint16_t)x; MaybeByteSwap((char*)&y,2,D); DumpVar(y,D); } break; case 4: { /* Reduce bounds to avoid messing 32-bit compilers up */ if (x>0xFFFFFFFE) D->status=LUA_ERR_CC_INTOVERFLOW; uint32_t y=x; MaybeByteSwap((char*)&y,4,D); DumpVar(y,D); } break; default: lua_assert(0); } }