Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm-c-api] Implement missing functions #1461

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/interp/interp-wasm-c-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,12 @@ void wasm_trap_trace(const wasm_trap_t* trap, own wasm_frame_vec_t* out) {
// TRACE(stderr, "error: %s\n", msg.c_str());
}

// wasm_config

own wasm_config_t* wasm_config_new() {
return new wasm_config_t();
}

// wasm_engine

own wasm_engine_t* wasm_engine_new() {
Expand Down Expand Up @@ -613,6 +619,28 @@ own wasm_module_t* wasm_module_new(wasm_store_t* store,
return new wasm_module_t{Module::New(store->I, module_desc), binary};
}

bool wasm_module_validate(wasm_store_t* store, const wasm_byte_vec_t* binary) {
// TODO: Optimize this; for now it is generating a new module and discarding
// it. But since this call only needs to validate, it could do much less.
wasm_module_t* module = wasm_module_new(store, binary);
if (module == nullptr) {
return false;
}
wasm_module_delete(module);
return true;
}

void wasm_module_imports(const wasm_module_t* module,
own wasm_importtype_vec_t* out) {
auto&& import_types = module->As<Module>()->import_types();
TRACE("%" PRIzx, import_types.size());
wasm_importtype_vec_new_uninitialized(out, import_types.size());

for (size_t i = 0; i < import_types.size(); ++i) {
out->data[i] = new wasm_importtype_t{import_types[i]};
}
}

void wasm_module_exports(const wasm_module_t* module,
own wasm_exporttype_vec_t* out) {
auto&& export_types = module->As<Module>()->export_types();
Expand Down Expand Up @@ -927,6 +955,10 @@ own wasm_memory_t* wasm_memory_new(wasm_store_t* store,
return new wasm_memory_t{Memory::New(store->I, *type->As<MemoryType>())};
}

own wasm_memorytype_t* wasm_memory_type(const wasm_memory_t* memory) {
return new wasm_memorytype_t{memory->As<Memory>()->type()};
}

byte_t* wasm_memory_data(wasm_memory_t* memory) {
return reinterpret_cast<byte_t*>(memory->As<Memory>()->UnsafeData());
}
Expand Down