def lll_compiler(lll, *args, **kwargs): lll = optimizer.optimize(LLLnode.from_list(lll)) bytecode, _ = compile_lll.assembly_to_evm(compile_lll.compile_to_assembly(lll)) abi = kwargs.get("abi") or [] c = w3.eth.contract(abi=abi, bytecode=bytecode) deploy_transaction = c.constructor() tx_hash = deploy_transaction.transact() address = w3.eth.getTransactionReceipt(tx_hash)["contractAddress"] contract = w3.eth.contract( address, abi=abi, bytecode=bytecode, ContractFactoryClass=VyperContract, ) return contract
def generate_bytecode(assembly: list) -> bytes: """ Generate bytecode from assembly instructions. Arguments --------- assembly : list Assembly instructions. Can be deployment or runtime assembly. Returns ------- bytes Final compiled bytecode. """ return compile_lll.assembly_to_evm(assembly)[0]
def build_source_map_output(compiler_data: CompilerData) -> OrderedDict: _, line_number_map = compile_lll.assembly_to_evm( compiler_data.assembly_runtime) # Sort line_number_map out = OrderedDict() for k in sorted(line_number_map.keys()): out[k] = line_number_map[k] out["pc_pos_map_compressed"] = _compress_source_map( compiler_data.source_code, out["pc_pos_map"], out["pc_jump_map"], compiler_data.source_id, ) out["pc_pos_map"] = dict((k, v) for k, v in out["pc_pos_map"].items() if v) return out
def compile_to_lll(input_file, output_formats, show_gas_estimates=False): with open(input_file) as fh: s_expressions = parse_s_exp(fh.read()) if show_gas_estimates: LLLnode.repr_show_gas = True compiler_data = {} lll = LLLnode.from_list(s_expressions[0]) lll = optimizer.optimize(lll) if "ir" in output_formats: compiler_data["ir"] = lll asm = compile_lll.compile_to_assembly(lll) if "asm" in output_formats: compiler_data["asm"] = asm if "bytecode" in output_formats: (bytecode, _srcmap) = compile_lll.assembly_to_evm(asm) compiler_data["bytecode"] = "0x" + bytecode.hex() return compiler_data
def test_pc_debugger(): debugger_lll = ["seq", ["mstore", 0, 32], ["pc_debugger"]] lll_nodes = LLLnode.from_list(debugger_lll) _, line_number_map = compile_lll.assembly_to_evm( compile_lll.compile_to_assembly(lll_nodes)) assert line_number_map["pc_breakpoints"][0] == 5