random stuff

extensions
Steven Massey 3 years ago
parent 6a16f1ab72
commit a033184b5a

@ -26,12 +26,28 @@ bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB)
return false;
}
u32 GetFuncTypeNumReturns (const IM3FuncType i_funcType)
u16 GetFuncTypeNumReturns (const IM3FuncType i_funcType)
{
return i_funcType ? i_funcType->numRets : 0;
}
u8 GetFuncTypeReturnType (const IM3FuncType i_funcType, u16 i_index)
{
u8 type = c_m3Type_unknown;
if (i_funcType)
{
if (i_index < i_funcType->numRets)
{
type = i_funcType->types [i_index];
}
}
return type;
}
//---------------------------------------------------------------------------------------------------------------
@ -178,16 +194,9 @@ u16 GetFunctionNumReturns (IM3Function i_function)
}
u8 GetFunctionReturnType (IM3Function i_function, u32 i_index)
u8 GetFunctionReturnType (const IM3Function i_function, u16 i_index)
{
u8 type = c_m3Type_none;
if (i_index < GetFunctionNumReturns (i_function))
{
type = i_function->funcType->types [i_index];
}
return type;
return i_function ? GetFuncTypeReturnType (i_function->funcType, i_index) : c_m3Type_unknown;
}

@ -29,8 +29,8 @@ typedef M3FuncType * IM3FuncType;
M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i_numTypes);
bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB);
u32 GetFuncTypeNumReturns (const IM3FuncType i_funcType);
u16 GetFuncTypeNumReturns (const IM3FuncType i_funcType);
u8 GetFuncTypeReturnType (const IM3FuncType i_funcType, u16 i_index);
//---------------------------------------------------------------------------------------------------------------------------------
@ -59,9 +59,10 @@ typedef struct M3Function
u32 hits;
#endif
#if d_m3EnableStrace >= 2
u16 index;
#endif
# if d_m3EnableStrace >= 2 || d_m3LogCompile
u32 index;
# endif
u16 maxStackSlots;
u16 numRetSlots;
@ -70,10 +71,10 @@ typedef struct M3Function
u16 numLocals; // not including args
u16 numLocalBytes;
void * constants;
u16 numConstantBytes;
bool ownsWasmCode;
bool ownsWasmCode;
u16 numConstantBytes;
void * constants;
}
M3Function;
@ -86,7 +87,7 @@ u16 GetFunctionNumArgs (IM3Function i_function);
u8 GetFunctionArgType (IM3Function i_function, u32 i_index);
u16 GetFunctionNumReturns (IM3Function i_function);
u8 GetFunctionReturnType (IM3Function i_function, u32 i_index);
u8 GetFunctionReturnType (const IM3Function i_function, u16 i_index);
u32 GetFunctionNumArgsAndLocals (IM3Function i_function);

@ -26,6 +26,7 @@ void m3_PrintM3Info ()
// printf (" sizeof M3CodePage : %zu bytes (%d slots) \n", sizeof (M3CodePage), c_m3CodePageNumSlots);
printf (" sizeof M3MemPage : %u bytes \n", d_m3MemPageSize);
printf (" sizeof M3Compilation : %zu bytes \n", sizeof (M3Compilation));
printf (" sizeof M3Function : %zu bytes \n", sizeof (M3Function));
printf ("----------------------------------------------------------------\n\n");
}

@ -77,7 +77,7 @@ _try {
IM3Function func = Module_GetFunction (io_module, index);
func->funcType = ft;
#if d_m3EnableStrace >= 2
#if d_m3EnableStrace >= 2 || d_m3LogCompile
func->index = index;
#endif

@ -148,7 +148,8 @@ d_m3ErrorConst (functionStackOverflow, "compiling function overran its
d_m3ErrorConst (functionStackUnderrun, "compiling function underran the stack")
d_m3ErrorConst (mallocFailedCodePage, "memory allocation failed when acquiring a new M3 code page")
d_m3ErrorConst (settingImmutableGlobal, "attempting to set an immutable global")
d_m3ErrorConst (typeMismatch, "malformed Wasm: incorrect type on stack")
d_m3ErrorConst (typeMismatch, "incorrect type on stack")
d_m3ErrorConst (typeCountMismatch, "incorrect value count on stack")
// runtime errors
d_m3ErrorConst (missingCompiledCode, "function is missing compiled m3 code")
@ -225,6 +226,9 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow")
// Calling m3_RunStart is optional
M3Result m3_RunStart (IM3Module i_module);
// Arguments and return values are passed in and out through the stack pointer _sp.
// Placeholder return value slots are first and arguments after. So, the first argument is at _sp [numReturns]
// Return values should be written into _sp [0] to _sp [num_returns - 1]
typedef const void * (* M3RawCall) (IM3Runtime runtime, IM3ImportContext _ctx, uint64_t * _sp, void * _mem);
M3Result m3_LinkRawFunction (IM3Module io_module,

Loading…
Cancel
Save