Class: Relaton::Un::Wasm::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton/un/wasm/decoder.rb

Overview

Binary WebAssembly decoder. Handles the subset of WASM MVP plus the sign-extension proposal that the shipped wasm_v_bg.wasm uses. No floats, no SIMD, no bulk-memory, no reference types beyond funcref.

Constant Summary collapse

MAGIC =
"\x00asm".b
VERSION =
"\x01\x00\x00\x00".b
VALTYPE_I32 =
0x7F
VALTYPE_I64 =
0x7E
VALTYPE_F32 =
0x7D
VALTYPE_F64 =
0x7C

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ Decoder

Returns a new instance of Decoder.



18
19
20
21
# File 'lib/relaton/un/wasm/decoder.rb', line 18

def initialize(bytes)
  @bytes = bytes.b
  @pos = 0
end

Instance Method Details

#decodeObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/relaton/un/wasm/decoder.rb', line 23

def decode
  header!
  mod = Module.new
  until eof?
    id = read_byte
    size = read_u32
    section_end = @pos + size
    decode_section(mod, id, section_end)
    @pos = section_end
  end
  mod
end