Skip to content

Commit

Permalink
[feature] Add method to get bytecode from a WasmFileHandler (#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Jan 26, 2024
1 parent 08d58f1 commit dfadf94
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

Unreleased
----------

Features:

* Add ``WasmFileHandler.bytecode()`` method to retrieve the WASM as bytecode.

1.24.0 (January 2024)
---------------------

Expand Down
6 changes: 4 additions & 2 deletions pytket/pytket/wasm/wasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def __init__(self, filepath: str, check_file: bool = True, int_size: int = 32):
self._unsupported_function = []

if self._check_file:

mod_iter = iter(decode_module(self._wasm_file))
_, _ = next(mod_iter)

Expand Down Expand Up @@ -143,7 +142,6 @@ def __init__(self, filepath: str, check_file: bool = True, int_size: int = 32):
self._function_types = cur_sec_data.payload.types

for x in function_names:

# check for only integer type in parameters and return values
supported_function = True
idx = _func_lookup[x][1]
Expand Down Expand Up @@ -214,6 +212,10 @@ def __repr__(self) -> str:
wasm file was checked"""
)

def bytecode(self) -> bytes:
"""The WASM content as bytecode"""
return self._wasm_file

def check_function(
self, function_name: str, number_of_parameters: int, number_of_returns: int
) -> bool:
Expand Down
4 changes: 4 additions & 0 deletions pytket/tests/classical_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ def test_wasm_2() -> None:
def test_wasm_3() -> None:
w = wasm.WasmFileHandler("testfile.wasm")

with open("testfile.wasm", "rb") as f:
bytecode = f.read()
assert w.bytecode() == bytecode

c = Circuit(0, 6)

c.add_wasm("add_one", w, [1], [1], [Bit(0), Bit(1)])
Expand Down

0 comments on commit dfadf94

Please sign in to comment.