extensions
Steven Massey 5 years ago
parent 215e13d331
commit 56fb008295

@ -1041,10 +1041,12 @@ M3Result ReadBlockType (IM3Compilation o, u8 * o_blockType)
}
M3Result Compile_Loop_Block (IM3Compilation o, u8 i_opcode)
M3Result Compile_LoopOrBlock (IM3Compilation o, u8 i_opcode)
{
M3Result result;
_ (PreserveRegisters (o));
u8 blockType;
_ (ReadBlockType (o, & blockType));
@ -1244,8 +1246,8 @@ const M3OpInfo c_operations [] =
{
{ "unreachable", 0, none, NULL, NULL, NULL, Compile_Trap }, // 0x00
{ "nop", 0, none, NULL, NULL, NULL, Compile_Nop }, // 0x01 .
{ "block", 0, none, NULL, NULL, NULL, Compile_Loop_Block }, // 0x02
{ "loop", 0, none, NULL, NULL, NULL, Compile_Loop_Block }, // 0x03
{ "block", 0, none, NULL, NULL, NULL, Compile_LoopOrBlock }, // 0x02
{ "loop", 0, none, NULL, NULL, NULL, Compile_LoopOrBlock }, // 0x03
{ "if", -1, none, NULL, NULL, NULL, Compile_If }, // 0x04
{ "else", 0, none, NULL, NULL, NULL, Compile_Else_End }, // 0x05
@ -1282,7 +1284,7 @@ const M3OpInfo c_operations [] =
{ "i32.load8_s", 0, i_32, op_i32_Load_i8_r, op_i32_Load_i8_s, NULL, Compile_Load_Store }, // 0x2c
{ "i32.load8_u", 0, i_32, op_i32_Load_u8_r, op_i32_Load_u8_s, NULL, Compile_Load_Store }, // 0x2d
{ "i32.load16_s", 0, i_32, NULL, NULL, NULL, Compile_Load_Store }, // 0x2e
{ "i32.load16_s", 0, i_32, op_i32_Load_i16_r, op_i32_Load_i16_s, NULL, Compile_Load_Store }, // 0x2e
{ "i32.load16_u", 0, i_32, op_i32_Load_u16_r, op_i32_Load_u16_s, NULL, Compile_Load_Store }, // 0x2f
{ "i64.load8_s", 0, i_64, NULL, NULL, NULL, }, // 0x30
@ -1571,27 +1573,28 @@ M3Result Compile_Block (IM3Compilation o, u8 i_blockType, u8 i_blockOpcode)
{
M3Result result;
// if (i_blockOpcode != c_waOp_block) yes or no??
{
u16 i = GetFunctionNumArgsAndLocals (o->function);
while (i < o->stackIndex)
{
u16 location = o->wasmStack [i];
if (IsRegisterLocation (location))
{
printf ("deal! %d - %d \n", (i32) i, (i32) location);
abort ();
d_m3Assert(false);
}
++i;
}
} d_m3Assert (not IsRegisterAllocated (o, 0));
d_m3Assert (not IsRegisterAllocated (o, 1));
u32 numArgsAndLocals = GetFunctionNumArgsAndLocals (o->function);
// save and clear the locals modification slots
u16 locals [numArgsAndLocals];
// {
// u16 i = GetFunctionNumArgsAndLocals (o->function);
// while (i < o->stackIndex)
// {
// u16 location = o->wasmStack [i];
// if (IsRegisterLocation (location))
// {
// printf ("deal! %d - %d \n", (i32) i, (i32) location);
//// abort ();
//// d_m3Assert(false);
// }
// ++i;
// }
// }
d_m3Assert (not IsRegisterAllocated (o, 0));
d_m3Assert (not IsRegisterAllocated (o, 1));
memcpy (locals, o->wasmStack, numArgsAndLocals * sizeof (u16));
for (u32 i = 0; i < numArgsAndLocals; ++i)
{

@ -10,12 +10,14 @@
#include "m3_compile.h"
void ReportOutOfBoundsMemoryError (pc_t i_pc, u8 * i_mem, u32 i_offset)
m3ret_t ReportOutOfBoundsMemoryError (pc_t i_pc, u8 * i_mem, u32 i_offset)
{
M3MemoryHeader * info = (M3MemoryHeader *) (i_mem - sizeof (M3MemoryHeader));
u8 * mem8 = i_mem + i_offset;
ErrorModule (c_m3Err_trapOutOfBoundsMemoryAccess, info->module, "memory bounds: [%p %p); accessed: %p; offset: %u overflow: %lld bytes", i_mem, info->end, mem8, i_offset, mem8 - (u8 *) info->end);
return c_m3Err_trapOutOfBoundsMemoryAccess;
}
@ -126,10 +128,14 @@ d_m3OpDef (Entry)
if (d_m3Log_exec)
{
char str [100];
SPrintArg (str, 99, _sp, function->funcType->returnType);
m3log (exec, " exit < %s -> %s %s\n", function->name, str, r ? r : "");
u8 returnType = function->funcType->returnType;
char str [100] = { '!', 0 };
if (not r)
SPrintArg (str, 99, _sp, function->funcType->returnType);
m3log (exec, " exit < %s %s %s %s\n", function->name, returnType ? "->" : "", str, r ? r : "");
}
return r;

@ -738,26 +738,47 @@ d_m3Op (PreserveSetSlot_f)
}
#define d_m3Load(REG,DEST,SRC) static inline m3ret_t vectorcall op_##DEST##_Load_##SRC##_r (d_m3OpSig) \
{ \
u32 offset = immediate (u32); \
u32 operand = (u32) _r0; \
SRC * source = (SRC *) (_mem + operand + offset); \
REG = (DEST) * source; \
return nextOp (); \
} \
static inline m3ret_t vectorcall op_##DEST##_Load_##SRC##_s (d_m3OpSig) \
{ \
u32 operand = * (u32 *) (_sp + immediate (i32)); \
u32 offset = immediate (u32); \
SRC * source = (SRC *) (_mem + operand + offset); \
REG = (DEST) * source; \
return nextOp (); \
//#define d_outOfBounds return c_m3Err_trapOutOfBoundsMemoryAccess
m3ret_t ReportOutOfBoundsMemoryError (pc_t i_pc, u8 * i_mem, u32 i_offset);
#define d_outOfBounds { printf ("%d %p\n", operand, end); return ReportOutOfBoundsMemoryError (_pc, _mem, operand); }
#define d_m3Load(REG,DEST_TYPE,SRC_TYPE) static inline m3ret_t vectorcall op_##DEST_TYPE##_Load_##SRC_TYPE##_r (d_m3OpSig) \
{ \
u32 offset = immediate (u32); \
u32 operand = (u32) _r0; \
\
u8 * src8 = _mem + operand + offset; \
u8 * end = * ((u8 **) _mem - 1); \
\
if (src8 + sizeof (SRC_TYPE) <= end) \
{ \
REG = (DEST_TYPE) (* (SRC_TYPE *) src8); \
return nextOp (); \
} \
else d_outOfBounds; \
} \
static inline m3ret_t vectorcall op_##DEST_TYPE##_Load_##SRC_TYPE##_s (d_m3OpSig) \
{ \
u32 operand = * (u32 *) (_sp + immediate (i32)); \
u32 offset = immediate (u32); \
\
u8 * src8 = _mem + operand + offset; \
u8 * end = * ((u8 **) _mem - 1); \
\
if (src8 + sizeof (SRC_TYPE) <= end) \
{ \
REG = (DEST_TYPE) (* (SRC_TYPE *) src8); \
return nextOp (); \
} \
else d_outOfBounds; \
}
// printf ("get: %d -> %d\n", operand + offset, (i64) REG); \
#define d_m3Load_i(DEST, SRC) d_m3Load(_r0, DEST, SRC)
#define d_m3Load_i(DEST_TYPE, SRC_TYPE) d_m3Load(_r0, DEST_TYPE, SRC_TYPE)
d_m3Load_i (i32, i32);
@ -777,12 +798,6 @@ d_m3Op (f64_Store)
return nextOp ();
}
//#define d_outOfBounds return c_m3Err_trapOutOfBoundsMemoryAccess
void ReportOutOfBoundsMemoryError (pc_t i_pc, u8 * i_mem, u32 i_offset);
#define d_outOfBounds { printf ("%d %p\n", operand, end); ReportOutOfBoundsMemoryError (_pc, _mem, operand); return c_m3Err_trapOutOfBoundsMemoryAccess; }
#define d_m3Store_i(SRC_TYPE, SIZE_TYPE) \
d_m3Op (SRC_TYPE##_Store_##SIZE_TYPE##_sr) \

@ -73,6 +73,8 @@ size_t SPrintArg (char * o_string, size_t i_n, m3stack_t i_sp, u8 i_type)
{
size_t len = 0;
* o_string = 0;
if (i_type == c_m3Type_i32)
len = snprintf (o_string, i_n, "%d", * (i32 *) i_sp);
else if (i_type == c_m3Type_i64)

Loading…
Cancel
Save