leb128
LEB128, the variable-length integer encoding WebAssembly uses for every index, count and constant: 7 bits per byte, low bits first, with the top bit set on every byte but the last.
from std.wasm.leb128 import *
macro leb(value: int) {
@emit uleb128(value)
}
macro sleb(value: int) {
@emit sleb128(value)
}
leb 624485
sleb -123456
e5 8e 26
c0 bb 78
Macros
uleb128_length
How many bytes value, which can’t be negative, takes as unsigned
LEB128.
| Syntax | Parameters | Result | Description |
|---|---|---|---|
uleb128_length(value) | value: int | returns int |
uleb128_padded
value as unsigned LEB128 in exactly n bytes. A larger n than
uleb128_length(value) pads with zero groups, which WebAssembly allows,
to give a field a fixed width.
| Syntax | Parameters | Result | Description |
|---|---|---|---|
uleb128_padded(value, n) | value: int, n: int | returns Bytes<...> |
uleb128
value, which can’t be negative, as unsigned LEB128 in as few bytes as
possible.
| Syntax | Parameters | Result | Description |
|---|---|---|---|
uleb128(value) | value: int | returns Bytes<...> |
sleb128_length
How many bytes value takes as signed LEB128.
| Syntax | Parameters | Result | Description |
|---|---|---|---|
sleb128_length(value) | value: int | returns int |
sleb128_padded
value as signed LEB128 in exactly n bytes, sign-extended to fill any
extra ones.
| Syntax | Parameters | Result | Description |
|---|---|---|---|
sleb128_padded(value, n) | value: int, n: int | returns Bytes<...> |
sleb128
value as signed LEB128 in as few bytes as possible.
| Syntax | Parameters | Result | Description |
|---|---|---|---|
sleb128(value) | value: int | returns Bytes<...> |
Types
Byte
type Byte = bits<8>
A byte.
Bytes
struct Bytes<const N: int>
N bytes, packed by bitter in order: a LEB128 encoding, or a whole
instruction.
Some of its fields are generated by @for or @if.