Skip to content

Commit

Permalink
cache current_module
Browse files Browse the repository at this point in the history
  • Loading branch information
bbyalcinkaya committed Oct 27, 2023
1 parent da0ad0f commit f6e0cd8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions kmxwasm/src/kmxwasm/property_testing/wasm_krun_initializer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from sys import getsizeof

from pyk.cterm import CTerm
from pyk.kast.inner import KApply, KInner, KSequence, KToken
from pyk.kcfg import KCFG
Expand Down Expand Up @@ -33,7 +35,7 @@ class WasmKrunInitializer:
def __init__(self, tools: Tools):
self.__tools = tools
self.__first_wasm_cell: KInner | None = None
self.__cache: dict[str, KInner] = {}
self.__cache: dict[str, tuple[KInner, KInner]] = {} # address -> (<wasm>, <contractModIdx>)

def initialize(self, kcfg: KCFG, start_node: KCFG.Node) -> None:
start_cell = start_node.cterm.config
Expand All @@ -46,18 +48,18 @@ def initialize(self, kcfg: KCFG, start_node: KCFG.Node) -> None:
acct_address = first.args[0].token

if acct_address in self.__cache:
print('*' * 30, 'Reading WASM from cache.')
wasm_cell = self.__cache[acct_address]
print('*' * 30, 'Reading WASM from cache:', acct_address)
wasm_cell, current_module = self.__cache[acct_address]
else:
krun_cell = self.__prepare_krun_cell(start_cell, first)
print('*' * 30, 'Initializing WASM.')
print('*' * 30, 'Initializing WASM:', acct_address)
krun_result = self.__tools.krun(krun_cell)

wasm_cell = get_wasm_cell(krun_result)
self.__cache[acct_address] = wasm_cell
current_module = get_contract_mod_idx_cell(krun_result)
self.__cache[acct_address] = (wasm_cell, current_module)

final_cell = replace_wasm_cell(start_cell, wasm_cell)
current_module = get_contract_mod_idx_cell(krun_result)
final_cell = replace_contract_mod_idx_cell(final_cell, current_module)
final_cell = set_commands_cell_contents(final_cell, KSequence(commands_contents.items[1:]))

Expand Down

0 comments on commit f6e0cd8

Please sign in to comment.