extensions
Volodymyr Shymanskyy 4 years ago
parent e6b7a48675
commit 7afc674875

@ -1509,13 +1509,10 @@ _ (ReadLebSigned (& type, 33, & o->wasm, o->wasmEnd));
_ (NormalizeType (&valueType, type)); m3log (compile, d_indent " (type: %s)", get_indention_string (o), c_waTypes [valueType]);
*o_blockType = o->module->environment->retFuncTypes[valueType];
}
else if (type < o->module->numFuncTypes)
{
*o_blockType = o->module->funcTypes[type]; m3log (compile, d_indent " (type: %s)", get_indention_string (o), SPrintFuncTypeSignature (*o_blockType));
}
else
{
return "func type out of bounds";
_throwif("func type out of bounds", type >= o->module->numFuncTypes);
*o_blockType = o->module->funcTypes[type]; m3log (compile, d_indent " (type: %s)", get_indention_string (o), SPrintFuncTypeSignature (*o_blockType));
}
_catch: return result;
}

@ -49,8 +49,8 @@ void Function_Release (IM3Function i_function)
FreeImportInfo (& i_function->import);
if (i_function->ownsWasmCode)
m3Free (i_function->wasm);
//if (i_function->ownsWasmCode)
// m3Free (i_function->wasm);
// Function_FreeCompiledCode (func);
@ -602,26 +602,19 @@ _ (ReadLEB_u32 (& numElements, & bytes, end));
u32 endElement = numElements + offset;
if (endElement > offset) // TODO: check this, endElement depends on offset
{
_ (m3ReallocArray (& io_module->table0, IM3Function, endElement, io_module->table0Size));
io_module->table0Size = endElement;
_throwif ("table overflow", offset >= endElement); // TODO: check this, endElement depends on offset
_ (m3ReallocArray (& io_module->table0, IM3Function, endElement, io_module->table0Size));
for (u32 e = 0; e < numElements; ++e)
{
u32 functionIndex;
_ (ReadLEB_u32 (& functionIndex, & bytes, end));
io_module->table0Size = endElement;
if (functionIndex < io_module->numFunctions)
{
IM3Function function = & io_module->functions [functionIndex]; d_m3Assert (function); //printf ("table: %s\n", function->name);
io_module->table0 [e + offset] = function;
}
else _throw ("function index out of range");
}
for (u32 e = 0; e < numElements; ++e)
{
u32 functionIndex;
_ (ReadLEB_u32 (& functionIndex, & bytes, end));
_throwif ("function index out of range", functionIndex >= io_module->numFunctions);
IM3Function function = & io_module->functions [functionIndex]; d_m3Assert (function); //printf ("table: %s\n", function->name);
io_module->table0 [e + offset] = function;
}
else _throw ("table overflow");
}
else _throw ("element table index must be zero for MVP");
}
@ -651,7 +644,7 @@ _ (Compile_Function (function));
_ ((M3Result) Call (function->compiled, (m3stack_t) runtime->stack, runtime->memory.mallocated, d_m3OpDefaultArgs));
io_module->startFunction = -1;
io_module->startFunction = -1;
}
_catch: return result;
@ -693,7 +686,9 @@ void * v_FindFunction (IM3Module i_module, const char * const i_name)
{
IM3Function f = & i_module->functions [i];
if (f->name)
bool isImported = f->import.moduleUtf8 or f->import.fieldUtf8;
if (not isImported and f->name)
{
if (strcmp (f->name, i_name) == 0)
return f;

@ -54,7 +54,7 @@ typedef struct M3Function
void * constants;
u16 numConstantBytes;
bool ownsWasmCode;
//bool ownsWasmCode;
}
M3Function;
@ -146,7 +146,7 @@ typedef struct M3Module
IM3FuncType * funcTypes; // array of pointers to list of FuncTypes
u32 numImports;
IM3Function * imports; // notice: "I" prefix. imports are pointers to functions in another module.
//IM3Function * imports; b // notice: "I" prefix. imports are pointers to functions in another module.
u32 numFunctions;
M3Function * functions;
@ -156,7 +156,7 @@ typedef struct M3Module
u32 numDataSegments;
M3DataSegment * dataSegments;
u32 importedGlobals;
//u32 importedGlobals;
u32 numGlobals;
M3Global * globals;
@ -170,7 +170,7 @@ typedef struct M3Module
M3MemoryInfo memoryInfo;
bool memoryImported;
bool hasWasmCodeCopy;
//bool hasWasmCodeCopy;
struct M3Module * next;
}

@ -29,7 +29,7 @@ void m3_FreeModule (IM3Module i_module)
Module_FreeFunctions (i_module);
m3Free (i_module->functions);
m3Free (i_module->imports);
//m3Free (i_module->imports);
m3Free (i_module->funcTypes);
m3Free (i_module->dataSegments);
m3Free (i_module->table0);
@ -70,22 +70,21 @@ M3Result Module_AddFunction (IM3Module io_module, u32 i_typeIndex, IM3ImportIn
u32 index = io_module->numFunctions++;
_ (m3ReallocArray (& io_module->functions, M3Function, io_module->numFunctions, index));
if (i_typeIndex < io_module->numFuncTypes)
{
IM3FuncType ft = io_module->funcTypes [i_typeIndex];
_throwif("type sig index out of bounds", i_typeIndex >= io_module->numFuncTypes);
IM3Function func = Module_GetFunction (io_module, index);
func->funcType = ft;
IM3FuncType ft = io_module->funcTypes [i_typeIndex];
if (i_importInfo)
{
func->import = * i_importInfo;
func->name = i_importInfo->fieldUtf8;
}
IM3Function func = Module_GetFunction (io_module, index);
func->funcType = ft;
// m3log (module, " added function: %3d; sig: %d", index, i_typeIndex);
if (i_importInfo)
{
func->import = * i_importInfo;
func->name = i_importInfo->fieldUtf8;
}
else result = "type sig index out of bounds";
// m3log (module, " added function: %3d; sig: %d", index, i_typeIndex);
_catch: return result;
}

@ -227,6 +227,7 @@ _ (ReadLEB_u32 (& index, & i_bytes, i_end));
if (exportKind == d_externalKind_function)
{
_throwif(m3Err_wasmMalformed, index >= io_module->numFunctions);
if (not io_module->functions [index].name)
{
io_module->functions [index].name = utf8;
@ -340,7 +341,7 @@ _ (NormalizeType (& normalType, wasmType));
func->module = io_module;
func->wasm = start;
func->wasmEnd = i_bytes;
func->ownsWasmCode = io_module->hasWasmCodeCopy;
//func->ownsWasmCode = io_module->hasWasmCodeCopy;
func->numLocals = numLocals;
}
else _throw (m3Err_wasmSectionOverrun);
@ -543,7 +544,7 @@ _ (m3Alloc (& module, M3Module, 1));
module->name = ".unnamed"; m3log (parse, "load module: %d bytes", i_numBytes);
module->startFunction = -1;
module->hasWasmCodeCopy = false;
//module->hasWasmCodeCopy = false;
module->environment = i_environment;
const u8 * pos = i_bytes;

Loading…
Cancel
Save