Search in sources :

Example 1 with ExportedWasmGlobal

use of org.graalvm.wasm.globals.ExportedWasmGlobal in project graal by oracle.

the class WebAssembly method instanceExport.

public static Object instanceExport(WasmInstance instance, String name) {
    CompilerAsserts.neverPartOfCompilation();
    WasmFunction function = instance.module().exportedFunctions().get(name);
    Integer globalIndex = instance.module().exportedGlobals().get(name);
    if (function != null) {
        return instance.functionInstance(function);
    } else if (globalIndex != null) {
        final int index = globalIndex;
        final int address = instance.globalAddress(index);
        if (address < 0) {
            return instance.context().globals().externalGlobal(address);
        } else {
            final ValueType valueType = ValueType.fromByteValue(instance.symbolTable().globalValueType(index));
            final boolean mutable = instance.symbolTable().isGlobalMutable(index);
            return new ExportedWasmGlobal(valueType, mutable, instance.context().globals(), address);
        }
    } else if (instance.module().exportedMemoryNames().contains(name)) {
        return instance.memory();
    } else if (instance.module().exportedTableNames().contains(name)) {
        return instance.table();
    } else {
        throw new WasmJsApiException(WasmJsApiException.Kind.TypeError, name + " is not a exported name of the given instance");
    }
}
Also used : WasmJsApiException(org.graalvm.wasm.exception.WasmJsApiException) WasmFunction(org.graalvm.wasm.WasmFunction) ExportedWasmGlobal(org.graalvm.wasm.globals.ExportedWasmGlobal)

Aggregations

WasmFunction (org.graalvm.wasm.WasmFunction)1 WasmJsApiException (org.graalvm.wasm.exception.WasmJsApiException)1 ExportedWasmGlobal (org.graalvm.wasm.globals.ExportedWasmGlobal)1