Search in sources :

Example 1 with ModuleExportDescriptor

use of org.graalvm.wasm.api.ModuleExportDescriptor in project graal by oracle.

the class WasmJsApiSuite method testCompile.

@Test
public void testCompile() throws IOException {
    runTest(context -> {
        final WebAssembly wasm = new WebAssembly(context);
        final WasmModule module = wasm.moduleDecode(binaryWithExports);
        try {
            HashMap<String, ModuleExportDescriptor> exports = new HashMap<>();
            int i = 0;
            while (i < WebAssembly.moduleExports(module).getArraySize()) {
                final ModuleExportDescriptor d = (ModuleExportDescriptor) WebAssembly.moduleExports(module).readArrayElement(i);
                exports.put(d.name(), d);
                i++;
            }
            Assert.assertEquals("Should export main.", ImportExportKind.function, exports.get("main").kind());
            Assert.assertEquals("Should export memory.", ImportExportKind.memory, exports.get("memory").kind());
            Assert.assertEquals("Should export global __heap_base.", ImportExportKind.global, exports.get("__heap_base").kind());
            Assert.assertEquals("Should export global __data_end.", ImportExportKind.global, exports.get("__data_end").kind());
            Assert.assertEquals("Should have empty imports.", 0L, WebAssembly.moduleImports(module).getArraySize());
        } catch (InvalidArrayIndexException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : WasmModule(org.graalvm.wasm.WasmModule) InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) HashMap(java.util.HashMap) WebAssembly(org.graalvm.wasm.api.WebAssembly) ModuleExportDescriptor(org.graalvm.wasm.api.ModuleExportDescriptor) Test(org.junit.Test)

Aggregations

InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)1 HashMap (java.util.HashMap)1 WasmModule (org.graalvm.wasm.WasmModule)1 ModuleExportDescriptor (org.graalvm.wasm.api.ModuleExportDescriptor)1 WebAssembly (org.graalvm.wasm.api.WebAssembly)1 Test (org.junit.Test)1