extensions
Steven Massey 3 years ago
parent fa9248f70f
commit 1ef8358506

@ -11,6 +11,7 @@ set(sources
"m3_emit.c"
"m3_env.c"
"m3_exec.c"
"m3_function.c"
"m3_info.c"
"m3_module.c"
"m3_parse.c"

@ -14,162 +14,6 @@
#include "m3_exception.h"
#include "m3_info.h"
void Runtime_ReleaseCodePages (IM3Runtime i_runtime)
{
}
void Function_Release (IM3Function i_function)
{
m3_Free (i_function->constants);
for (int i = 0; i < i_function->numNames; i++)
{
// name can be an alias of fieldUtf8
if (i_function->names[i] != i_function->import.fieldUtf8)
{
m3_Free (i_function->names[i]);
}
}
FreeImportInfo (& i_function->import);
if (i_function->ownsWasmCode)
m3_Free (i_function->wasm);
// Function_FreeCompiledCode (func);
# if (d_m3EnableCodePageRefCounting)
{
m3_Free (i_function->codePageRefs);
i_function->numCodePageRefs = 0;
}
# endif
}
void Function_FreeCompiledCode (IM3Function i_function)
{
# if (d_m3EnableCodePageRefCounting)
{
i_function->compiled = NULL;
while (i_function->numCodePageRefs--)
{
IM3CodePage page = i_function->codePageRefs [i_function->numCodePageRefs];
if (--(page->info.usageCount) == 0)
{
// printf ("free %p\n", page);
}
}
m3_Free (i_function->codePageRefs);
Runtime_ReleaseCodePages (i_function->module->runtime);
}
# endif
}
cstr_t m3_GetFunctionName (IM3Function i_function)
{
u16 numNames = 0;
cstr_t *names = GetFunctionNames(i_function, &numNames);
if (numNames > 0)
return names[0];
else
return "<unnamed>";
}
IM3Module m3_GetFunctionModule (IM3Function i_function)
{
return i_function ? i_function->module : NULL;
}
cstr_t * GetFunctionNames (IM3Function i_function, u16 * o_numNames)
{
if (!i_function || !o_numNames)
return NULL;
if (i_function->import.fieldUtf8)
{
*o_numNames = 1;
return &i_function->import.fieldUtf8;
}
else
{
*o_numNames = i_function->numNames;
return i_function->names;
}
}
cstr_t GetFunctionImportModuleName (IM3Function i_function)
{
return (i_function->import.moduleUtf8) ? i_function->import.moduleUtf8 : "";
}
u32 GetFunctionNumArgs (IM3Function i_function)
{
u32 numArgs = 0;
if (i_function)
{
if (i_function->funcType)
numArgs = i_function->funcType->numArgs;
}
return numArgs;
}
u32 GetFunctionNumReturns (IM3Function i_function)
{
u32 numReturns = 0;
if (i_function)
{
if (i_function->funcType)
numReturns = i_function->funcType->numRets;
}
return numReturns;
}
u8 GetFunctionReturnType (IM3Function i_function, u32 i_index)
{
u8 type = c_m3Type_none;
if (i_index < GetFunctionNumReturns (i_function))
{
type = i_function->funcType->types [i_index];
}
return type;
}
u32 GetFunctionNumArgsAndLocals (IM3Function i_function)
{
if (i_function)
return i_function->numLocals + GetFunctionNumArgs (i_function);
else
return 0;
}
void FreeImportInfo (M3ImportInfo * i_info)
{
m3_Free (i_info->moduleUtf8);
m3_Free (i_info->fieldUtf8);
}
IM3Environment m3_NewEnvironment ()
{

@ -15,63 +15,6 @@
d_m3BeginExternC
//---------------------------------------------------------------------------------------------------------------------------------
typedef struct M3Function
{
struct M3Module * module;
M3ImportInfo import;
bytes_t wasm;
bytes_t wasmEnd;
u16 numNames; // maximum of d_m3MaxDuplicateFunctionImpl
cstr_t names[d_m3MaxDuplicateFunctionImpl];
IM3FuncType funcType;
pc_t compiled;
#if (d_m3EnableCodePageRefCounting)
IM3CodePage * codePageRefs; // array of all pages used
u32 numCodePageRefs;
#endif
#if defined(DEBUG)
u32 hits;
#endif
#if d_m3EnableStrace >= 2
u16 index;
#endif
u16 maxStackSlots;
u16 numArgSlots;
u16 numLocals; // not including args
u16 numLocalBytes;
void * constants;
u16 numConstantBytes;
bool ownsWasmCode;
}
M3Function;
void Function_Release (IM3Function i_function);
void Function_FreeCompiledCode (IM3Function i_function);
cstr_t GetFunctionImportModuleName (IM3Function i_function);
cstr_t * GetFunctionNames (IM3Function i_function, u16 * o_numNames);
u32 GetFunctionNumArgs (IM3Function i_function);
u32 GetFunctionNumReturns (IM3Function i_function);
u8 GetFunctionReturnType (IM3Function i_function, u32 i_index);
u32 GetFunctionNumArgsAndLocals (IM3Function i_function);
cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp);
//---------------------------------------------------------------------------------------------------------------------------------
typedef struct M3MemoryInfo

@ -31,3 +31,157 @@ u32 GetFuncTypeNumReturns (const IM3FuncType i_funcType)
return i_funcType ? i_funcType->numRets : 0;
}
//---------------------------------------------------------------------------------------------------------------
void FreeImportInfo (M3ImportInfo * i_info)
{
m3_Free (i_info->moduleUtf8);
m3_Free (i_info->fieldUtf8);
}
void Function_Release (IM3Function i_function)
{
m3_Free (i_function->constants);
for (int i = 0; i < i_function->numNames; i++)
{
// name can be an alias of fieldUtf8
if (i_function->names[i] != i_function->import.fieldUtf8)
{
m3_Free (i_function->names[i]);
}
}
FreeImportInfo (& i_function->import);
if (i_function->ownsWasmCode)
m3_Free (i_function->wasm);
// Function_FreeCompiledCode (func);
# if (d_m3EnableCodePageRefCounting)
{
m3_Free (i_function->codePageRefs);
i_function->numCodePageRefs = 0;
}
# endif
}
void Function_FreeCompiledCode (IM3Function i_function)
{
# if (d_m3EnableCodePageRefCounting)
{
i_function->compiled = NULL;
while (i_function->numCodePageRefs--)
{
IM3CodePage page = i_function->codePageRefs [i_function->numCodePageRefs];
if (--(page->info.usageCount) == 0)
{
// printf ("free %p\n", page);
}
}
m3_Free (i_function->codePageRefs);
Runtime_ReleaseCodePages (i_function->module->runtime);
}
# endif
}
cstr_t m3_GetFunctionName (IM3Function i_function)
{
u16 numNames = 0;
cstr_t *names = GetFunctionNames(i_function, &numNames);
if (numNames > 0)
return names[0];
else
return "<unnamed>";
}
IM3Module m3_GetFunctionModule (IM3Function i_function)
{
return i_function ? i_function->module : NULL;
}
cstr_t * GetFunctionNames (IM3Function i_function, u16 * o_numNames)
{
if (!i_function || !o_numNames)
return NULL;
if (i_function->import.fieldUtf8)
{
*o_numNames = 1;
return &i_function->import.fieldUtf8;
}
else
{
*o_numNames = i_function->numNames;
return i_function->names;
}
}
cstr_t GetFunctionImportModuleName (IM3Function i_function)
{
return (i_function->import.moduleUtf8) ? i_function->import.moduleUtf8 : "";
}
u32 GetFunctionNumArgs (IM3Function i_function)
{
u32 numArgs = 0;
if (i_function)
{
if (i_function->funcType)
numArgs = i_function->funcType->numArgs;
}
return numArgs;
}
u32 GetFunctionNumReturns (IM3Function i_function)
{
u32 numReturns = 0;
if (i_function)
{
if (i_function->funcType)
numReturns = i_function->funcType->numRets;
}
return numReturns;
}
u8 GetFunctionReturnType (IM3Function i_function, u32 i_index)
{
u8 type = c_m3Type_none;
if (i_index < GetFunctionNumReturns (i_function))
{
type = i_function->funcType->types [i_index];
}
return type;
}
u32 GetFunctionNumArgsAndLocals (IM3Function i_function)
{
if (i_function)
return i_function->numLocals + GetFunctionNumArgs (i_function);
else
return 0;
}

