diff --git a/Makefile b/Makefile index 9eb1785..eef7502 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,19 @@ +WABT_DIR := /home/johan/Sources/github.com/WebAssembly/wabt + +WAT2WASM := $(WABT_DIR)/bin/wat2wasm +WASM2C := $(WABT_DIR)/bin/wasm2c + %.wat: %.py py2wasm/*.py python3.8 -m py2wasm $< $@ %.wasm: %.wat - wat2wasm $^ -o $@ + $(WAT2WASM) $^ -o $@ + +%.c: %.wasm + $(WASM2C) $^ -o $@ + +# %.exe: %.c +# cc $^ -o $@ -I $(WABT_DIR)/wasm2c server: python3.8 -m http.server diff --git a/tests/integration/test_helper.py b/tests/integration/test_helper.py new file mode 100644 index 0000000..cde6560 --- /dev/null +++ b/tests/integration/test_helper.py @@ -0,0 +1,33 @@ +import io + +import pytest + +from pywasm import binary +from pywasm import Runtime + +from .helpers import wat2wasm + +@pytest.mark.parametrize('size,offset,output', [ + ('32', 0, 0x3020100), + ('32', 1, 0x4030201), + ('64', 0, 0x706050403020100), + ('64', 2, 0x908070605040302), +]) +def test_i32_64_load(size, offset, output): + code_wat = f""" + (module + (memory 1) + (data (memory 0) (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\10") + + (func (export "testEntry") (result i{size}) + i32.const {offset} + i{size}.load + return )) +""" + code_wasm = wat2wasm(code_wat) + module = binary.Module.from_reader(io.BytesIO(code_wasm)) + + runtime = Runtime(module, {}, {}) + + out_put = runtime.exec('testEntry', []) + assert output == out_put