Class: WAG::WABT

Inherits:
Object
  • Object
show all
Defined in:
lib/wag/wabt.rb

Overview

Instance Method Summary collapse

Constructor Details

#initializeWABT

Returns a new instance of WABT.



9
10
11
# File 'lib/wag/wabt.rb', line 9

def initialize
  throw 'Unable to find `wat2wasm` in path. Please install WABT.' unless find_util('wat2wasm')
end

Instance Method Details

#wasm_validate(wasm_source) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wag/wabt.rb', line 24

def wasm_validate(wasm_source)
  Dir.mktmpdir('wasm-validate') do |dir|
    wasm_path = File.join(dir, 'validate.wasm')
    File.write(wasm_path, wasm_source)
    if system(find_util('wasm-validate'), wasm_path)
      true
    else
      false
    end
  end
end

#wat2wasm(wat_source) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/wag/wabt.rb', line 13

def wat2wasm(wat_source)
  Dir.mktmpdir('wat2wasm') do |dir|
    wat_path = File.join(dir, 'source.wat')
    wasm_path = File.join(dir, 'target.wasm')
    File.write(wat_path, wat_source)
    system(find_util('wat2wasm'), '-o', wasm_path, wat_path, exception: true)
    File.unlink(wat_path)
    File.read(wasm_path)
  end
end