Fix fpermissive flag requirement

extensions
Volodymyr Shymanskyy 5 years ago
parent ddcb3ce995
commit 074f6918c2

@ -35,9 +35,9 @@ typedef f64 (* M3ArgPusherFpReturn) (d_m3BindingArgList, M3State * i_state);
m3ret_t PushArg_module (d_m3BindingArgList, M3State * _state)
{
void ** ptr = (void **) _state->mem;
IM3Module module = * (ptr - 2);
IM3Module module = (IM3Module)(*(ptr - 2));
_i0 = (i64) module;
M3ArgPusher pusher = (* _state->pc++);
M3ArgPusher pusher = (M3ArgPusher)(* _state->pc++);
return pusher (d_m3BindingArgs, _state);
}
@ -47,7 +47,7 @@ m3ret_t PushArg_p##INDEX (d_m3BindingArgList, M3State * _state) \
{ \
i32 offset = (u32) * (_state->sp++); \
_i##INDEX = (i64) (_state->mem + offset); \
M3ArgPusher pusher = (* _state->pc++); \
M3ArgPusher pusher = (M3ArgPusher)(* _state->pc++); \
if (0) printf ("push ptr: r%d off: %d\n", INDEX, offset); \
return pusher (d_m3BindingArgs, _state); \
}
@ -57,7 +57,7 @@ m3ret_t PushArg_p##INDEX (d_m3BindingArgList, M3State * _state) \
m3ret_t PushArg_i##INDEX (d_m3BindingArgList, M3State * _state) \
{ \
_i##INDEX = * (_state->sp++); \
M3ArgPusher pusher = (* _state->pc++); \
M3ArgPusher pusher = (M3ArgPusher)(* _state->pc++); \
return pusher (d_m3BindingArgs, _state); \
}
@ -67,7 +67,7 @@ m3ret_t PushArg_i##INDEX (d_m3BindingArgList, M3State * _state) \
m3ret_t PushArg_##TYPE##_##INDEX (d_m3BindingArgList, M3State * _state) \
{ \
_f##INDEX = * (TYPE *) (_state->sp++); \
M3ArgPusher pusher = (* _state->pc++); \
M3ArgPusher pusher = (M3ArgPusher)(* _state->pc++); \
return pusher (d_m3BindingArgs, _state); \
}
@ -139,10 +139,10 @@ d_m3RetSig CallCFunction_ptr (d_m3OpSig)
M3ArgPusher pusher = (M3ArgPusher) (* _pc++);
M3State state = { _pc, _sp, _mem };
const u8 * r = pusher (0, 0, 0, 0, 0., 0., 0., 0., & state);
const u8 * r = (const u8*)pusher (0, 0, 0, 0, 0., 0., 0., 0., & state);
void ** ptr = (void **) _mem;
IM3Module module = * (ptr - 2);
IM3Module module = (IM3Module)(* (ptr - 2));
size_t offset = r - (const u8 *) module->memory.wasmPages;

