aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
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 /src/main/java
parent60270ec2c59b803804d67dd94ceea12b8857e4d7 (diff)
Don't write empty symbol table
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/WasmBinaryFormatLinking.java55
1 files changed, 32 insertions, 23 deletions
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) {