aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-21 16:49:29 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-21 16:49:29 +0000
commit008285a797c969ab1a5addac9b44f93a0063c4f3 (patch)
treedbf8edf3c8c63b2dcf52af540cd2b688457d6de6 /src/main/java
parentb51059a7cbec54cc89811dd8e78d1bd3e55ca081 (diff)
Don't assume relocatable section is CODE
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java
index c8fc458b..14393722 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryWriter.java
@@ -118,11 +118,14 @@ public class WasmBinaryWriter {
WasmRelocatableIndex index
) throws IOException {
// TODO: handle custom sections?
- var isRelocatable = currentSection
- .map(c -> c == WasmSectionId.CODE || c == WasmSectionId.DATA)
- .orElse(false);
-
- if (isRelocatable) {
+ var relocatableSectionName = currentSection
+ .flatMap(c -> switch (c) {
+ case CODE -> Optional.of("CODE");
+ case DATA -> Optional.of("DATA");
+ default -> Optional.empty();
+ });
+
+ if (relocatableSectionName.isPresent()) {
var value = unrelocatedIndex.orElse(0);
var sectionContentsOffset = writer.position() - sectionContentsStart;
if (relocationType.isSigned()) {
@@ -132,8 +135,10 @@ public class WasmBinaryWriter {
}
if (!relocationSections.containsKey(sectionIndex)) {
- // TODO: don't assume CODE
- relocationSections.put(sectionIndex, WasmRelocationSection.empty(sectionIndex, "CODE"));
+ relocationSections.put(sectionIndex, WasmRelocationSection.empty(
+ sectionIndex,
+ relocatableSectionName.get()
+ ));
}
relocationSections.get(sectionIndex).addEntry(new WasmRelocationEntry(
relocationType,