Skip to content

Commit

Permalink
The exported global type now contains the mutability.
Browse files Browse the repository at this point in the history
The custom section lookup can now deal with TruffleStrings.
  • Loading branch information
flohuemer committed Sep 5, 2022
1 parent 96d195f commit 1151ada
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.Map;
import java.util.Objects;

import com.oracle.truffle.api.strings.TruffleString;
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.Pair;
import org.graalvm.wasm.EmbedderDataHolder;
Expand Down Expand Up @@ -349,7 +350,8 @@ public static Sequence<ModuleExportDescriptor> moduleExports(WasmModule module)
list.add(new ModuleExportDescriptor(name, ImportExportKind.function.name(), WebAssembly.functionTypeToString(f)));
} else if (globalIndex != null) {
String valueType = ValueType.fromByteValue(module.globalValueType(globalIndex)).toString();
list.add(new ModuleExportDescriptor(name, ImportExportKind.global.name(), valueType));
String mutability = module.isGlobalMutable(globalIndex) ? "mut" : "con";
list.add(new ModuleExportDescriptor(name, ImportExportKind.global.name(), valueType + " " + mutability));
} else {
throw WasmException.create(Failure.UNSPECIFIED_INTERNAL, "Exported symbol list does not match the actual exports.");
}
Expand Down Expand Up @@ -405,9 +407,15 @@ private static Object customSections(Object[] args) {
}

public static Sequence<ByteArrayBuffer> customSections(WasmModule module, Object sectionName) {
Object name;
if (sectionName instanceof TruffleString) {
name = sectionName.toString();
} else {
name = sectionName;
}
List<ByteArrayBuffer> sections = new ArrayList<>();
for (WasmCustomSection section : module.customSections()) {
if (section.getName().equals(sectionName)) {
if (section.getName().equals(name)) {
sections.add(new ByteArrayBuffer(module.data(), section.getOffset(), section.getLength()));
}
}
Expand Down

0 comments on commit 1151ada

Please sign in to comment.