def __compile(code, interface_codes=None, *args, **kwargs): ast = parser.parse_to_ast(code) lll = parser.parse_tree_to_lll(ast, code, interface_codes=interface_codes, runtime_only=kwargs.get( 'bytecode_runtime', False)) opt_lll = optimizer.optimize(lll) asm = compile_lll.compile_to_assembly(opt_lll) def find_nested_opcode(asm_list, key): if key in asm_list: return True else: sublists = [sub for sub in asm_list if isinstance(sub, list)] return any(find_nested_opcode(x, key) for x in sublists) if find_nested_opcode(asm, 'DEBUG'): print('Please note this code contains DEBUG opcode.') print( 'This will only work in a support EVM. This FAIL on any other nodes.' ) c, line_number_map = compile_lll.assembly_to_evm(asm) return c
def generate_lll_nodes( source_code: str, global_ctx: GlobalContext) -> Tuple[parser.LLLnode, parser.LLLnode]: """ Generate the intermediate representation (LLL) from the contextualized AST. This phase also includes LLL-level optimizations. This function returns two values, one for generating deployment bytecode and the other for generating runtime bytecode. The remaining compilation phases may be called with either value, depending on the desired final output. Arguments --------- source_code : str Vyper source code. global_ctx : GlobalContext Contextualized Vyper AST Returns ------- (LLLnode, LLLnode) LLL to generate deployment bytecode LLL to generate runtime bytecode """ lll_nodes, lll_runtime = parser.parse_tree_to_lll(source_code, global_ctx) lll_nodes = optimizer.optimize(lll_nodes) lll_runtime = optimizer.optimize(lll_runtime) return lll_nodes, lll_runtime
def compile(code, *args, **kwargs): lll = optimizer.optimize( parser.parse_tree_to_lll(parser.parse(code), code, runtime_only=kwargs.get( 'bytecode_runtime', False))) return compile_lll.assembly_to_evm(compile_lll.compile_to_assembly(lll))
def produce_source_map(code, interface_codes=None): global_ctx = GlobalContext.get_global_context( parser.parse_to_ast(code), interface_codes=interface_codes) asm_list = compile_lll.compile_to_assembly( optimizer.optimize( parse_to_lll(code, runtime_only=True, interface_codes=interface_codes))) c, line_number_map = compile_lll.assembly_to_evm(asm_list) source_map = { "globals": {}, "locals": {}, "line_number_map": line_number_map } source_map["globals"] = { name: serialise_var_rec(var_record) for name, var_record in global_ctx._globals.items() } # Fetch context for each function. lll = parser.parse_tree_to_lll( parser.parse_to_ast(code), code, interface_codes=interface_codes, runtime_only=True, ) contexts = { f.func_name: f.context for f in lll.args[1:] if hasattr(f, "context") } prev_func_name = None for _def in global_ctx._defs: if _def.name != "__init__": func_info = {"from_lineno": _def.lineno, "variables": {}} # set local variables for specific function. context = contexts[_def.name] func_info["variables"] = { var_name: serialise_var_rec(var_rec) for var_name, var_rec in context.vars.items() } source_map["locals"][_def.name] = func_info # set to_lineno if prev_func_name: source_map["locals"][prev_func_name]["to_lineno"] = _def.lineno prev_func_name = _def.name source_map["locals"][_def.name]["to_lineno"] = len(code.splitlines()) return source_map
def compile(code, *args, **kwargs): lll = optimizer.optimize(parser.parse_tree_to_lll(parser.parse(code), code, runtime_only=kwargs.get('bytecode_runtime', False))) asm = compile_lll.compile_to_assembly(lll) def find_nested_opcode(asm_list, key): if key in asm_list: return True else: sublists = [sub for sub in asm_list if isinstance(sub, list)] return any([find_nested_opcode(x, key) for x in sublists]) if find_nested_opcode(asm, 'DEBUG'): print('Please not this code contains DEBUG opcode.') print('This will only work in a support EVM. This FAIL on any other nodes.') return compile_lll.assembly_to_evm(asm)
def produce_source_map(code): global_ctx = GlobalContext.get_global_context(parser.parse_to_ast(code)) asm_list = compile_lll.compile_to_assembly( optimizer.optimize(parse_to_lll(code, runtime_only=True))) c, line_number_map = compile_lll.assembly_to_evm(asm_list) source_map = { 'globals': {}, 'locals': {}, 'line_number_map': line_number_map } source_map['globals'] = { name: serialise_var_rec(var_record) for name, var_record in global_ctx._globals.items() } # Fetch context for each function. lll = parser.parse_tree_to_lll(parser.parse_to_ast(code), code, runtime_only=True) contexts = { f.func_name: f.context for f in lll.args[1:] if hasattr(f, 'context') } prev_func_name = None for _def in global_ctx._defs: if _def.name != '__init__': func_info = {'from_lineno': _def.lineno, 'variables': {}} # set local variables for specific function. context = contexts[_def.name] func_info['variables'] = { var_name: serialise_var_rec(var_rec) for var_name, var_rec in context.vars.items() } source_map['locals'][_def.name] = func_info # set to_lineno if prev_func_name: source_map['locals'][prev_func_name]['to_lineno'] = _def.lineno prev_func_name = _def.name source_map['locals'][_def.name]['to_lineno'] = len(code.splitlines()) return source_map