Search in sources :

Example 1 with ExportGlobalSym

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

the class Linker method resolveGlobalImport.

void resolveGlobalImport(WasmContext context, WasmInstance instance, ImportDescriptor importDescriptor, int globalIndex, byte valueType, byte mutability) {
    final String importedGlobalName = importDescriptor.memberName;
    final String importedModuleName = importDescriptor.moduleName;
    final Runnable resolveAction = () -> {
        final WasmInstance importedInstance = context.moduleInstances().get(importedModuleName);
        if (importedInstance == null) {
            throw WasmException.create(Failure.UNKNOWN_IMPORT, "Module '" + importedModuleName + "', referenced in the import of global variable '" + importedGlobalName + "' into module '" + instance.name() + "', does not exist.");
        }
        // Check that the imported global is resolved in the imported module.
        Integer exportedGlobalIndex = importedInstance.symbolTable().exportedGlobals().get(importedGlobalName);
        if (exportedGlobalIndex == null) {
            throw WasmException.create(Failure.UNKNOWN_IMPORT, "Global variable '" + importedGlobalName + "', imported into module '" + instance.name() + "', was not exported in the module '" + importedModuleName + "'.");
        }
        int exportedValueType = importedInstance.symbolTable().globalValueType(exportedGlobalIndex);
        if (exportedValueType != valueType) {
            throw WasmException.create(Failure.INCOMPATIBLE_IMPORT_TYPE, "Global variable '" + importedGlobalName + "' is imported into module '" + instance.name() + "' with the type " + WasmType.toString(valueType) + ", " + "'but it was exported in the module '" + importedModuleName + "' with the type " + WasmType.toString(exportedValueType) + ".");
        }
        int exportedMutability = importedInstance.symbolTable().globalMutability(exportedGlobalIndex);
        if (exportedMutability != mutability) {
            throw WasmException.create(Failure.INCOMPATIBLE_IMPORT_TYPE, "Global variable '" + importedGlobalName + "' is imported into module '" + instance.name() + "' with the modifier " + GlobalModifier.asString(mutability) + ", " + "'but it was exported in the module '" + importedModuleName + "' with the modifier " + GlobalModifier.asString(exportedMutability) + ".");
        }
        int address = importedInstance.globalAddress(exportedGlobalIndex);
        instance.setGlobalAddress(globalIndex, address);
    };
    final ImportGlobalSym importGlobalSym = new ImportGlobalSym(instance.name(), importDescriptor, globalIndex);
    final Sym[] dependencies = new Sym[] { new ExportGlobalSym(importedModuleName, importedGlobalName) };
    resolutionDag.resolveLater(importGlobalSym, dependencies, resolveAction);
    resolutionDag.resolveLater(new InitializeGlobalSym(instance.name(), globalIndex), new Sym[] { importGlobalSym }, NO_RESOLVE_ACTION);
}
Also used : ExportGlobalSym(org.graalvm.wasm.Linker.ResolutionDag.ExportGlobalSym) ImportGlobalSym(org.graalvm.wasm.Linker.ResolutionDag.ImportGlobalSym) 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) InitializeGlobalSym(org.graalvm.wasm.Linker.ResolutionDag.InitializeGlobalSym)

Example 2 with ExportGlobalSym

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

the class Linker method resolveGlobalExport.

void resolveGlobalExport(WasmModule module, String globalName, int globalIndex) {
    final Sym[] dependencies;
    dependencies = new Sym[] { new InitializeGlobalSym(module.name(), globalIndex) };
    resolutionDag.resolveLater(new ExportGlobalSym(module.name(), globalName), dependencies, NO_RESOLVE_ACTION);
}
Also used : ExportGlobalSym(org.graalvm.wasm.Linker.ResolutionDag.ExportGlobalSym) 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) InitializeGlobalSym(org.graalvm.wasm.Linker.ResolutionDag.InitializeGlobalSym)

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