Search in sources :

Example 1 with ImportFunctionSym

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

the class Linker method resolveElemSegment.

void resolveElemSegment(WasmContext context, WasmInstance instance, int elemSegmentId, int offsetAddress, int offsetGlobalIndex, int[] functionsIndices) {
    final Runnable resolveAction = () -> immediatelyResolveElemSegment(context, instance, elemSegmentId, offsetAddress, offsetGlobalIndex, functionsIndices);
    final ArrayList<Sym> dependencies = new ArrayList<>();
    if (instance.symbolTable().importedTable() != null) {
        dependencies.add(new ImportTableSym(instance.name(), instance.symbolTable().importedTable()));
    }
    if (elemSegmentId > 0) {
        dependencies.add(new ElemSym(instance.name(), elemSegmentId - 1));
    }
    if (offsetGlobalIndex != -1) {
        dependencies.add(new InitializeGlobalSym(instance.name(), offsetGlobalIndex));
    }
    for (final int functionIndex : functionsIndices) {
        final WasmFunction function = instance.module().function(functionIndex);
        if (function.importDescriptor() != null) {
            dependencies.add(new ImportFunctionSym(instance.name(), function.importDescriptor(), function.index()));
        }
    }
    resolutionDag.resolveLater(new ElemSym(instance.name(), elemSegmentId), dependencies.toArray(new Sym[dependencies.size()]), resolveAction);
}
Also used : ElemSym(org.graalvm.wasm.Linker.ResolutionDag.ElemSym) 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) InitializeGlobalSym(org.graalvm.wasm.Linker.ResolutionDag.InitializeGlobalSym) ImportFunctionSym(org.graalvm.wasm.Linker.ResolutionDag.ImportFunctionSym)

Example 2 with ImportFunctionSym

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

the class Linker method resolveCallsite.

void resolveCallsite(WasmInstance instance, WasmBlockNode block, int controlTableOffset, WasmFunction function) {
    final Runnable resolveAction = () -> block.resolveCallNode(controlTableOffset);
    final Sym[] dependencies = new Sym[] { function.isImported() ? new ImportFunctionSym(instance.name(), function.importDescriptor(), function.index()) : new CodeEntrySym(instance.name(), function.index()) };
    resolutionDag.resolveLater(new CallsiteSym(instance.name(), block.startOffset(), controlTableOffset), dependencies, resolveAction);
}
Also used : CodeEntrySym(org.graalvm.wasm.Linker.ResolutionDag.CodeEntrySym) CallsiteSym(org.graalvm.wasm.Linker.ResolutionDag.CallsiteSym) 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) ImportFunctionSym(org.graalvm.wasm.Linker.ResolutionDag.ImportFunctionSym)

Example 3 with ImportFunctionSym

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

the class Linker method resolveFunctionImport.

void resolveFunctionImport(WasmContext context, WasmInstance instance, WasmFunction function) {
    final Runnable resolveAction = () -> {
        final WasmInstance importedInstance = context.moduleInstances().get(function.importedModuleName());
        if (importedInstance == null) {
            throw WasmException.create(Failure.UNKNOWN_IMPORT, "The module '" + function.importedModuleName() + "', referenced by the import '" + function.importedFunctionName() + "' in the module '" + instance.name() + "', does not exist.");
        }
        WasmFunction importedFunction = importedInstance.module().exportedFunctions().get(function.importedFunctionName());
        if (importedFunction == null) {
            throw WasmException.create(Failure.UNKNOWN_IMPORT, "The imported function '" + function.importedFunctionName() + "', referenced in the module '" + instance.name() + "', does not exist in the imported module '" + function.importedModuleName() + "'.");
        }
        if (!function.type().equals(importedFunction.type())) {
            throw WasmException.create(Failure.INCOMPATIBLE_IMPORT_TYPE);
        }
        final CallTarget target = importedInstance.target(importedFunction.index());
        final WasmFunctionInstance functionInstance = importedInstance.functionInstance(importedFunction);
        instance.setTarget(function.index(), target);
        instance.setFunctionInstance(function.index(), functionInstance);
    };
    final Sym[] dependencies = new Sym[] { new ExportFunctionSym(function.importDescriptor().moduleName, function.importDescriptor().memberName) };
    resolutionDag.resolveLater(new ImportFunctionSym(instance.name(), function.importDescriptor(), function.index()), dependencies, resolveAction);
}
Also used : ExportFunctionSym(org.graalvm.wasm.Linker.ResolutionDag.ExportFunctionSym) CallTarget(com.oracle.truffle.api.CallTarget) 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) ImportFunctionSym(org.graalvm.wasm.Linker.ResolutionDag.ImportFunctionSym)

Example 4 with ImportFunctionSym

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

the class Linker method resolveFunctionExport.

void resolveFunctionExport(WasmModule module, int functionIndex, String exportedFunctionName) {
    final ImportDescriptor importDescriptor = module.symbolTable().function(functionIndex).importDescriptor();
    final Sym[] dependencies = (importDescriptor != null) ? new Sym[] { new ImportFunctionSym(module.name(), importDescriptor, functionIndex) } : ResolutionDag.NO_DEPENDENCIES;
    resolutionDag.resolveLater(new ExportFunctionSym(module.name(), exportedFunctionName), dependencies, NO_RESOLVE_ACTION);
}
Also used : ExportFunctionSym(org.graalvm.wasm.Linker.ResolutionDag.ExportFunctionSym) 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) ImportFunctionSym(org.graalvm.wasm.Linker.ResolutionDag.ImportFunctionSym)

Aggregations

CallsiteSym (org.graalvm.wasm.Linker.ResolutionDag.CallsiteSym)4 CodeEntrySym (org.graalvm.wasm.Linker.ResolutionDag.CodeEntrySym)4 DataSym (org.graalvm.wasm.Linker.ResolutionDag.DataSym)4 ElemSym (org.graalvm.wasm.Linker.ResolutionDag.ElemSym)4 ExportFunctionSym (org.graalvm.wasm.Linker.ResolutionDag.ExportFunctionSym)4 ExportGlobalSym (org.graalvm.wasm.Linker.ResolutionDag.ExportGlobalSym)4 ExportMemorySym (org.graalvm.wasm.Linker.ResolutionDag.ExportMemorySym)4 ExportTableSym (org.graalvm.wasm.Linker.ResolutionDag.ExportTableSym)4 ImportFunctionSym (org.graalvm.wasm.Linker.ResolutionDag.ImportFunctionSym)4 ImportGlobalSym (org.graalvm.wasm.Linker.ResolutionDag.ImportGlobalSym)4 ImportMemorySym (org.graalvm.wasm.Linker.ResolutionDag.ImportMemorySym)4 ImportTableSym (org.graalvm.wasm.Linker.ResolutionDag.ImportTableSym)4 InitializeGlobalSym (org.graalvm.wasm.Linker.ResolutionDag.InitializeGlobalSym)4 Sym (org.graalvm.wasm.Linker.ResolutionDag.Sym)4 CallTarget (com.oracle.truffle.api.CallTarget)1 ArrayList (java.util.ArrayList)1