class WAG::WABT
Public Class Methods
new()
click to toggle source
# File lib/wag/wabt.rb, line 9 def initialize throw 'Unable to find `wat2wasm` in path. Please install WABT.' unless find_util('wat2wasm') end
Public Instance Methods
wasm_validate(wasm_source)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
find_util(util_name)
click to toggle source
# File lib/wag/wabt.rb, line 38 def find_util(util_name) path = `which #{util_name}`.strip return nil if path.empty? path end