コード例 #1
0
def test_lll_from_s_expression(get_contract_from_lll):
    code = """
(seq
  (return
    0
    (lll ; just return 32 byte of calldata back
      (seq
          (calldatacopy 0 4 32)
          (return 0 32)
          stop
        )
      0)))
    """
    abi = [{
        "name": "test",
        "outputs": [{
            "type": "int128",
            "name": "out"
        }],
        "inputs": [{
            "type": "int128",
            "name": "a"
        }],
        "constant": False,
        "payable": False,
        "type": "function",
        "gas": 394
    }]

    s_expressions = parse_s_exp(code)
    lll = LLLnode.from_list(s_expressions[0])
    c = get_contract_from_lll(lll, abi=abi)
    assert c.test(-123456) == -123456
コード例 #2
0
ファイル: vyper_lll.py プロジェクト: sambacha/vyper-xcode
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])
    if "ir" in output_formats:
        compiler_data["ir"] = lll

    if "opt_ir" in output_formats:
        compiler_data["opt_ir"] = optimizer.optimize(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