Search in sources :

Example 1 with ExportFunctionSym

use of org.graalvm.wasm.Linker.ResolutionDag.ExportFunctionSym 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 2 with ExportFunctionSym

use of org.graalvm.wasm.Linker.ResolutionDag.ExportFunctionSym 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)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 CallTarget (com.oracle.truffle.api.CallTarget)1