use of org.graalvm.wasm.WasmContext in project graal by oracle.
the class WasmRootNode method execute.
@Override
public final Object execute(VirtualFrame frame) {
final WasmContext context = getContext();
tryInitialize(context);
return executeWithContext(frame, context);
}
use of org.graalvm.wasm.WasmContext in project graal by oracle.
the class WebAssembly method moduleInstantiate.
public WasmInstance moduleInstantiate(WasmModule module, Object importObject) {
final TruffleContext innerTruffleContext = currentContext.environment().newContextBuilder().build();
final Object prev = innerTruffleContext.enter(null);
try {
final WasmContext instanceContext = WasmContext.get(null);
WasmInstance instance = instantiateModule(module, importObject, instanceContext, innerTruffleContext);
instanceContext.linker().tryLink(instance);
return instance;
} finally {
innerTruffleContext.leave(null, prev);
}
}
use of org.graalvm.wasm.WasmContext in project graal by oracle.
the class SaveBinaryFileNode method saveFile.
@CompilerDirectives.TruffleBoundary
private void saveFile(int filenamePtr, int dataPtr, int size) {
final WasmContext context = getContext();
Assert.assertIntLessOrEqual(context.memories().count(), 1, "Currently, dumping works with only 1 memory.", Failure.UNSPECIFIED_MALFORMED);
final WasmMemory memory = context.memories().memory(0);
// Read the file name.
String filename = readFileName(memory, filenamePtr);
final Path temporaryFile = temporaryDirectory.resolve(filename);
if (!TestutilModule.Options.KEEP_TEMP_FILES.equals("true")) {
temporaryFile.toFile().deleteOnExit();
}
// Read the byte array.
byte[] bytes = new byte[size];
for (int i = 0; i < size; i++) {
bytes[i] = (byte) memory.load_i32_8u(this, dataPtr + i);
}
// Store the byte array to a temporary file.
try (FileOutputStream stream = new FileOutputStream(temporaryFile.toFile())) {
stream.write(bytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations