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