@ -12,6 +12,7 @@
d_m3BeginExternC
//---------------------------------------------------------------------------------------------------------------------------------
typedef struct M3FuncType
{
@ -30,6 +31,67 @@ M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i
bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB);
u32 GetFuncTypeNumReturns (const IM3FuncType i_funcType);
//---------------------------------------------------------------------------------------------------------------------------------
typedef struct M3Function
{
struct M3Module * module;
M3ImportInfo import;
bytes_t wasm;
bytes_t wasmEnd;
u16 numNames; // maximum of d_m3MaxDuplicateFunctionImpl
cstr_t names[d_m3MaxDuplicateFunctionImpl];
IM3FuncType funcType;
pc_t compiled;
#if (d_m3EnableCodePageRefCounting)
IM3CodePage * codePageRefs; // array of all pages used
u32 numCodePageRefs;
#endif
#if defined(DEBUG)
u32 hits;
#endif
#if d_m3EnableStrace >= 2
u16 index;
#endif
u16 maxStackSlots;
u16 numArgSlots;
u16 numLocals; // not including args
u16 numLocalBytes;
void * constants;
u16 numConstantBytes;
bool ownsWasmCode;
}
M3Function;
void Function_Release (IM3Function i_function);
void Function_FreeCompiledCode (IM3Function i_function);
cstr_t GetFunctionImportModuleName (IM3Function i_function);
cstr_t * GetFunctionNames (IM3Function i_function, u16 * o_numNames);
u32 GetFunctionNumArgs (IM3Function i_function);
u32 GetFunctionNumReturns (IM3Function i_function);
u8 GetFunctionReturnType (IM3Function i_function, u32 i_index);
u32 GetFunctionNumArgsAndLocals (IM3Function i_function);
cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp);
//---------------------------------------------------------------------------------------------------------------------------------
d_m3EndExternC
#endif /* m3_function_h */

Loading…
Cancel
Save