def pykPrettyPrint(module): WASM_definition_llvm_no_coverage_dir = '.build/defn/llvm' WASM_definition_main_file = 'test' WASM_definition_llvm_no_coverage = pyk.readKastTerm( WASM_definition_llvm_no_coverage_dir + '/' + WASM_definition_main_file + '-kompiled/compiled.json') WASM_symbols_llvm_no_coverage = pyk.buildSymbolTable( WASM_definition_llvm_no_coverage) print(pyk.prettyPrintKast(module, WASM_symbols_llvm_no_coverage))
def _fromMapItem(mi): if pyk.isKApply(mi) and mi['label'] == '_|->_': return (mi['args'][0], mi['args'][1]) return None return flattenAssoc(m, 'Map', elemConverter=_fromMapItem) def kMapToDict(s, keyConvert=lambda x: x, valueConvert=lambda x: x): return {keyConvert(k): valueConvert(v) for (k, v) in flattenMap(s)} # Symbol Table (for Unparsing) # ---------------------------- MCD_definition_llvm_symbols = pyk.buildSymbolTable(MCD_definition_llvm) MCD_definition_llvm_symbols['_List_'] = lambda l1, l2: pyk.newLines([l1, l2]) MCD_definition_llvm_symbols['_Set_'] = lambda s1, s2: pyk.newLines([s1, s2]) MCD_definition_llvm_symbols['_Map_'] = lambda m1, m2: pyk.newLines([m1, m2]) MCD_definition_llvm_symbols[ '___KMCD-DRIVER_MCDSteps_MCDStep_MCDSteps'] = lambda s1, s2: pyk.newLines( [s1, s2]) def printMCD(k): return pyk.prettyPrintKast(k, MCD_definition_llvm_symbols) # Building KAST MCD Terms # -----------------------
def beacon_chain_symbols(backend): BEACON_CHAIN_definition = pyk.readKastTerm( '.build/defn/%s/beacon-chain-kompiled/compiled.json' % backend) return pyk.buildSymbolTable(BEACON_CHAIN_definition)
WASM_definition_main_file = 'kwasm-polkadot-host' WASM_definition_main_module = 'KWASM-POLKADOT-HOST' WASM_definition_llvm_no_coverage_dir = '.build/defn/kwasm/llvm' WASM_definition_llvm_coverage_dir = '.build/defn/coverage/llvm' WASM_definition_haskell_no_coverage_dir = '.build/defn/kwasm/haskell' WASM_definition_haskell_coverage_dir = '.build/defn/coverage/haskell' WASM_definition_llvm_no_coverage = pyk.readKastTerm(WASM_definition_llvm_no_coverage_dir + '/' + WASM_definition_main_file + '-kompiled/compiled.json') WASM_definition_llvm_coverage = pyk.readKastTerm(WASM_definition_llvm_coverage_dir + '/' + WASM_definition_main_file + '-kompiled/compiled.json') WASM_definition_haskell_no_coverage = pyk.readKastTerm(WASM_definition_haskell_no_coverage_dir + '/' + WASM_definition_main_file + '-kompiled/compiled.json') WASM_definition_haskell_coverage = pyk.readKastTerm(WASM_definition_haskell_coverage_dir + '/' + WASM_definition_main_file + '-kompiled/compiled.json') WASM_symbols_llvm_no_coverage = pyk.buildSymbolTable(WASM_definition_llvm_no_coverage) WASM_symbols_llvm_coverage = pyk.buildSymbolTable(WASM_definition_llvm_coverage) WASM_symbols_haskell_no_coverage = pyk.buildSymbolTable(WASM_definition_haskell_no_coverage) WASM_symbols_haskell_coverage = pyk.buildSymbolTable(WASM_definition_haskell_coverage) for symbolTable in [WASM_symbols_llvm_no_coverage, WASM_symbols_llvm_coverage, WASM_symbols_haskell_no_coverage, WASM_symbols_haskell_coverage]: symbolTable['#init_locals___WASM_Instr_Int_ValStack'] = lambda k, s: '#init_locals ' + k + ' ' + s symbolTable['init_locals__WASM_Instr_ValStack'] = lambda s: 'init_locals ' + s symbolTable['init_local___WASM_Instr_Val_ValStack'] = lambda k, v: 'init_local ' + k + ' ' + v symbolTable['#dotsLeft'] = lambda k: '... ' + k symbolTable['#dotsRight'] = lambda k: k + ' ...' symbolTable['#dotsBoth'] = lambda k: '... ' + k + ' ...' symbolTable['_in_keys(_)_MAP_Bool_KItem_Map'] = lambda k, s: k + ' in_keys( ' + s + ' )'
from pyk import KApply, KVariable, KToken input_file = sys.argv[1] definition = pyk.readKastTerm('deps/evm-semantics/.build/defn/java/driver-kompiled/compiled.json') with open(input_file) as f: input_json = json.load(f) gas_exp = input_json['args'][0] constraint = input_json['args'][1:] ite_label = '#if_#then_#else_#fi_K-EQUAL-SYNTAX' symbolTable = pyk.buildSymbolTable(definition) symbolTable['infGas'] = pyk.appliedLabelStr('#gas') symbolTable['notBool_'] = pyk.paren(pyk.underbarUnparsing('notBool_')) for label in ['+Int', '-Int', '*Int', '/Int', 'andBool', 'orBool']: symbolTable['_' + label + '_'] = pyk.paren(pyk.binOpStr(label)) def gatherConstInts(input, constants = [], non_constants = []): if pyk.isKApply(input) and input['label'] == '_+Int_': (c0, v0s) = gatherConstInts(input['args'][0]) (c1, v1s) = gatherConstInts(input['args'][1]) return (c0 + c1, v0s + v1s) elif pyk.isKToken(input) and input['sort'] == 'Int': return (int(input['token']), []) else: return (0, [input])