Search in sources :

Example 1 with ExportTableSym

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

the class Linker method resolveTableImport.

void resolveTableImport(WasmContext context, WasmInstance instance, ImportDescriptor importDescriptor, int declaredMinSize, int declaredMaxSize) {
    final Runnable resolveAction = () -> {
        final WasmInstance importedInstance = context.moduleInstances().get(importDescriptor.moduleName);
        final String importedModuleName = importDescriptor.moduleName;
        if (importedInstance == null) {
            throw WasmException.create(Failure.UNKNOWN_IMPORT, String.format("Imported module '%s', referenced in module '%s', does not exist.", importedModuleName, instance.name()));
        } else {
            final String importedTableName = importDescriptor.memberName;
            final List<String> exportedTableNames = importedInstance.symbolTable().exportedTableNames();
            if (exportedTableNames.size() == 0) {
                throw WasmException.create(Failure.UNKNOWN_IMPORT, String.format("The imported module '%s' does not export any tables, so cannot resolve table '%s' imported in module '%s'.", importedModuleName, importedTableName, instance.name()));
            }
            if (!exportedTableNames.contains(importedTableName)) {
                throw WasmException.create(Failure.UNKNOWN_IMPORT, String.format("The imported module '%s' exports a table '%s', but module '%s' imports a table '%s'.", importedModuleName, exportedTableNames, instance.name(), importedTableName));
            }
            final WasmTable table = importedInstance.table();
            // 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, table.declaredMinSize(), Failure.INCOMPATIBLE_IMPORT_TYPE);
            assertUnsignedIntGreaterOrEqual(declaredMaxSize, table.declaredMaxSize(), Failure.INCOMPATIBLE_IMPORT_TYPE);
            instance.setTable(table);
        }
    };
    Sym[] dependencies = new Sym[] { new ExportTableSym(importDescriptor.moduleName, importDescriptor.memberName) };
    resolutionDag.resolveLater(new ImportTableSym(instance.name(), importDescriptor), dependencies, resolveAction);
}
Also used : ImportTableSym(org.graalvm.wasm.Linker.ResolutionDag.ImportTableSym) 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) ArrayList(java.util.ArrayList) List(java.util.List) ExportTableSym(org.graalvm.wasm.Linker.ResolutionDag.ExportTableSym)

Example 2 with ExportTableSym

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

the class Linker method resolveTableExport.

void resolveTableExport(WasmModule module, String exportedTableName) {
    final ImportDescriptor importDescriptor = module.symbolTable().importedTable();
    final Sym[] dependencies = importDescriptor != null ? new Sym[] { new ImportTableSym(module.name(), importDescriptor) } : ResolutionDag.NO_DEPENDENCIES;
    resolutionDag.resolveLater(new ExportTableSym(module.name(), exportedTableName), dependencies, NO_RESOLVE_ACTION);
}
Also used : ImportTableSym(org.graalvm.wasm.Linker.ResolutionDag.ImportTableSym) 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) ExportTableSym(org.graalvm.wasm.Linker.ResolutionDag.ExportTableSym)

Aggregations

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