mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2024-11-26 15:32:05 +00:00
Add architecture document for wasm export (#2049)
This commit is contained in:
parent
bfbe51e1b3
commit
db2a4104b3
|
@ -4,3 +4,5 @@
|
|||
## Wasm function
|
||||
- [Wasm function architecture](./doc/wasm_function.MD)
|
||||
|
||||
## Exports
|
||||
- [Wasm export architecture](./doc/wasm_exports.MD)
|
||||
|
|
5695
core/iwasm/doc/images/export_function.excalidraw
Normal file
5695
core/iwasm/doc/images/export_function.excalidraw
Normal file
File diff suppressed because it is too large
Load Diff
16
core/iwasm/doc/images/wasm_exports.svg
Normal file
16
core/iwasm/doc/images/wasm_exports.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 158 KiB |
22
core/iwasm/doc/wasm_exports.MD
Normal file
22
core/iwasm/doc/wasm_exports.MD
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Wasm exports
|
||||
The internal data structure for Wasm exports:
|
||||
![](./images/wasm_exports.svg)
|
||||
|
||||
## Setup exports for Module
|
||||
The array data structure pointed by `WASMModule::exports` is setup during loading a module. Basically the runtime will load the exports sections from the module file content, and construct an array of C struct `WASMExport`.
|
||||
|
||||
A `WASMExport` item contains three elements that map the Wasm file exports section structure:
|
||||
- name: the name shown to external
|
||||
- kind: total 4 export types: function, globals, memory, table
|
||||
- index: As all the 4 export types are organized in array, this refers to index in target export type
|
||||
|
||||
## Function exports
|
||||
### use function exports
|
||||
function exports are often used in two situations:
|
||||
1. **call by host**: runtime API `wasm_runtime_lookup_function` will walk through the array of `WASMModuleInstance::export_functions` and compare the exported name with given target symbol name in the function parameter. If any array item matches the name, it then returns the value of field `function` which points to associated function instance (WASMFunctionInstance)
|
||||
2. **import by another module**: During linking multiple modules, the runtime saves the pointer of exported WASMFunctionInstance in the local WASMFunctionInstance of importing module.
|
||||
|
||||
### setup for instance
|
||||
The data structure pointed by `WASMModuleInstance::export_functions` is set up during instantiating module instance.
|
||||
|
||||
The runtime will walk through the `WASMModule::exports` array and find all the item with kind equal to "function". Create a node of `WASMExportFuncInstance` for each matching, find the associated `WASMFunctionInstance` object and save its address in the field `function`.
|
Loading…
Reference in New Issue
Block a user