aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/Leb128Encoding.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/Leb128Encoding.java b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/Leb128Encoding.java
index 87d91520..71076da9 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/Leb128Encoding.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/structure/binary/Leb128Encoding.java
@@ -65,6 +65,15 @@ public class Leb128Encoding {
}
}
+ static void encodePaddedUnsignedInt64(long value, BinaryWriter writer) {
+ for (var byteIndex = 0; byteIndex < 9; byteIndex++) {
+ var nextByte = value & 0x7f;
+ writer.writeByte((byte) (nextByte | 0x80));
+ value >>>= 7;
+ }
+ writer.writeByte((byte) value);
+ }
+
static void encodeSignedInt64(long value, BinaryWriter writer) {
if (value >= 0) {
while (true) {
@@ -88,4 +97,17 @@ public class Leb128Encoding {
}
}
}
+
+ static void encodePaddedSignedInt64(long value, BinaryWriter writer) {
+ if (value > 0) {
+ encodePaddedUnsignedInt64(value, writer);
+ } else {
+ for (var byteIndex = 0; byteIndex < 9; byteIndex++) {
+ var nextByte = value & 0x7f;
+ writer.writeByte((byte) (nextByte | 0x80));
+ value >>= 7;
+ }
+ writer.writeByte((byte) (value & 0x7f));
+ }
+ }
}