Add m3_CompileModule

opam-2.0.0
Volodymyr Shymanskyy 3 years ago
parent 9b6d0c9637
commit 067261d490

@ -430,8 +430,12 @@ M3Result repl_global_set (const char* name, const char* value)
return m3_SetGlobal (g, &tagged);
}
M3Result repl_compile ()
{
return m3_CompileModule(runtime->modules);
}
M3Result repl_dump()
M3Result repl_dump ()
{
uint32_t len;
uint8_t* mem = m3_GetMemory(runtime, &len, 0);
@ -448,7 +452,7 @@ M3Result repl_dump()
return m3Err_none;
}
void repl_free()
void repl_free ()
{
if (runtime) {
m3_FreeRuntime (runtime);
@ -461,7 +465,7 @@ void repl_free()
}
}
M3Result repl_init(unsigned stack)
M3Result repl_init (unsigned stack)
{
repl_free();
runtime = m3_NewRuntime (env, stack, NULL);
@ -664,6 +668,8 @@ int main (int i_argc, const char* i_argv[])
result = repl_global_set(argv[1], argv[2]);
} else if (!strcmp(":dump", argv[0])) {
result = repl_dump();
} else if (!strcmp(":compile", argv[0])) {
result = repl_compile();
} else if (!strcmp(":invoke", argv[0])) {
unescape(argv[1]);
result = repl_invoke(argv[1], argc-2, (const char**)(argv+2));

@ -521,6 +521,26 @@ m3ApiRawFunction(m3_wasi_generic_path_rename)
m3ApiReturn(ret);
}
m3ApiRawFunction(m3_wasi_generic_path_symlink)
{
m3ApiReturnType (uint32_t)
m3ApiGetArgMem (const char * , old_path)
m3ApiGetArg (uvwasi_size_t , old_path_len)
m3ApiGetArg (uvwasi_fd_t , fd)
m3ApiGetArgMem (const char * , new_path)
m3ApiGetArg (uvwasi_size_t , new_path_len)
m3ApiCheckMem(old_path, old_path_len);
m3ApiCheckMem(new_path, new_path_len);
uvwasi_errno_t ret = uvwasi_path_symlink(&uvwasi, old_path, old_path_len,
fd, new_path, new_path_len);
WASI_TRACE("old_fd:%d, old_path:%s, fd:%d, new_path:%s", old_fd, old_path, fd, new_path);
m3ApiReturn(ret);
}
m3ApiRawFunction(m3_wasi_generic_path_unlink_file)
{
m3ApiReturnType (uint32_t)
@ -993,7 +1013,7 @@ _ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_open",
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_readlink", "i(i*i*i*)", &m3_wasi_generic_path_readlink)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_remove_directory", "i(i*i)", &m3_wasi_generic_path_remove_directory)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_rename", "i(i*ii*i)", &m3_wasi_generic_path_rename)));
//_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_symlink", "i(*ii*i)", )));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_symlink", "i(*ii*i)", &m3_wasi_generic_path_symlink)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "path_unlink_file", "i(i*i)", &m3_wasi_generic_path_unlink_file)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, wasi, "poll_oneoff", "i(**i*)", &m3_wasi_generic_poll_oneoff)));

@ -513,6 +513,22 @@ _ (ReadLEB_u32 (& functionIndex, & bytes, end));
_catch: return result;
}
M3Result m3_CompileModule (IM3Module io_module)
{
M3Result result = m3Err_none;
for (u32 i = 0; i < io_module->numFunctions; ++i)
{
IM3Function f = & io_module->functions [i];
if (f->wasm and not f->compiled)
{
_ (CompileFunction (f));
}
}
_catch: return result;
}
M3Result m3_RunStart (IM3Module io_module)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION

@ -229,6 +229,9 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow")
// LoadModule transfers ownership of a module to the runtime. Do not free modules once successfully loaded into the runtime
M3Result m3_LoadModule (IM3Runtime io_runtime, IM3Module io_module);
// Optional, compiles all functions in the module
M3Result m3_CompileModule (IM3Module io_module);
// Calling m3_RunStart is optional
M3Result m3_RunStart (IM3Module i_module);

Loading…
Cancel
Save