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 assertNum(): global _assertCounter _assertCounter = _assertCounter + 1 return _assertCounter # Definition Loading/Running # -------------------------- MCD_main_file_name = 'kmcd-prelude' MCD_definition_llvm_dir = '.build/defn/llvm' MCD_definition_llvm_kompiled = MCD_definition_llvm_dir + '/' + MCD_main_file_name + '-kompiled/compiled.json' MCD_definition_llvm = pyk.readKastTerm(MCD_definition_llvm_kompiled) def krun(inputJSON, *krunArgs): return pyk.krunJSON(MCD_definition_llvm_dir, inputJSON, krunArgs=list(krunArgs)) def randomSeedArgs(seedbytes=b''): return [ '-cRANDOMSEED=' + '#token("' + seedbytes.decode('latin-1') + '", "Bytes")', '-pRANDOMSEED=printf %s' ]
return merged_rules ################################################################################ # Load Definition Specific Stuff # ################################################################################ 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
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)
#!/usr/bin/env python3 import json import sys import pyk 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)
def run_tests(): global args testArgs = argparse.ArgumentParser(description='') testArgs.add_argument('files', metavar='N', type=str, nargs='+', help='') testArgs.add_argument('--coverage', action='store_true', help='Display test coverage data.') testArgs.add_argument('--log-level', choices=['none', 'per-file', 'per-step'], default='per-file') testArgs.add_argument('--verbose', action='store_true', help='') args = testArgs.parse_args() tests = args.files per_test_coverage = [] template_wasm_config = pyk.readKastTerm('src/elrond-runtime.loaded.json') cells = pyk.splitConfigFrom(template_wasm_config)[1] assert cells['K_CELL']['arity'] == 0 coverage = cov.Coverage() for test in tests: if args.verbose: print("Running test %s" % test) tmpdir = tempfile.mkdtemp(prefix="mandos_") if args.verbose: print("Intermediate test outputs stored in:\n%s" % tmpdir) initial_name = "0000_initial_config" with open('%s/%s' % (tmpdir, initial_name), 'w') as f: f.write(json.dumps(config_to_kast_term(template_wasm_config))) result_wasm_config = run_test_file(template_wasm_config, test, tmpdir, args) if args.coverage: end_config = result_wasm_config #pyk.readKastTerm(os.path.join(tmpdir, test_name)) collect_data_func = lambda entry: (int(entry['args'][0]['token']), int(entry['args'][1]['token'])) func_cov_filter_func = lambda term: 'label' in term and term[ 'label'] == 'fcd' func_cov = cov.get_coverage_data(end_config, 'COVEREDFUNCS_CELL', func_cov_filter_func, collect_data_func) block_cov_filter_func = lambda term: 'label' in term and term[ 'label'] == 'blockUid' block_cov = cov.get_coverage_data(end_config, 'COVEREDBLOCK_CELL', block_cov_filter_func, collect_data_func) mods = cov.get_module_filename_map(result_wasm_config) cov_data = { 'func_cov': func_cov, 'block_cov': block_cov, 'idx2file': mods } coverage.add_coverage(cov_data, unnamed='import') if args.verbose: print('See %s' % tmpdir) print() if args.coverage: text_modules = cov.insert_coverage_on_text_module( coverage, imports_mod_name='import') for module in text_modules: for line in module.splitlines(): print(line.decode('utf8'))
tail = KList_aux(lis[1:]) return KApply("_List_", [head, tail]) return KList_aux(list_items) def config_to_kast_term(config): return {'format': 'KAST', 'version': 1, 'term': config} ############################### WASM_definition_main_file = 'mandos' WASM_definition_llvm_no_coverage_dir = '.build/defn/llvm' WASM_definition_llvm_no_coverage_kompiled_dir = WASM_definition_llvm_no_coverage_dir + '/' + WASM_definition_main_file + '-kompiled' WASM_definition_llvm_no_coverage = pyk.readKastTerm( WASM_definition_llvm_no_coverage_kompiled_dir + '/compiled.json') WASM_symbols_llvm_no_coverage = pyk.buildSymbolTable( WASM_definition_llvm_no_coverage) addr_prefix = "address:" keccak_prefix = "keccak256:" u64_prefix = "u64:" u32_prefix = "u32:" u16_prefix = "u16:" u8_prefix = "u8:" biguint_prefix = "biguint:" sys.setrecursionlimit(1500000000) resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
else: print(stderr) _warning('Cannot merge rules!') return None ################################################################################ # Load Definition Specific Stuff # ################################################################################ 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-with-k-io-kompiled/compiled.json') WASM_definition_llvm_coverage = pyk.readKastTerm(WASM_definition_llvm_coverage_dir + '/wasm-with-k-io-kompiled/compiled.json') WASM_definition_haskell_no_coverage = pyk.readKastTerm(WASM_definition_haskell_no_coverage_dir + '/wasm-with-k-io-kompiled/compiled.json') WASM_definition_haskell_coverage = pyk.readKastTerm(WASM_definition_haskell_coverage_dir + '/wasm-with-k-io-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) # Custom unparsers for some symbols # WASM_symbols [ '.ValStack_WASM-DATA_' ] = pyk.constLabel('.ValStack') # WASM_symbols [ '.Int_WASM-DATA_' ] = pyk.constLabel('.Int') # WASM_symbols [ '.ModuleInstCellMap' ] = pyk.constLabel('.ModuleInstCellMap')