Search in sources :

Example 1 with ExportMemorySym

use of org.graalvm.wasm.Linker.ResolutionDag.ExportMemorySym in project graal by oracle.

the class Linker method resolveMemoryExport.

void resolveMemoryExport(WasmInstance instance, String exportedMemoryName) {
    WasmModule module = instance.module();
    final ImportDescriptor importDescriptor = module.symbolTable().importedMemory();
    final Sym[] dependencies = importDescriptor != null ? new Sym[] { new ImportMemorySym(module.name(), importDescriptor) } : ResolutionDag.NO_DEPENDENCIES;
    resolutionDag.resolveLater(new ExportMemorySym(module.name(), exportedMemoryName), dependencies, () -> {
    });
}
Also used : ImportMemorySym(org.graalvm.wasm.Linker.ResolutionDag.ImportMemorySym) ElemSym(org.graalvm.wasm.Linker.ResolutionDag.ElemSym) ExportMemorySym(org.graalvm.wasm.Linker.ResolutionDag.ExportMemorySym) ExportTableSym(org.graalvm.wasm.Linker.ResolutionDag.ExportTableSym) InitializeGlobalSym(org.graalvm.wasm.Linker.ResolutionDag.InitializeGlobalSym) ExportFunctionSym(org.graalvm.wasm.Linker.ResolutionDag.ExportFunctionSym) CodeEntrySym(org.graalvm.wasm.Linker.ResolutionDag.CodeEntrySym) CallsiteSym(org.graalvm.wasm.Linker.ResolutionDag.CallsiteSym) ImportMemorySym(org.graalvm.wasm.Linker.ResolutionDag.ImportMemorySym) ExportGlobalSym(org.graalvm.wasm.Linker.ResolutionDag.ExportGlobalSym) ImportFunctionSym(org.graalvm.wasm.Linker.ResolutionDag.ImportFunctionSym) Sym(org.graalvm.wasm.Linker.ResolutionDag.Sym) ImportTableSym(org.graalvm.wasm.Linker.ResolutionDag.ImportTableSym) ImportGlobalSym(org.graalvm.wasm.Linker.ResolutionDag.ImportGlobalSym) DataSym(org.graalvm.wasm.Linker.ResolutionDag.DataSym) ExportMemorySym(org.graalvm.wasm.Linker.ResolutionDag.ExportMemorySym)

Example 2 with ExportMemorySym

use of org.graalvm.wasm.Linker.ResolutionDag.ExportMemorySym in project graal by oracle.

the class Linker method resolveMemoryImport.

void resolveMemoryImport(WasmContext context, WasmInstance instance, ImportDescriptor importDescriptor, int declaredMinSize, int declaredMaxSize) {
    final String importedModuleName = importDescriptor.moduleName;
    final String importedMemoryName = importDescriptor.memberName;
    final Runnable resolveAction = () -> {
        final WasmInstance importedInstance = context.moduleInstances().get(importedModuleName);
        if (importedInstance == null) {
            throw WasmException.create(Failure.UNKNOWN_IMPORT, String.format("The module '%s', referenced in the import of memory '%s' in module '%s', does not exist", importedModuleName, importedMemoryName, instance.name()));
        }
        final List<String> exportedMemory = importedInstance.symbolTable().exportedMemoryNames();
        if (exportedMemory.size() == 0) {
            throw WasmException.create(Failure.UNKNOWN_IMPORT, String.format("The imported module '%s' does not export any memories, so cannot resolve memory '%s' imported in module '%s'.", importedModuleName, importedMemoryName, instance.name()));
        }
        if (!exportedMemory.contains(importedMemoryName)) {
            throw WasmException.create(Failure.UNKNOWN_IMPORT, String.format("The imported module '%s' exports a memory '%s', but module '%s' imports a memory '%s'.", importedModuleName, exportedMemory, instance.name(), importedModuleName));
        }
        final WasmMemory memory = importedInstance.memory();
        // Rules for limits matching:
        // https://webassembly.github.io/spec/core/exec/modules.html#limits
        // If no max size is declared, then declaredMaxSize value will be
        // MAX_TABLE_DECLARATION_SIZE, so this condition will pass.
        assertUnsignedIntLessOrEqual(declaredMinSize, memory.declaredMinSize(), Failure.INCOMPATIBLE_IMPORT_TYPE);
        assertUnsignedIntGreaterOrEqual(declaredMaxSize, memory.declaredMaxSize(), Failure.INCOMPATIBLE_IMPORT_TYPE);
        instance.setMemory(memory);
    };
    resolutionDag.resolveLater(new ImportMemorySym(instance.name(), importDescriptor), new Sym[] { new ExportMemorySym(importedModuleName, importedMemoryName) }, resolveAction);
}
Also used : ImportMemorySym(org.graalvm.wasm.Linker.ResolutionDag.ImportMemorySym) ArrayList(java.util.ArrayList) List(java.util.List) WasmMemory(org.graalvm.wasm.memory.WasmMemory) ExportMemorySym(org.graalvm.wasm.Linker.ResolutionDag.ExportMemorySym)

Aggregations

ExportMemorySym (org.graalvm.wasm.Linker.ResolutionDag.ExportMemorySym)2 ImportMemorySym (org.graalvm.wasm.Linker.ResolutionDag.ImportMemorySym)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CallsiteSym (org.graalvm.wasm.Linker.ResolutionDag.CallsiteSym)1 CodeEntrySym (org.graalvm.wasm.Linker.ResolutionDag.CodeEntrySym)1 DataSym (org.graalvm.wasm.Linker.ResolutionDag.DataSym)1 ElemSym (org.graalvm.wasm.Linker.ResolutionDag.ElemSym)1 ExportFunctionSym (org.graalvm.wasm.Linker.ResolutionDag.ExportFunctionSym)1 ExportGlobalSym (org.graalvm.wasm.Linker.ResolutionDag.ExportGlobalSym)1 ExportTableSym (org.graalvm.wasm.Linker.ResolutionDag.ExportTableSym)1 ImportFunctionSym (org.graalvm.wasm.Linker.ResolutionDag.ImportFunctionSym)1 ImportGlobalSym (org.graalvm.wasm.Linker.ResolutionDag.ImportGlobalSym)1 ImportTableSym (org.graalvm.wasm.Linker.ResolutionDag.ImportTableSym)1 InitializeGlobalSym (org.graalvm.wasm.Linker.ResolutionDag.InitializeGlobalSym)1 Sym (org.graalvm.wasm.Linker.ResolutionDag.Sym)1 WasmMemory (org.graalvm.wasm.memory.WasmMemory)1