Search in sources :

Example 6 with WasmContext

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);
}
Also used : WasmContext(org.graalvm.wasm.WasmContext)

Example 7 with WasmContext

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);
    }
}
Also used : WasmContext(org.graalvm.wasm.WasmContext) WasmInstance(org.graalvm.wasm.WasmInstance) TruffleContext(com.oracle.truffle.api.TruffleContext)

Example 8 with WasmContext

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);
    }
}
Also used : Path(java.nio.file.Path) WasmContext(org.graalvm.wasm.WasmContext) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) WasmMemory(org.graalvm.wasm.memory.WasmMemory)

Aggregations

WasmContext (org.graalvm.wasm.WasmContext)8 WasmInstance (org.graalvm.wasm.WasmInstance)3 TruffleContext (com.oracle.truffle.api.TruffleContext)2 Value (org.graalvm.polyglot.Value)2 WasmFunctionInstance (org.graalvm.wasm.WasmFunctionInstance)2 WasmMemory (org.graalvm.wasm.memory.WasmMemory)2 CallTarget (com.oracle.truffle.api.CallTarget)1 BytecodeInterpreterSwitch (com.oracle.truffle.api.HostCompilerDirectives.BytecodeInterpreterSwitch)1 BytecodeInterpreterSwitchBoundary (com.oracle.truffle.api.HostCompilerDirectives.BytecodeInterpreterSwitchBoundary)1 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 ArityException (com.oracle.truffle.api.interop.ArityException)1 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)1 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)1 LoopNode (com.oracle.truffle.api.nodes.LoopNode)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1