extensions
Steven Massey 3 years ago
parent e409d7b601
commit eeb8f87178

@ -138,7 +138,7 @@ M3Result repl_load (const char* fn)
fclose (f);
f = NULL;
result = m3_ParseModule (env, &module, wasm, fsize);
result = m3_ParseModule (env, &module, wasm, fsize, false);
if (result) goto on_error;
result = m3_LoadModule (runtime, module);
@ -197,7 +197,7 @@ M3Result repl_load_hex (u32 fsize)
}
IM3Module module;
result = m3_ParseModule (env, &module, wasm, fsize);
result = m3_ParseModule (env, &module, wasm, fsize, false);
if (result) return result;
result = m3_LoadModule (runtime, module);

@ -92,8 +92,8 @@ _ (Module_AddFunction (i_module, funcTypeIndex, NULL));
function->wasmEnd = function->wasm + numBytes;
function->ownsWasmCode = true;
function->module = i_module;
function->module = i_module;
if (i_doCompilation and not i_module->runtime)
_throw ("module must be loaded into runtime to compile function");

@ -1463,9 +1463,9 @@ _ (ReadLEB_u32 (& target, & o->wasm, o->wasmEnd));
IM3CompilationScope scope;
_ (GetBlockScope (o, & scope, target));
// TODO: don't need codepage rigmarole for
// no-param forward-branch targets
// TODO: don't need codepage rigmarole for
// no-param forward-branch targets
_ (AcquireCompilationCodePage (o, & continueOpPage));
pc_t startPC = GetPagePC (continueOpPage);
@ -2431,7 +2431,9 @@ _ (Read_opcode (& opcode, & o->wasm, o->wasmEnd)); log_opco
}
IM3OpInfo opinfo = GetOpInfo(opcode);
_throwif (m3Err_unknownOpcode, opinfo == NULL);
if (opinfo == NULL)
_throw (ErrorCompile (m3Err_unknownOpcode, o, "opcode '%x' not available", opcode));
if (opinfo->compiler) {
_ ((* opinfo->compiler) (o, opcode))

@ -112,7 +112,7 @@ typedef struct M3Module
M3MemoryInfo memoryInfo;
bool memoryImported;
//bool hasWasmCodeCopy;
bool hasWasmCodeCopy;
struct M3Module * next;
}

@ -1406,29 +1406,6 @@ d_m3Store_i (i64, i64)
#undef m3MemCheck
//---------------------------------------------------------------------------------------------------------------------
# if 0 //d_m3EnableOptimizations
//---------------------------------------------------------------------------------------------------------------------
#define d_m3BinaryOpWith1_i(TYPE, NAME, OPERATION) \
d_m3Op(TYPE##_##NAME) \
{ \
_r0 = _r0 OPERATION 1; \
nextOp (); \
}
d_m3BinaryOpWith1_i (u64, Increment, +)
d_m3BinaryOpWith1_i (u32, Decrement, -)
d_m3BinaryOpWith1_i (u32, ShiftLeft1, <<)
d_m3BinaryOpWith1_i (u64, ShiftLeft1, <<)
d_m3BinaryOpWith1_i (u32, ShiftRight1, >>)
d_m3BinaryOpWith1_i (u64, ShiftRight1, >>)
//---------------------------------------------------------------------------------------------------------------------
# endif
//---------------------------------------------------------------------------------------------------------------------
// debug/profiling

@ -41,6 +41,11 @@ void m3_FreeModule (IM3Module i_module)
}
m3_Free (i_module->globals);
if (i_module->hasWasmCodeCopy)
{
m3_Free (i_module->wasmStart);
}
m3_Free (i_module);
}
}

@ -572,7 +572,7 @@ M3Result ParseModuleSection (M3Module * o_module, u8 i_sectionType, bytes_t i_
}
M3Result m3_ParseModule (IM3Environment i_environment, IM3Module * o_module, cbytes_t i_bytes, u32 i_numBytes)
M3Result m3_ParseModule (IM3Environment i_environment, IM3Module * o_module, cbytes_t i_bytes, u32 i_numBytes, bool i_copyBytes)
{
M3Result result;
@ -582,10 +582,17 @@ _try {
_throwifnull(module);
module->name = ".unnamed"; m3log (parse, "load module: %d bytes", i_numBytes);
module->startFunction = -1;
//module->hasWasmCodeCopy = false;
module->environment = i_environment;
const u8 * pos = i_bytes;
module->environment = i_environment;
module->hasWasmCodeCopy = i_copyBytes;
const u8 * pos = i_bytes;
if (i_copyBytes)
{
pos = m3_CopyMem (i_bytes, i_numBytes);
_throwifnull (pos);
}
const u8 * end = pos + i_numBytes;
module->wasmStart = pos;

@ -15,6 +15,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>
#include <stdarg.h>
@ -210,11 +211,12 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow")
// modules
//-------------------------------------------------------------------------------------------------------------------------------
// i_wasmBytes data must be persistent during the lifetime of the module
// i_wasmBytes data must be persistent during the lifetime of the module unless i_copyWasmBytes is true
M3Result m3_ParseModule (IM3Environment i_environment,
IM3Module * o_module,
const uint8_t * const i_wasmBytes,
uint32_t i_numWasmBytes);
uint32_t i_numWasmBytes,
bool i_copyWasmBytes);
// Only modules not loaded into a M3Runtime need to be freed. A module is considered unloaded if
// a. m3_LoadModule has not yet been called on that module. Or,

@ -205,7 +205,7 @@ int main (int argc, const char * argv [])
};
IM3Module module;
result = m3_ParseModule (env, & module, wasm, 44); expect (result == m3Err_none)
result = m3_ParseModule (env, & module, wasm, 44, false); expect (result == m3Err_none)
result = m3_LoadModule (runtime, module); expect (result == m3Err_none)

Loading…
Cancel
Save