|
|
@ -499,15 +499,15 @@ M3Result Pop (IM3Compilation o)
|
|
|
|
M3Result PopType (IM3Compilation o, u8 i_type)
|
|
|
|
M3Result PopType (IM3Compilation o, u8 i_type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
M3Result result = m3Err_none;
|
|
|
|
M3Result result = m3Err_none;
|
|
|
|
|
|
|
|
|
|
|
|
u8 topType = GetStackTopType (o);
|
|
|
|
u8 topType = GetStackTopType (o);
|
|
|
|
|
|
|
|
|
|
|
|
if (i_type == topType or o->block.isPolymorphic)
|
|
|
|
if (i_type == topType or o->block.isPolymorphic)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
result = Pop (o);
|
|
|
|
result = Pop (o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else result = m3Err_typeMismatch;
|
|
|
|
else result = m3Err_typeMismatch;
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1011,7 +1011,7 @@ M3Result Compile_Return (IM3Compilation o, m3opcode_t i_opcode)
|
|
|
|
if (GetFunctionNumReturns (o->function))
|
|
|
|
if (GetFunctionNumReturns (o->function))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
u8 type = GetFunctionReturnType (o->function, 0);
|
|
|
|
u8 type = GetFunctionReturnType (o->function, 0);
|
|
|
|
|
|
|
|
|
|
|
|
_ (ReturnStackTop (o));
|
|
|
|
_ (ReturnStackTop (o));
|
|
|
|
_ (PopType (o, type));
|
|
|
|
_ (PopType (o, type));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1037,7 +1037,7 @@ M3Result Compile_End (IM3Compilation o, m3opcode_t i_opcode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (not o->block.isPolymorphic and type != GetStackTopType (o))
|
|
|
|
if (not o->block.isPolymorphic and type != GetStackTopType (o))
|
|
|
|
_throw (m3Err_typeMismatch);
|
|
|
|
_throw (m3Err_typeMismatch);
|
|
|
|
|
|
|
|
|
|
|
|
// if there are branches to the function end, then their values are in a register
|
|
|
|
// if there are branches to the function end, then their values are in a register
|
|
|
|
// if the block happens to have its top in a register too, then we can patch the branch
|
|
|
|
// if the block happens to have its top in a register too, then we can patch the branch
|
|
|
|
// to here. Otherwise, an ReturnStackTop is appended to the end of the function (at B) and
|
|
|
|
// to here. Otherwise, an ReturnStackTop is appended to the end of the function (at B) and
|
|
|
@ -1486,13 +1486,15 @@ _ (EmitOp (o, op_CallIndirect));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
M3Result Compile_Memory_Current (IM3Compilation o, m3opcode_t i_opcode)
|
|
|
|
M3Result Compile_Memory_Size (IM3Compilation o, m3opcode_t i_opcode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
M3Result result;
|
|
|
|
M3Result result;
|
|
|
|
|
|
|
|
|
|
|
|
i8 reserved;
|
|
|
|
i8 reserved;
|
|
|
|
_ (ReadLEB_i7 (& reserved, & o->wasm, o->wasmEnd));
|
|
|
|
_ (ReadLEB_i7 (& reserved, & o->wasm, o->wasmEnd));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ (PreserveRegisterIfOccupied (o, c_m3Type_i32));
|
|
|
|
|
|
|
|
|
|
|
|
_ (EmitOp (o, op_MemCurrent));
|
|
|
|
_ (EmitOp (o, op_MemCurrent));
|
|
|
|
|
|
|
|
|
|
|
|
_ (PushRegister (o, c_m3Type_i32));
|
|
|
|
_ (PushRegister (o, c_m3Type_i32));
|
|
|
@ -1971,8 +1973,8 @@ const M3OpInfo c_operations [] =
|
|
|
|
M3OP( "i64.store16", -2, none, d_binOpList (i64, Store_i16), Compile_Load_Store ), // 0x3d
|
|
|
|
M3OP( "i64.store16", -2, none, d_binOpList (i64, Store_i16), Compile_Load_Store ), // 0x3d
|
|
|
|
M3OP( "i64.store32", -2, none, d_binOpList (i64, Store_i32), Compile_Load_Store ), // 0x3e
|
|
|
|
M3OP( "i64.store32", -2, none, d_binOpList (i64, Store_i32), Compile_Load_Store ), // 0x3e
|
|
|
|
|
|
|
|
|
|
|
|
M3OP( "memory.current", 1, i_32, d_logOp (MemCurrent), Compile_Memory_Current ), // 0x3f
|
|
|
|
M3OP( "memory.size", 1, i_32, d_logOp (MemCurrent), Compile_Memory_Size ), // 0x3f
|
|
|
|
M3OP( "memory.grow", 1, i_32, d_logOp (MemGrow), Compile_Memory_Grow ), // 0x40
|
|
|
|
M3OP( "memory.grow", 1, i_32, d_logOp (MemGrow), Compile_Memory_Grow ), // 0x40
|
|
|
|
|
|
|
|
|
|
|
|
M3OP( "i32.const", 1, i_32, d_logOp (Const32), Compile_Const_i32 ), // 0x41
|
|
|
|
M3OP( "i32.const", 1, i_32, d_logOp (Const32), Compile_Const_i32 ), // 0x41
|
|
|
|
M3OP( "i64.const", 1, i_64, d_logOp (Const64), Compile_Const_i64 ), // 0x42
|
|
|
|
M3OP( "i64.const", 1, i_64, d_logOp (Const64), Compile_Const_i64 ), // 0x42
|
|
|
@ -2190,14 +2192,9 @@ M3Result Compile_BlockStatements (IM3Compilation o)
|
|
|
|
|
|
|
|
|
|
|
|
while (o->wasm < o->wasmEnd)
|
|
|
|
while (o->wasm < o->wasmEnd)
|
|
|
|
{ emit_stack_dump (o);
|
|
|
|
{ emit_stack_dump (o);
|
|
|
|
|
|
|
|
m3opcode_t opcode;
|
|
|
|
o->lastOpcodeStart = o->wasm;
|
|
|
|
o->lastOpcodeStart = o->wasm;
|
|
|
|
m3opcode_t opcode = * (o->wasm++); log_opcode (o, opcode);
|
|
|
|
_ (Read_opcode (& opcode, & o->wasm, o->wasmEnd)); log_opcode (o, opcode);
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef d_m3CompileExtendedOpcode
|
|
|
|
|
|
|
|
if (UNLIKELY(opcode == 0xFC)) {
|
|
|
|
|
|
|
|
opcode = (opcode << 8) | (* (o->wasm++));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IM3OpInfo opinfo = GetOpInfo(opcode);
|
|
|
|
IM3OpInfo opinfo = GetOpInfo(opcode);
|
|
|
|
_throwif (m3Err_unknownOpcode, opinfo == NULL);
|
|
|
|
_throwif (m3Err_unknownOpcode, opinfo == NULL);
|
|
|
@ -2380,7 +2377,7 @@ _try {
|
|
|
|
// skip over code size. the end was already calculated during parse phase
|
|
|
|
// skip over code size. the end was already calculated during parse phase
|
|
|
|
u32 size;
|
|
|
|
u32 size;
|
|
|
|
_ (ReadLEB_u32 (& size, & o->wasm, o->wasmEnd)); d_m3Assert (size == (o->wasmEnd - o->wasm))
|
|
|
|
_ (ReadLEB_u32 (& size, & o->wasm, o->wasmEnd)); d_m3Assert (size == (o->wasmEnd - o->wasm))
|
|
|
|
|
|
|
|
|
|
|
|
_ (AcquireCompilationCodePage (o, & o->page));
|
|
|
|
_ (AcquireCompilationCodePage (o, & o->page));
|
|
|
|
|
|
|
|
|
|
|
|
pc_t pc = GetPagePC (o->page);
|
|
|
|
pc_t pc = GetPagePC (o->page);
|
|
|
|