use of org.graalvm.wasm.globals.WasmGlobal in project graal by oracle.
the class WasmJsApiSuite method checkInstantiateWithImportGlobal.
private static void checkInstantiateWithImportGlobal(byte[] binaryWithGlobalImport, String globalType, Object globalValue) throws IOException {
runTest(context -> {
final WebAssembly wasm = new WebAssembly(context);
final WasmGlobal global = WebAssembly.globalAlloc(ValueType.valueOf(globalType), false, globalValue);
Dictionary importObject = Dictionary.create(new Object[] { "host", Dictionary.create(new Object[] { "defaultGlobal", global }) });
final WasmInstance instance = moduleInstantiate(wasm, binaryWithGlobalImport, importObject);
try {
InteropLibrary interop = InteropLibrary.getUncached();
final Object readGlobal1 = WebAssembly.instanceExport(instance, "readGlobal1");
final Object readGlobal2 = WebAssembly.instanceExport(instance, "readGlobal2");
final Object result1 = interop.execute(readGlobal1);
final Object result2 = interop.execute(readGlobal2);
Assert.assertEquals("Must be " + globalValue + " initially.", globalValue, result1);
Assert.assertEquals("Must be " + globalValue + " initially.", globalValue, result2);
} catch (InteropException e) {
throw new RuntimeException(e);
}
});
}
use of org.graalvm.wasm.globals.WasmGlobal in project graal by oracle.
the class WasmJsApiSuite method testGlobalEmbedderData.
@Test
public void testGlobalEmbedderData() throws IOException {
runTest(context -> {
WasmGlobal global = WebAssembly.globalAlloc(ValueType.i32, false, 0);
checkEmbedderData(global);
});
}
use of org.graalvm.wasm.globals.WasmGlobal in project graal by oracle.
the class ImportModule method createInstance.
@Override
protected WasmInstance createInstance(WasmLanguage language, WasmContext context, String name) {
WasmInstance instance = new WasmInstance(context, WasmModule.createBuiltin(name), functions.size());
for (Map.Entry<String, Pair<WasmFunction, Object>> entry : functions.entrySet()) {
final String functionName = entry.getKey();
final Pair<WasmFunction, Object> info = entry.getValue();
final WasmFunction function = info.getLeft();
final SymbolTable.FunctionType type = function.type();
if (info.getRight() instanceof WasmFunctionInstance) {
defineExportedFunction(instance, functionName, type.paramTypes(), type.returnTypes(), (WasmFunctionInstance) info.getRight());
} else {
defineFunction(instance, functionName, type.paramTypes(), type.returnTypes(), new ExecuteInParentContextNode(context.language(), instance, info.getRight()));
}
}
for (Map.Entry<String, WasmMemory> entry : memories.entrySet()) {
final String memoryName = entry.getKey();
final WasmMemory memory = entry.getValue();
defineExternalMemory(instance, memoryName, memory);
}
for (Map.Entry<String, WasmTable> entry : tables.entrySet()) {
final String tableName = entry.getKey();
final WasmTable table = entry.getValue();
defineExternalTable(instance, tableName, table);
}
for (Map.Entry<String, WasmGlobal> entry : globals.entrySet()) {
final String globalName = entry.getKey();
final WasmGlobal global = entry.getValue();
defineExternalGlobal(instance, globalName, global);
}
return instance;
}
Aggregations