Exemplo n.º 1
0
def extended_format_RAISE_VARARGS(opc, instructions):
    raise_inst = instructions[0]
    assert raise_inst.opname == "RAISE_VARARGS"
    argc = raise_inst.argval
    if argc == 0:
        return "reraise"
    elif argc == 1:
        instance_arg = resolved_attrs(instructions[1:])
        if instance_arg:
            return "instance_arg"
    return format_RAISE_VARARGS(raise_inst.argval)
Exemplo n.º 2
0
def extended_format_CALL_FUNCTION(opc, instructions):
    """call_function_inst should be a "CALL_FUNCTION" instruction. Look in
    `instructions` to see if we can find a method name.  If not we'll
    return None.

    """
    # From opcode description: argc indicates the total number of positional and keyword arguments.
    # Sometimes the function name is in the stack arg positions back.
    call_function_inst = instructions[0]
    assert call_function_inst.opname == "CALL_FUNCTION"
    function_pos = call_function_inst.arg + 1
    assert len(instructions) >= function_pos
    s = ""
    for i, inst in enumerate(instructions[1:]):
        if i == function_pos:
            break
        if inst.is_jump_target:
            i += 1
            break
        # Make sure we are in the same basic block
        # and ... ?
        opcode = inst.opcode
        if inst.optype in ("nargs", "vargs"):
            break
        if inst.optype != "name":
            function_pos += (oppop[opcode] - oppush[opcode]) + 1
        if inst.opname in ("CALL_FUNCTION", "CALL_FUNCTION_KW"):
            break
        pass
    else:
        i += 1

    if i == function_pos:
        if instructions[function_pos].opname in ("LOAD_CONST", "LOAD_GLOBAL",
                                                 "LOAD_ATTR", "LOAD_NAME"):
            s = resolved_attrs(instructions[function_pos:])
            s += ": "
            pass
        pass
    s += format_CALL_FUNCTION(call_function_inst.arg)
    return s