added m3_GetMemory API

extensions
Steven Massey 5 years ago
parent 1bd17809f2
commit 94ef35d843

@ -177,7 +177,12 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow")
uint32_t i_stackSizeInBytes,
M3StackInfo * i_nativeStackInfo); // i_nativeStackInfo can be NULL
void m3_FreeRuntime (IM3Runtime i_runtime);
void m3_FreeRuntime (IM3Runtime i_runtime);
const uint8_t * m3_GetMemory (IM3Runtime i_runtime,
uint32_t * o_memorySizeInBytes,
uint32_t i_memoryIndex);
// Wasm currently only supports one memory region. i_memoryIndex should be zero.
//-------------------------------------------------------------------------------------------------------------------------------
// modules
@ -187,6 +192,7 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow")
IM3Module * o_module,
const uint8_t * const i_wasmBytes,
uint32_t i_numWasmBytes);
// i_wasmBytes data must be persistent during the lifetime of the module
void m3_FreeModule (IM3Module i_module);
// Only unloaded modules need to be freed

@ -91,6 +91,8 @@ M3Result FindAndLinkFunction (IM3Module io_module,
{
M3Result result = m3Err_functionLookupFailed;
bool wildcardModule = (strcmp (i_moduleName, "*") == 0);
for (u32 i = 0; i < io_module->numFunctions; ++i)
{
IM3Function f = & io_module->functions [i];
@ -98,7 +100,7 @@ M3Result FindAndLinkFunction (IM3Module io_module,
if (f->import.moduleUtf8 and f->import.fieldUtf8)
{
if (strcmp (f->import.fieldUtf8, i_functionName) == 0 and
strcmp (f->import.moduleUtf8, i_moduleName) == 0)
(wildcardModule or strcmp (f->import.moduleUtf8, i_moduleName) == 0))
{
result = i_linker (io_module, f, i_signature, i_function);
if (result) return result;

@ -135,7 +135,7 @@ typedef struct M3CodePageHeader
u32 lineIndex;
u32 numLines;
u32 sequence; // this is just used for debugging; could be removed
u32 __;
u32 usageCount;
}
M3CodePageHeader;

@ -22,8 +22,8 @@ M3Result EnsureCodePageNumLines (IM3Compilation o, u32 i_numLines)
if (page)
{
d_m3Assert (NumFreeLines (o->page) >= 2);
m3log (emit, "bridging new code page from: %d %p (free slots: %d) to: %d", o->page->info.sequence, GetPC (o), NumFreeLines (o->page), page->info.sequence);
d_m3Assert (NumFreeLines (o->page) >= 2);
EmitWord (o->page, op_Bridge);
EmitWord (o->page, GetPagePC (page));

@ -851,3 +851,22 @@ M3StackInfo m3_GetNativeStackInfo (i32 i_stackSize)
return info;
}
bytes_t m3_GetMemory (IM3Runtime i_runtime, u32 * o_memorySizeInBytes, u32 i_memoryIndex)
{
bytes_t memory = NULL; d_m3Assert (i_memoryIndex == 0);
if (i_runtime)
{
u32 size = (u32) i_runtime->memory.mallocated->length;
if (o_memorySizeInBytes)
* o_memorySizeInBytes = size;
if (size)
memory = m3MemData (i_runtime->memory.mallocated);
}
return memory;
}

@ -39,21 +39,21 @@ typedef struct M3Function
cstr_t name;
u32 hits;
IM3FuncType funcType;
IM3Operation callOp;
pc_t compiled;
u32 maxStackSlots;
u32 hits;
u32 numLocals; // not including args
u16 maxStackSlots;
u32 numConstants;
u16 numLocals; // not including args
u16 numConstants;
void * constants;
bool callNeedsRuntime;
// bool callNeedsRuntime;
}
M3Function;
@ -248,10 +248,7 @@ IM3CodePage AcquireCodePage (IM3Runtime io_runtime);
IM3CodePage AcquireCodePageWithCapacity (IM3Runtime io_runtime, u32 i_slotCount);
void ReleaseCodePage (IM3Runtime io_runtime, IM3CodePage i_codePage);
// Wasm MVP: i_memoryIndex must be zero
//void * m3_GetMemory (IM3Runtime i_runtime, u32 i_memoryIndex);
//size_t m3_GetMemorySize (void * i_memory);
bytes_t m3_GetMemory (IM3Runtime i_runtime, u32 * o_memorySizeInBytes, u32 i_memoryIndex);
M3Result m3Error (M3Result i_result, IM3Runtime i_runtime, IM3Module i_module, IM3Function i_function, const char * const i_file, u32 i_lineNum, const char * const i_errorMessage, ...);

Loading…
Cancel
Save