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);
}
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);
}
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);
}
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);
}
Aggregations