use of org.graalvm.wasm.Linker.ResolutionDag.ExportMemorySym in project graal by oracle.
the class Linker method resolveMemoryExport.
void resolveMemoryExport(WasmInstance instance, String exportedMemoryName) {
WasmModule module = instance.module();
final ImportDescriptor importDescriptor = module.symbolTable().importedMemory();
final Sym[] dependencies = importDescriptor != null ? new Sym[] { new ImportMemorySym(module.name(), importDescriptor) } : ResolutionDag.NO_DEPENDENCIES;
resolutionDag.resolveLater(new ExportMemorySym(module.name(), exportedMemoryName), dependencies, () -> {
});
}
use of org.graalvm.wasm.Linker.ResolutionDag.ExportMemorySym in project graal by oracle.
the class Linker method resolveMemoryImport.
void resolveMemoryImport(WasmContext context, WasmInstance instance, ImportDescriptor importDescriptor, int declaredMinSize, int declaredMaxSize) {
final String importedModuleName = importDescriptor.moduleName;
final String importedMemoryName = importDescriptor.memberName;
final Runnable resolveAction = () -> {
final WasmInstance importedInstance = context.moduleInstances().get(importedModuleName);
if (importedInstance == null) {
throw WasmException.create(Failure.UNKNOWN_IMPORT, String.format("The module '%s', referenced in the import of memory '%s' in module '%s', does not exist", importedModuleName, importedMemoryName, instance.name()));
}
final List<String> exportedMemory = importedInstance.symbolTable().exportedMemoryNames();
if (exportedMemory.size() == 0) {
throw WasmException.create(Failure.UNKNOWN_IMPORT, String.format("The imported module '%s' does not export any memories, so cannot resolve memory '%s' imported in module '%s'.", importedModuleName, importedMemoryName, instance.name()));
}
if (!exportedMemory.contains(importedMemoryName)) {
throw WasmException.create(Failure.UNKNOWN_IMPORT, String.format("The imported module '%s' exports a memory '%s', but module '%s' imports a memory '%s'.", importedModuleName, exportedMemory, instance.name(), importedModuleName));
}
final WasmMemory memory = importedInstance.memory();
// 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, memory.declaredMinSize(), Failure.INCOMPATIBLE_IMPORT_TYPE);
assertUnsignedIntGreaterOrEqual(declaredMaxSize, memory.declaredMaxSize(), Failure.INCOMPATIBLE_IMPORT_TYPE);
instance.setMemory(memory);
};
resolutionDag.resolveLater(new ImportMemorySym(instance.name(), importDescriptor), new Sym[] { new ExportMemorySym(importedModuleName, importedMemoryName) }, resolveAction);
}
Aggregations