aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-06-25 14:48:50 +0100
committerMichael Williamson <mike@zwobble.org>2023-06-25 14:48:50 +0100
commit5d987fd53baf2dd6632cc6db8d7acea7633f6780 (patch)
tree84bf035c84a41f07818582f5cc2b8a6a933116f6
parent60270ec2c59b803804d67dd94ceea12b8857e4d7 (diff)
Don't write empty symbol table
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeEmptyModule(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected1
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithDataSegments(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected1
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemories(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected1
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemoryImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected1
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTableImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected1
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTables(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected1
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTypes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected1
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatLinking.java55
8 files changed, 32 insertions, 30 deletions
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeEmptyModule(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeEmptyModule(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index e4409dc6..340b1609 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeEmptyModule(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeEmptyModule(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -7,6 +7,5 @@ Custom:
- name: "name"
Custom:
- name: "linking"
- - symbol table [count=0]
Code Disassembly:
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithDataSegments(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithDataSegments(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 13654007..b3753d8b 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithDataSegments(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithDataSegments(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -17,6 +17,5 @@ Custom:
- segment info [count=2]
- 0: .data p2align=2 [ ]
- 1: .rodata p2align=0 [ ]
- - symbol table [count=0]
Code Disassembly:
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemories(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemories(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index efbfd916..8b870190 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemories(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemories(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -9,6 +9,5 @@ Custom:
- name: "name"
Custom:
- name: "linking"
- - symbol table [count=0]
Code Disassembly:
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemoryImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemoryImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index b4b87bb6..6a59736f 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemoryImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithMemoryImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -9,6 +9,5 @@ Custom:
- name: "name"
Custom:
- name: "linking"
- - symbol table [count=0]
Code Disassembly:
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTableImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTableImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 5a718c59..67836ea0 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTableImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTableImports(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -10,6 +10,5 @@ Custom:
- name: "name"
Custom:
- name: "linking"
- - symbol table [count=0]
Code Disassembly:
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTables(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTables(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index e7d86cec..cf945e0d 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTables(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTables(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -10,6 +10,5 @@ Custom:
- name: "name"
Custom:
- name: "linking"
- - symbol table [count=0]
Code Disassembly:
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTypes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTypes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index d49f4d8d..9434e657 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTypes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.backends.wasm.structure.WasmBinaryFormatModuleTests]/[method:canSerializeModuleWithTypes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -10,6 +10,5 @@ Custom:
- name: "name"
Custom:
- name: "linking"
- - symbol table [count=0]
Code Disassembly:
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatLinking.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatLinking.java
index 1023206e..3cb75953 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatLinking.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatLinking.java
@@ -1,6 +1,7 @@
package org.shedlang.compiler.backends.wasm.structure.binary;
import org.shedlang.compiler.backends.wasm.structure.BinaryWriter;
+import org.shedlang.compiler.backends.wasm.structure.ast.linking.WasmInitFunc;
import org.shedlang.compiler.backends.wasm.structure.ast.linking.WasmSymbolIndex;
import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmAlignment;
import org.shedlang.compiler.backends.wasm.structure.ast.modules.WasmFuncIndex;
@@ -38,12 +39,8 @@ public class WasmBinaryFormatLinking {
var symbolTable = generateSymbolTable(module);
writeSegmentInfoSubsection(module, writer);
-
writeSymbolTableSubsection(symbolTable, writer);
-
- if (module.initFuncs().size() > 0) {
- writeInitFuncsSubsection(module, symbolTable, writer);
- }
+ writeInitFuncsSubsection(module, symbolTable, writer);
});
}
@@ -93,30 +90,42 @@ public class WasmBinaryFormatLinking {
SymbolTable symbolTable,
BinaryWriter writer
) throws IOException {
- writeSubsection(SubsectionType.WASM_INIT_FUNCS, writer, () -> {
- writeVec(
- module.initFuncs(),
- initFunc -> {
- Leb128Encoding.encodeUnsignedInt32(initFunc.priority(), writer);
- var symbolIndex = symbolTable.funcIndexToSymbolIndex(initFunc.funcIndex());
- writeSymbolIndex(symbolIndex, writer);
- },
- writer
- );
- });
+ if (module.initFuncs().size() > 0) {
+ writeSubsection(SubsectionType.WASM_INIT_FUNCS, writer, () -> {
+ writeVec(
+ module.initFuncs(),
+ initFunc -> {
+ writeInitFunc(initFunc, symbolTable, writer);
+ },
+ writer
+ );
+ });
+ }
+ }
+
+ private static void writeInitFunc(
+ WasmInitFunc initFunc,
+ SymbolTable symbolTable,
+ BinaryWriter writer
+ ) {
+ Leb128Encoding.encodeUnsignedInt32(initFunc.priority(), writer);
+ var symbolIndex = symbolTable.funcIndexToSymbolIndex(initFunc.funcIndex());
+ writeSymbolIndex(symbolIndex, writer);
}
private static void writeSymbolTableSubsection(
SymbolTable symbolTable,
BinaryWriter writer
) throws IOException {
- writeSubsection(SubsectionType.WASM_SYMBOL_TABLE, writer, () -> {
- writeVec(
- symbolTable.symbolInfos,
- symbolInfo -> writeSymbolInfo(symbolInfo, writer),
- writer
- );
- });
+ if (symbolTable.symbolInfos.size() > 0) {
+ writeSubsection(SubsectionType.WASM_SYMBOL_TABLE, writer, () -> {
+ writeVec(
+ symbolTable.symbolInfos,
+ symbolInfo -> writeSymbolInfo(symbolInfo, writer),
+ writer
+ );
+ });
+ }
}
private static void writeSymbolInfo(SymbolInfo symbolInfo, BinaryWriter writer) {