@ -59,7 +59,7 @@ u32 NumFreeLines (IM3CodePage i_page)
}
void EmitWord (IM3CodePage i_page, const void * const i_word)
void EmitWordImpl (IM3CodePage i_page, const void * i_word)
{
i_page->code [i_page->info.lineIndex++] = (void *) i_word;

@ -30,7 +30,7 @@ void FreeCodePages (IM3CodePage i_page);
//void CloseCodePage (IM3CodePage i_page);
u32 NumFreeLines (IM3CodePage i_page);
pc_t GetPagePC (IM3CodePage i_page);
void EmitWord (IM3CodePage i_page, const void * const i_word);
void EmitWordImpl (IM3CodePage i_page, const void * i_word);
void PushCodePage (IM3CodePage * i_list, IM3CodePage i_codePage);
IM3CodePage PopCodePage (IM3CodePage * i_list);
@ -38,5 +38,6 @@ IM3CodePage PopCodePage (IM3CodePage * i_list);
void TestCodePageCapacity (IM3CodePage i_page);
void DumpCodePage (IM3CodePage i_codePage, pc_t i_startPC);
#define EmitWord(page, val) EmitWordImpl(page, (void*)(val))
#endif /* m3_code_h */

@ -661,6 +661,7 @@ M3Result Compile_Const_f32 (IM3Compilation o, u8 i_opcode)
{
M3Result result;
_try {
u32 value;
_ (ReadLEB_u32 (& value, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const f32 = %f)", GetIndentionString (o), * ((f32 *) & value));
@ -668,7 +669,7 @@ _ (ReadLEB_u32 (& value, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%
f64 f = * (f32 *) & value;
_ (PushConst (o, * (u64 *) & f, c_m3Type_f64));
_catch: return result;
} _catch: return result;
}
@ -761,13 +762,13 @@ M3Result Compile_GetLocal (IM3Compilation o, u8 i_opcode)
{
M3Result result;
_try {
u32 localIndex;
_ (ReadLEB_u32 (& localIndex, & o->wasm, o->wasmEnd));
u8 type = o->typeStack [localIndex];
Push (o, type, localIndex);
_catch: return result;
} _catch: return result;
}
@ -876,7 +877,7 @@ _ (EmitOp (o, op));
_ (m3Alloc (& scope->patches, M3BranchPatch, 1));
// printf ("scope: %p -- attach patch: %p to %p \n", scope, scope->patches, patch);
scope->patches->location = ReservePointer (o);
scope->patches->location = (pc_t*)ReservePointer (o);
scope->patches->next = patch;
}
@ -888,6 +889,7 @@ M3Result Compile_BranchTable (IM3Compilation o, u8 i_opcode)
{
M3Result result;
_try {
u32 targetCount;
_ (ReadLEB_u32 (& targetCount, & o->wasm, o->wasmEnd));
@ -921,12 +923,12 @@ _ (GetBlockScope (o, & scope, target));
IM3BranchPatch patch = scope->patches;
_ (m3Alloc (& scope->patches, M3BranchPatch, 1));
scope->patches->location = ReservePointer (o);
scope->patches->location = (pc_t*)ReservePointer (o);
scope->patches->next = patch;
}
}
_catch: return result;
} _catch: return result;
}
@ -934,6 +936,7 @@ M3Result CompileCallArgsReturn (IM3Compilation o, IM3FuncType i_type, bool i_i
{
M3Result result = c_m3Err_none;
_try {
u16 execTop = GetMaxExecSlot (o);
u32 numArgs = i_type->numArgs + i_isIndirect;
u16 argTop = execTop + numArgs;
@ -954,7 +957,7 @@ _ (Pop (o));
Push (o, i_type->returnType, execTop);
}
_catch: return result;
} _catch: return result;
}
@ -962,6 +965,7 @@ M3Result Compile_Call (IM3Compilation o, u8 i_opcode)
{
M3Result result;
_try {
u32 functionIndex;
_ (ReadLEB_u32 (& functionIndex, & o->wasm, o->wasmEnd));
@ -972,7 +976,7 @@ _ (ReadLEB_u32 (& functionIndex, & o->wasm, o->wasmEnd));
GetIndentionString (o), GetFunctionName (function), function->funcType->numArgs);
if (function->module)
{
// OPTZ: could avoid arg copy when args are already sequential and at top
// TODO OPTZ: could avoid arg copy when args are already sequential and at top
u16 execTop = GetMaxExecSlot (o);
@ -1000,7 +1004,7 @@ _ (EmitOp (o, op));
}
else result = c_m3Err_functionLookupFailed;
_catch: return result;
} _catch: return result;
}
@ -1023,7 +1027,7 @@ _ (CompileCallArgsReturn (o, type, true));
_ (EmitOp (o, op_CallIndirect));
EmitPointer (o, o->module);
EmitPointer (o, type); // TODO: unify all types in M3Rsuntime
EmitPointer (o, type); // TODO: unify all types in M3Runtime
EmitOffset (o, execTop);
}
else _throw ("function type index out of range");
@ -1066,6 +1070,7 @@ M3Result Compile_If (IM3Compilation o, u8 i_opcode)
{
M3Result result;
_try {
_ (PreserveNonTopRegisters (o));
IM3Operation op = IsStackTopInRegister (o) ? op_If_r : op_If_s;
@ -1075,8 +1080,8 @@ _ (EmitTopSlotAndPop (o));
i32 stackIndex = o->stackIndex;
pc_t * preservations = ReservePointer (o);
pc_t * pc = ReservePointer (o);
pc_t * preservations = (pc_t*)ReservePointer (o);
pc_t * pc = (pc_t*)ReservePointer (o);
u8 blockType;
_ (ReadBlockType (o, & blockType));
@ -1094,7 +1099,7 @@ _ (Compile_ElseBlock (o, pc, blockType));
}
else * pc = GetPC (o);
_catch: return result;
} _catch: return result;
}
@ -1120,7 +1125,7 @@ M3Result Compile_Select (IM3Compilation o, u8 i_opcode)
_ (Pop (o));
}
d_m3AssertFatal (IsIntType (type)); // fp unimplemented
d_m3AssertFatal (IsIntType (type)); // TODO: fp unimplemented
// this operation doesn't consume a register, so might have to protected its contents
if (op == op_Select_i_sss)
@ -1158,7 +1163,7 @@ M3Result Compile_Trap (IM3Compilation o, u8 i_opcode)
}
// OPTZ: currently all stack slot indicies take up a full word, but
// TODO OPTZ: currently all stack slot indicies take up a full word, but
// dual stack source operands could be packed together
M3Result Compile_Operator (IM3Compilation o, u8 i_opcode)
{

@ -293,7 +293,7 @@ _ (ReadLEB_u32 (& numElements, & bytes, end));
if (endElement > offset)
{
io_module->table0 = m3RellocArray (io_module->table0, IM3Function, endElement, io_module->table0Size);
io_module->table0 = (IM3Function*)m3RellocArray (io_module->table0, IM3Function, endElement, io_module->table0Size);
if (io_module->table0)
{
@ -366,7 +366,7 @@ M3Result m3_FindFunction (IM3Function * o_function, IM3Runtime i_runtime, cons
{
M3Result result = c_m3Err_none;
IM3Function function = ForEachModule (i_runtime, (ModuleVisitor) v_FindFunction, (void *) i_functionName);
IM3Function function = (IM3Function)ForEachModule (i_runtime, (ModuleVisitor) v_FindFunction, (void *) i_functionName);
if (function)
{
@ -407,12 +407,12 @@ M3Result m3_CallWithArgs (IM3Function i_function, i32 i_argc, ccstr_t * i_argv
u8 * linearMemory = module->memory.wasmPages;
m3stack_t stack = env->stack;
m3stack_t stack = (m3stack_t)(env->stack);
m3logif (runtime, PrintFuncTypeSignature (ftype));
if (i_argc != ftype->numArgs) {
_throw("arguments count missmatch");
_throw("arguments count mismatch");
}
// The format is currently not user-friendly by default,
@ -437,7 +437,7 @@ M3Result m3_CallWithArgs (IM3Function i_function, i32 i_argc, ccstr_t * i_argv
}
}
_ (Call (i_function->compiled, stack, linearMemory, d_m3OpDefaultArgs));
_ ((M3Result)Call (i_function->compiled, stack, linearMemory, d_m3OpDefaultArgs));
switch (ftype->returnType) {
case c_m3Type_none: break;
@ -477,7 +477,7 @@ _ (Module_EnsureMemorySize (module, & i_function->module->memory, 3000000));
u8 * linearMemory = module->memory.wasmPages;
m3stack_t stack = env->stack;
m3stack_t stack = (m3stack_t)(env->stack);
if (i_argc)
{
@ -505,7 +505,7 @@ _ (Module_EnsureMemorySize (module, & i_function->module->memory, 3000000));
stack [1] = offset;
}
_ (Call (i_function->compiled, stack, linearMemory, d_m3OpDefaultArgs));
_ ((M3Result)Call (i_function->compiled, stack, linearMemory, d_m3OpDefaultArgs));
u64 value = * (u64 *) (stack);
m3log (runtime, "return64: %llu return32: %u", value, (u32) value);

@ -21,9 +21,9 @@ m3ret_t ReportOutOfBoundsMemoryError (pc_t i_pc, u8 * i_mem, u32 i_offset)
}
void ReportError2 (IM3Function i_function, M3Result i_result)
void ReportError2 (IM3Function i_function, m3ret_t i_result)
{
i_function->module->runtime->runtimeError = i_result;
i_function->module->runtime->runtimeError = (M3Result)i_result;
}
@ -92,7 +92,7 @@ d_m3OpDef (Compile)
IM3Function function = immediate (IM3Function);
M3Result result = c_m3Err_none;
m3ret_t result = c_m3Err_none;
if (not function->compiled) // check to see if function was compiled since this operation was emitted.
result = Compile_Function (function);
@ -272,16 +272,3 @@ d_m3OpDef (IfPreserve)
else
return d_else (elsePC);
}
d_m3OpDef (Trap)
{ m3log (exec, "*** trapping ***");
return c_m3Err_runtimeTrap;
}
d_m3OpDef (End)
{
return 0;
}

@ -19,7 +19,7 @@
#include <math.h>
#include <limits.h>
# define rewrite(NAME) * ((void **) (_pc-1)) = NAME
# define rewrite(NAME) * ((void **) (_pc-1)) = (void*)(NAME)
# define d_m3RetSig static inline m3ret_t vectorcall
# define d_m3Op(NAME) d_m3RetSig op_##NAME (d_m3OpSig)
@ -32,7 +32,7 @@
# define slot(TYPE) * (TYPE *) (_sp + immediate (i32))
# if d_m3EnableOpProfiling
# define nextOp() profileOp (_pc, d_m3OpArgs, __PRETTY_FUNCTION__)
# define nextOp() profileOp (d_m3OpAllArgs, __PRETTY_FUNCTION__)
# endif
# if d_m3TraceExec
@ -43,20 +43,20 @@
# define nextOp() ((IM3Operation)(* _pc))(_pc + 1, d_m3OpArgs)
# endif
#define d_call(PC) Call (PC, d_m3OpArgs)
#define d_call(PC) Call ((pc_t)PC, d_m3OpArgs)
#define d_else(PC) Else (PC, d_m3OpArgs)
#define d_else(PC) Else ((pc_t)PC, d_m3OpArgs)
d_m3RetSig Call (d_m3OpSig)
{
IM3Operation operation = (* _pc);
IM3Operation operation = (IM3Operation)(* _pc);
return operation (_pc + 1, d_m3OpArgs);
}
d_m3RetSig Else (d_m3OpSig)
{
IM3Operation operation = (* _pc);
IM3Operation operation = (IM3Operation)(* _pc);
return operation (_pc + 1, d_m3OpArgs);
}
@ -527,9 +527,17 @@ d_m3Op (Const)
}
d_m3OpDecl (Trap)
d_m3Op (Trap)
{ m3log (exec, "*** trapping ***");
return c_m3Err_runtimeTrap;
}
d_m3Op (End)
{
return 0;
}
d_m3OpDecl (End)
d_m3Op (GetGlobal)
@ -713,7 +721,8 @@ d_m3Op(DEST_TYPE##_Load_##SRC_TYPE##_s) \
} \
else d_outOfBounds; \
}
// printf ("get: %d -> %d\n", operand + offset, (i64) REG); \
// printf ("get: %d -> %d\n", operand + offset, (i64) REG);
#define d_m3Load_i(DEST_TYPE, SRC_TYPE) d_m3Load(_r0, DEST_TYPE, SRC_TYPE)

@ -14,9 +14,16 @@
// default Windows x64 calling convention doesn't have enough registers for M3. It only supports
// 4 args passed through registers but its enhanced __vectorcall calling convention does.
# if defined (_WIN32) || defined (WIN32)
# if defined (M3_COMPILER_MSVC)
# define vectorcall
# elif defined(WIN32)
# define vectorcall __vectorcall
#
# elif defined (ESP8266)
# include <c_types.h>
# define vectorcall //ICACHE_FLASH_ATTR
# elif defined (ESP32)
# include "esp_system.h"
# define vectorcall IRAM_ATTR
# else
# define vectorcall
# endif

@ -15,7 +15,7 @@
#include <stdio.h>
#include <assert.h>
#ifndef WIN32
#if !defined(WIN32) && !defined(ESP8266) && !defined(WM_W600)
#include <unistd.h>
#include <sys/ioctl.h>
#endif
@ -27,7 +27,7 @@ void m3_printf (cstr_t i_format, const void * i_varArgs)
char output [c_bufferLength];
size_t formatLength = strlen (i_format) + 1;
char * buffer = formatLength <= c_bufferLength ? format : malloc (formatLength);
char * buffer = formatLength <= c_bufferLength ? format : (char*)malloc (formatLength);
size_t numArgs = 0;
char * p = 0;
@ -143,7 +143,7 @@ i32 m3_getStderr (IM3Module i_module)
i32 m3_fread (void * io_ptr, i32 i_size, i32 i_count, FILE * i_file)
{
FILE * file = * (void **) i_file;
FILE * file = (FILE *)(* (void **) i_file);
return (i32) fread (io_ptr, i_size, i_count, file);
}
@ -151,7 +151,7 @@ i32 m3_fread (void * io_ptr, i32 i_size, i32 i_count, FILE * i_file)
i32 m3_fwrite (void * i_ptr, i32 i_size, i32 i_count, FILE * i_file)
{
FILE * file = * (void **) i_file;
FILE * file = (FILE *)(* (void **) i_file);
return (i32) fwrite (i_ptr, i_size, i_count, file);
}
@ -159,11 +159,10 @@ i32 m3_fwrite (void * i_ptr, i32 i_size, i32 i_count, FILE * i_file)
i32 m3_write (i32 i_fd, const void * i_data, i32 i_count)
{
#if defined(WIN32)
return 0;
#else
#if !defined(WIN32) && !defined(ESP8266) && !defined(WM_W600)
return (i32) write (i_fd, i_data, i_count);
#endif
return 0;
}
@ -255,7 +254,7 @@ _ (SuppressLookupFailure (m3_LinkFunction (io_module, "_fwrite", "i(*ii*)", (
_ (SuppressLookupFailure (m3_LinkFunction (io_module, "_write", "i(i*i)", (void *) m3_write)));
#ifndef WIN32
#if !defined(WIN32) && !defined(ESP8266) && !defined(WM_W600)
_ (SuppressLookupFailure (m3_LinkFunction (io_module, "_ioctl", "i(ii*)", (void *) ioctl)));
#endif

@ -197,7 +197,7 @@ void DumpCodePage (IM3CodePage i_codePage, pc_t i_startPC)
while (pc < end)
{
IM3Operation op = * pc++;
IM3Operation op = (IM3Operation)(* pc++);
if (op)
{

@ -35,7 +35,7 @@ M3Result Module_AddGlobal (IM3Module io_module, IM3Global * o_global, u8 i_typ
M3Result result = c_m3Err_none;
u32 index = io_module->numGlobals++;
io_module->globals = m3RellocArray (io_module->globals, M3Global, io_module->numGlobals, index);
io_module->globals = (M3Global*)m3RellocArray (io_module->globals, M3Global, io_module->numGlobals, index);
if (io_module->globals)
{
@ -58,7 +58,7 @@ M3Result Module_AddFunction (IM3Module io_module, u32 i_typeIndex, IM3ImportIn
M3Result result = c_m3Err_none;
u32 index = io_module->numFunctions++;
io_module->functions = m3RellocArray (io_module->functions, M3Function, io_module->numFunctions, index);
io_module->functions = (M3Function*)m3RellocArray (io_module->functions, M3Function, io_module->numFunctions, index);
if (io_module->functions)
{
@ -128,7 +128,7 @@ M3Result Module_EnsureMemorySize (IM3Module i_module, M3Memory * io_memory, si
alignedSize &= ~aligner;
}
io_memory->mallocated = m3Realloc (io_memory->mallocated, alignedSize, actualSize);
io_memory->mallocated = (M3MemoryHeader *)m3Realloc (io_memory->mallocated, alignedSize, actualSize);
m3log (runtime, "resized WASM linear memory to %llu bytes (%p)", alignedSize, io_memory->mallocated);

@ -486,6 +486,7 @@ M3Result m3_ParseModule (IM3Module * o_module, cbytes_t i_bytes, u32 i_numByte
M3Result result;
IM3Module module;
_try {
_ (m3Alloc (& module, M3Module, 1));
// Module_Init (module);
@ -529,7 +530,7 @@ _ (ParseModuleSection (module, sectionCode, pos, sectionLength));
}
else _throw (c_m3Err_wasmMalformed);
_catch:
} _catch:
if (result)
{

Loading…
Cancel
Save