Base Framework
|
#include <base/webassembly/WebAssembly.h>
Inherits Object.
Classes | |
class | Arguments |
class | FunctionContext |
class | FunctionType |
class | MapType |
class | MapType< bool > |
class | MapType< const char * > |
class | MapType< const TYPE * > |
class | MapType< const wchar * > |
class | MapType< double > |
class | MapType< float > |
class | MapType< int > |
class | MapType< int64 > |
class | MapType< long double > |
class | MapType< short > |
class | MapType< String > |
class | MapType< TYPE * > |
class | MapType< uint64 > |
class | MapType< unsigned char > |
class | MapType< unsigned int > |
class | MapType< unsigned short > |
class | MapType< void > |
class | MapType< WideString > |
class | Module |
class | OpaqueContext |
class | Symbol |
class | WASMCallback |
class | WASMValue |
class | WebAssemblyException |
Public Types | |
enum | Type { TYPE_UNSPECIFIED, TYPE_FUNCTION, TYPE_i32, TYPE_i64, TYPE_f32, TYPE_f64 } |
enum | ExternType { EXTERN_FUNCTION, EXTERN_GLOBAL, EXTERN_TABLE, EXTERN_MEMORY } |
enum | Format { FORMAT_UNSPECIFIED, FORMAT_WAT, FORMAT_WASM } |
enum | WASMABI { WASM32, WASM64 } |
typedef void(* | WASMFunction) (AnyReference context, WebAssembly &wasm, const WASMValue *arguments, WASMValue *results) |
Public Member Functions | |
WebAssembly () | |
String | getEngine () |
uint64 | getProcessingTime () const |
MemorySize | getMaximumMemoryUsage () const |
void | setMaximumMemoryUsage (MemorySize size) |
MemorySize | getMemoryUsage () const |
void | setUseLog (bool useLog) |
void | garbageCollect () |
void | registerFunction (WASMFunction func, AnyReference context, const FunctionType &type, const String &name, const String &module=String()) |
template<typename RESULT , typename... ARGS> | |
void | registerFunction (WASMFunction func, AnyReference context, RESULT(*functype)(ARGS...), const String &name, const String &module=String()) |
void | registerCallback (R< WASMCallback > callack, const FunctionType &type, const String &name, const String &module=String()) |
bool | loadFile (const String &path) |
bool | load (const uint8 *wasm, MemorySize size) |
bool | load (const String &path) |
bool | loadAny (const String &bytes) |
WASMABI | getWASMABI () const |
bool | isValid (const uint8 *wasm, MemorySize size) |
bool | isValid (const String &bytes) |
void | setArguments (const Array< String > &arguments) |
void | setEnvironment (const Map< String, String > &environment) |
void | setMountedFolders (const Map< String, String > &folders) |
void | setUseProfiler (bool useProfiler) |
bool | makeInstance (bool fake=false) |
bool | makeWASIInstance (InputStream *_stdin, OutputStream *_stdout, OutputStream *_stderr) |
ConstSpan< uint8 > | getMemory () const |
Span< uint8 > | getMemory () |
String | getString (MemorySize address, MemorySize size) const |
MemorySize | getNumberOfImports () const |
MemorySize | getNumberOfExports () const |
Array< Symbol > | getImports () |
Array< Symbol > | getExports () |
Symbol | getSymbol (MemorySize index) |
Symbol | getSymbol (const String &name) |
MemorySize | getFunctionIndex (const String &id) const |
void | callEntry () |
void | call (unsigned int id, const WASMValue *arguments, WASMValue *results) |
AnyValue | call (const String &id, const AnyValue *arguments, MemorySize size) |
AnyValue | call (const String &id) |
AnyValue | call (const String &id, const Array< AnyValue > &arguments) |
AnyValue | call (unsigned int id, const Array< AnyValue > &arguments) |
WebAssemblyFunction | getFunction (const String &id) |
template<typename RESULT , typename... ARGS> | |
RESULT | invoke (const String &id, ARGS... args) |
FunctionType | getFunctionType (unsigned int id) |
WebAssemblyFunction | getFunction (unsigned int id) |
template<typename... ARGS> | |
void | forward (void(*function)(ARGS...), const WASMValue *_arguments, WASMValue *results) |
template<typename RESULT , typename... ARGS> | |
void | forward (RESULT(*function)(ARGS...), const WASMValue *_arguments, WASMValue *results) |
template<class TYPE , typename... ARGS> | |
void | forward (void(*function)(ARGS...), TYPE *object, const WASMValue *_arguments, WASMValue *results) |
template<class TYPE , typename RESULT , typename... ARGS> | |
void | forward (RESULT(TYPE::*function)(ARGS...), TYPE *object, const WASMValue *_arguments, WASMValue *results) |
~WebAssembly () | |
Static Public Member Functions | |
static bool | isSupported () noexcept |
static const char * | toString (Type type) noexcept |
static String | convertWATToWASM (const String &text) |
template<typename RESULT , typename... TYPES> | |
static constexpr size_t | getNumberOfArguments (RESULT(*f)(TYPES ...)) |
static Format | getFormat (const String &bytes) |
template<typename RESULT , typename... ARGS> | |
static FunctionType | getFunctionType (RESULT(*)(ARGS... args)) |
static String | toString (const FunctionType &functionType, const String &name=String(), const String &module=String(), bool colorize=false) |
static String | toString (const Symbol &s, bool colorize=false) |
WebAssembly integration.
typedef void(* WebAssembly::WASMFunction) (AnyReference context, WebAssembly &wasm, const WASMValue *arguments, WASMValue *results) |
Extern WASM function.
enum WebAssembly::Format |
enum WebAssembly::Type |
Types.
enum WebAssembly::WASMABI |
WebAssembly::WebAssembly | ( | ) |
Initializes WebAssembly engine.
WebAssembly::~WebAssembly | ( | ) |
Releases WASM handle.
Calls the function with the given id and arguments.
Calls the function with the given id and arguments.
Calls the function with the given id and arguments.
Calls the exported function with the given id and arguments.
Calls the function with the given id and arguments and results.
void WebAssembly::callEntry | ( | ) |
Calls the entry function without arguments.
Returns the WASM for the given text (WAT).
void WebAssembly::garbageCollect | ( | ) |
Garbage collects any unused memory.
String WebAssembly::getEngine | ( | ) |
Returns info about the WebAssembly engine.
Returns the format for the given buffer. Only looks at header.
WebAssemblyFunction WebAssembly::getFunction | ( | const String & | id | ) |
Returns function reference.
WebAssemblyFunction WebAssembly::getFunction | ( | unsigned int | id | ) |
Returns function reference.
MemorySize WebAssembly::getFunctionIndex | ( | const String & | id | ) | const |
Returns the function index for the given name.
|
inlinestatic |
Get function type from given function pointer.
FunctionType WebAssembly::getFunctionType | ( | unsigned int | id | ) |
Returns function type.
MemorySize WebAssembly::getMaximumMemoryUsage | ( | ) | const |
Returns the memory limit.
Span<uint8> WebAssembly::getMemory | ( | ) |
Write access memory.
ConstSpan<uint8> WebAssembly::getMemory | ( | ) | const |
Read access memory.
MemorySize WebAssembly::getMemoryUsage | ( | ) | const |
Returns the current memory usage.
|
inlinestaticconstexpr |
Returns the number of arguments.
MemorySize WebAssembly::getNumberOfExports | ( | ) | const |
Returns the number of exported symbols.
MemorySize WebAssembly::getNumberOfImports | ( | ) | const |
Returns the number of imported symbols.
uint64 WebAssembly::getProcessingTime | ( | ) | const |
Returns the processing time.
String WebAssembly::getString | ( | MemorySize | address, |
MemorySize | size | ||
) | const |
Get memory as string.
Symbol WebAssembly::getSymbol | ( | MemorySize | index | ) |
Returns information about the given index.
WASMABI WebAssembly::getWASMABI | ( | ) | const |
Returns the WASM ABI.
|
inline |
Calls function with given arguments.
|
staticnoexcept |
Returns true if WASM is supported by the runtime.
|
inline |
Returns true if the given WASM module is valid.
bool WebAssembly::isValid | ( | const uint8 * | wasm, |
MemorySize | size | ||
) |
Returns true if the given WASM module is valid.
|
inline |
Loads the given WASM module in buffer.
bool WebAssembly::load | ( | const uint8 * | wasm, |
MemorySize | size | ||
) |
Loads the given WASM module in buffer.
bool WebAssembly::loadAny | ( | const String & | bytes | ) |
Loads the given WAT or WASM module in buffer.
bool WebAssembly::loadFile | ( | const String & | path | ) |
Loads the given WASM module.
bool WebAssembly::makeInstance | ( | bool | fake = false | ) |
Makes instance for loaded module.
fake | If, true dummy imports will be registered automatically. |
bool WebAssembly::makeWASIInstance | ( | InputStream * | _stdin, |
OutputStream * | _stdout, | ||
OutputStream * | _stderr | ||
) |
Makes a WASI instance.
void WebAssembly::registerCallback | ( | R< WASMCallback > | callack, |
const FunctionType & | type, | ||
const String & | name, | ||
const String & | module = String() |
||
) |
Registers global callback.
void WebAssembly::registerFunction | ( | WASMFunction | func, |
AnyReference | context, | ||
const FunctionType & | type, | ||
const String & | name, | ||
const String & | module = String() |
||
) |
Registers global function.
|
inline |
Registers global function.
Sets the command line arguments.
Sets the initial environment.
void WebAssembly::setMaximumMemoryUsage | ( | MemorySize | size | ) |
Sets the memory limit.
Sets the initial environment.
void WebAssembly::setUseLog | ( | bool | useLog | ) |
Enables logging.
void WebAssembly::setUseProfiler | ( | bool | useProfiler | ) |
Enables profiling.
|
static |
Returns function type as string.
Returns symbol as string.
|
staticnoexcept |
Returns type as string.