Merge branch 'main' of https://github.com/wasm3/wasm3 into main

extensions
Steven Massey 3 years ago
commit 451d2d11c5

@ -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;
i8 reserved;
_ (ReadLEB_i7 (& reserved, & o->wasm, o->wasmEnd));
_ (PreserveRegisterIfOccupied (o, c_m3Type_i32));
_ (EmitOp (o, op_MemCurrent));
_ (PushRegister (o, c_m3Type_i32));
@ -1971,7 +1973,7 @@ const M3OpInfo c_operations [] =
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( "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( "i32.const", 1, i_32, d_logOp (Const32), Compile_Const_i32 ), // 0x41
@ -2190,14 +2192,9 @@ M3Result Compile_BlockStatements (IM3Compilation o)
while (o->wasm < o->wasmEnd)
{ emit_stack_dump (o);
m3opcode_t opcode;
o->lastOpcodeStart = o->wasm;
m3opcode_t opcode = * (o->wasm++); log_opcode (o, opcode);
#ifndef d_m3CompileExtendedOpcode
if (UNLIKELY(opcode == 0xFC)) {
opcode = (opcode << 8) | (* (o->wasm++));
}
#endif
_ (Read_opcode (& opcode, & o->wasm, o->wasmEnd)); log_opcode (o, opcode);
IM3OpInfo opinfo = GetOpInfo(opcode);
_throwif (m3Err_unknownOpcode, opinfo == NULL);

@ -305,7 +305,32 @@ M3Result Read_u8 (u8 * o_value, bytes_t * io_bytes, cbytes_t i_end)
if (ptr < i_end)
{
* o_value = * ptr;
ptr += sizeof (u8);
* io_bytes = ptr + 1;
return m3Err_none;
}
else return m3Err_wasmUnderrun;
}
M3Result Read_opcode (m3opcode_t * o_value, bytes_t * io_bytes, cbytes_t i_end)
{
const u8 * ptr = * io_bytes;
if (ptr < i_end)
{
m3opcode_t opcode = * ptr++;
#ifndef d_m3CompileExtendedOpcode
if (UNLIKELY(opcode == 0xFC))
{
if (ptr < i_end)
{
opcode = (opcode << 8) | (* ptr++);
}
else return m3Err_wasmUnderrun;
}
#endif
* o_value = opcode;
* io_bytes = ptr;
return m3Err_none;

@ -84,12 +84,6 @@ const void * const cvptr_t;
# define m3log_compile(...) {}
# endif
# if d_m3LogWasmStack
# define m3log_stack(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
# define m3log_stack(...) {}
# endif
# if d_m3LogEmit
# define m3log_emit(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
@ -121,7 +115,7 @@ const void * const cvptr_t;
# endif
# if (defined(DEBUG) && !defined(NASSERTS))
# if defined(ASSERTS) || (defined(DEBUG) && !defined(NASSERTS))
# define d_m3Assert(ASS) if (!(ASS)) { printf("Assertion failed at %s:%d : %s\n", __FILE__, __LINE__, #ASS); abort(); }
# else
# define d_m3Assert(ASS)
@ -228,6 +222,7 @@ M3Result Read_f64 (f64 * o_value, bytes_t * io_bytes, cbytes_t
M3Result Read_f32 (f32 * o_value, bytes_t * io_bytes, cbytes_t i_end);
#endif
M3Result Read_u8 (u8 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result Read_opcode (m3opcode_t * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLebUnsigned (u64 * o_value, u32 i_maxNumBits, bytes_t * io_bytes, cbytes_t i_end);
M3Result ReadLebSigned (i64 * o_value, u32 i_maxNumBits, bytes_t * io_bytes, cbytes_t i_end);

@ -275,8 +275,6 @@ void DecodeOperation (char * o_string, u8 i_opcode, IM3Operation i_operation,
}
}
# ifdef DEBUG
// WARNING/TODO: this isn't fully implemented. it blindly assumes each word is a Operation pointer
// and, if an operation happens to missing from the c_operations table it won't be recognized here
void dump_code_page (IM3CodePage i_codePage, pc_t i_startPC)
@ -312,7 +310,6 @@ void dump_code_page (IM3CodePage i_codePage, pc_t i_startPC)
m3log (code, "free-lines: %d", i_codePage->info.numLines - i_codePage->info.lineIndex);
}
# endif
void dump_type_stack (IM3Compilation o)
@ -400,17 +397,13 @@ const char * get_indention_string (IM3Compilation o)
}
void log_opcode (IM3Compilation o, u8 i_opcode)
void log_opcode (IM3Compilation o, m3opcode_t i_opcode)
{
i32 depth = o->block.depth;
if (i_opcode == c_waOp_end or i_opcode == c_waOp_else)
depth--;
# ifdef DEBUG
m3log (compile, "%4d | 0x%02x %s %s", o->numOpcodes++, i_opcode, GetOpcodeIndentionString (depth), c_operations [i_opcode].name);
# else
m3log (compile, "%4d | 0x%02x %s", o->numOpcodes++, i_opcode, GetOpcodeIndentionString (depth));
# endif
m3log (compile, "%4d | 0x%02x %s %s", o->numOpcodes++, i_opcode, GetOpcodeIndentionString (depth), GetOpInfo(i_opcode)->name);
}
@ -432,7 +425,6 @@ void emit_stack_dump (IM3Compilation o)
void log_emit (IM3Compilation o, IM3Operation i_operation)
{
# ifdef DEBUG
OpInfo i = find_operation_info (i_operation);
d_m3Log(emit, "");
@ -441,7 +433,6 @@ void log_emit (IM3Compilation o, IM3Operation i_operation)
printf ("%p: %s\n", GetPC (o), i.info->name);
}
else printf ("not found: %p\n", i_operation);
# endif
}
#endif // DEBUG

@ -15,7 +15,7 @@ d_m3BeginExternC
#ifdef DEBUG
void dump_type_stack (IM3Compilation o);
void log_opcode (IM3Compilation o, u8 i_opcode);
void log_opcode (IM3Compilation o, m3opcode_t i_opcode);
const char * get_indention_string (IM3Compilation o);
void emit_stack_dump (IM3Compilation o);
void log_emit (IM3Compilation o, IM3Operation i_operation);

Loading…
Cancel
Save