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");
}
}
Aggregations