当前位置: 首页>>代码示例>>Python>>正文


Python dis.hasjabs方法代码示例

本文整理汇总了Python中dis.hasjabs方法的典型用法代码示例。如果您正苦于以下问题:Python dis.hasjabs方法的具体用法?Python dis.hasjabs怎么用?Python dis.hasjabs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dis的用法示例。


在下文中一共展示了dis.hasjabs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: apply_labels

# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasjabs [as 别名]
def apply_labels(self, start=None):
        '''
        Find all JMP REL and ABS bytecode sequences and update the target
        within branch instruction and add xref to the destination.
        '''
        for current in self.nodes(start):
            current.xrefs = []
            current.target = None

        for current in self.nodes(start):
            label = -1
            if current.opcode >= dis.HAVE_ARGUMENT:
                if current.opcode in dis.hasjrel:
                    label = current.addr+current.oparg+current.len()
                elif current.opcode in dis.hasjabs:
                    label = current.oparg

                if label >= 0:
                    if current not in self.bytecodes[label].xrefs:
                        self.bytecodes[label].xrefs.append(current)
                    current.target = self.bytecodes[label]
            current = current.next
        return 
开发者ID:fireeye,项目名称:flare-bytecode_graph,代码行数:25,代码来源:bytecode_graph.py

示例2: patch_opargs

# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasjabs [as 别名]
def patch_opargs(self, start=None):
        '''
        Updates branch instructions to correct offsets after adding or
        deleting bytecode
        '''
        for current in self.nodes(start):
            # No argument, skip to next
            if current.opcode < dis.HAVE_ARGUMENT:
                continue

            # Patch relative offsets
            if current.opcode in dis.hasjrel:
                current.oparg = current.target.addr - \
                                    (current.addr+current.len())

            # Patch absolute offsets
            elif current.opcode in dis.hasjabs:
                current.oparg = current.target.addr 
开发者ID:fireeye,项目名称:flare-bytecode_graph,代码行数:20,代码来源:bytecode_graph.py

示例3: flattenGraph

# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasjabs [as 别名]
def flattenGraph(self):
        """Arrange the blocks in order and resolve jumps"""
        assert self.stage == RAW
        self.insts = insts = []
        pc = 0
        begin = {}
        end = {}
        for b in self.getBlocksInOrder():
            begin[b] = pc
            for inst in b.getInstructions():
                insts.append(inst)
                if len(inst) == 1:
                    pc = pc + 1
                elif inst[0] != "SET_LINENO":
                    # arg takes 2 bytes
                    pc = pc + 3
            end[b] = pc
        pc = 0
        for i in range(len(insts)):
            inst = insts[i]
            if len(inst) == 1:
                pc = pc + 1
            elif inst[0] != "SET_LINENO":
                pc = pc + 3
            opname = inst[0]
            if opname in self.hasjrel:
                oparg = inst[1]
                offset = begin[oparg] - pc
                insts[i] = opname, offset
            elif opname in self.hasjabs:
                insts[i] = opname, begin[inst[1]]
        self.stage = FLAT 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:34,代码来源:pyassem.py

示例4: jump

# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasjabs [as 别名]
def jump(self, op, arg=None):
        def jump_target(offset):
            target = offset
            if op not in hasjabs:
                target = target - (posn + 3)
                if target < 0:
                    raise AssertionError("Relative jumps can't go backwards")
                if target > 0xFFFF:
                    target = offset - (posn + 6)
            return target

        def backpatch(offset):
            target = jump_target(offset)
            if target > 0xFFFF:
                raise AssertionError("Forward jump span must be <64K bytes")
            self.patch_arg(posn, 0, target)
            self.branch_stack(offset, old_level)

        if op == FOR_ITER:
            old_level = self.stack_size = self.stack_size - 1
            self.stack_size += 2
        else:
            old_level = self.stack_size
        self.stack_size -= (op in (JUMP_IF_TRUE_OR_POP, JUMP_IF_FALSE_OR_POP))
        posn = self.here()
        if arg is not None:
            self.emit_arg(op, jump_target(arg))
            self.branch_stack(arg, old_level)
            lbl = None
        else:
            self.emit_arg(op, 0)

            def lbl(code=None):
                backpatch(self.here())
        if op in (JUMP_FORWARD, JUMP_ABSOLUTE, CONTINUE_LOOP):
            self.stack_unknown()
        return lbl 
开发者ID:openstack,项目名称:monasca-analytics,代码行数:39,代码来源:assembler.py

示例5: jump

# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasjabs [as 别名]
def jump(self):
        opcode = self.opcode
        if opcode in dis.hasjrel:
            return self[1] + self.arg
        elif opcode in dis.hasjabs:
            return self.code.address(self.arg) 
开发者ID:figment,项目名称:unpyc3,代码行数:8,代码来源:unpyc3.py

示例6: get_target_addr

# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasjabs [as 别名]
def get_target_addr(self):
        '''
        Returns the target address for the current instruction based on the
        current address.
        '''
        rvalue = None
        if self.opcode in dis.hasjrel:
            rvalue = self.addr + self.oparg + self.len()
        if self.opcode in dis.hasjabs:
            rvalue = self.oparg

        return rvalue 
开发者ID:fireeye,项目名称:flare-bytecode_graph,代码行数:14,代码来源:bytecode_graph.py

示例7: flattenGraph

# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasjabs [as 别名]
def flattenGraph(self):
        """Arrange the blocks in order and resolve jumps"""
        assert self.stage == RAW
        self.insts = insts = []
        pc = 0
        begin = {}
        end = {}
        for b in self.getBlocksInOrder():
            begin[b] = pc
            for inst in b.getInstructions():
                insts.append(inst)
                if len(inst) == 1:
                    pc = pc + 1
                elif inst[0] != "SET_LINENO":
                    # arg takes 2 bytes
                    pc = pc + 3
            end[b] = pc
        pc = 0
        for i in range(len(insts)):
            inst = insts[i]
            if len(inst) == 1:
                pc = pc + 1
            elif inst[0] != "SET_LINENO":
                pc = pc + 3
            opname = inst[0]
            if self.hasjrel.has_elt(opname):
                oparg = inst[1]
                offset = begin[oparg] - pc
                insts[i] = opname, offset
            elif self.hasjabs.has_elt(opname):
                insts[i] = opname, begin[inst[1]]
        self.stage = FLAT 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:34,代码来源:pyassem.py

示例8: _update_label_offsets

# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasjabs [as 别名]
def _update_label_offsets(code_obj, breakpoint_offset, breakpoint_code_list):
    """
    Update labels for the relative and absolute jump targets
    :param code_obj: code to modify
    :param breakpoint_offset: offset for the inserted code
    :param breakpoint_code_list: size of the inserted code
    :return: bytes sequence with modified labels; list of tuples (resulting offset, list of code instructions) with
    information about all inserted pieces of code
    """
    inserted_code = list()
    # the list with all inserted pieces of code
    inserted_code.append((breakpoint_offset, breakpoint_code_list))
    code_list = list(code_obj)
    j = 0

    while j < len(inserted_code):
        current_offset, current_code_list = inserted_code[j]
        offsets_for_modification = []

        for offset, op, arg in _unpack_opargs(code_list, inserted_code, j):
            if arg is not None:
                if op in dis.hasjrel:
                    # has relative jump target
                    label = offset + 2 + arg
                    if offset < current_offset < label:
                        # change labels for relative jump targets if code was inserted inside
                        offsets_for_modification.append(offset)
                elif op in dis.hasjabs:
                    # change label for absolute jump if code was inserted before it
                    if current_offset < arg:
                        offsets_for_modification.append(offset)
        for i in range(0, len(code_list), 2):
            op = code_list[i]
            if i in offsets_for_modification and op >= dis.HAVE_ARGUMENT:
                new_arg = code_list[i + 1] + len(current_code_list)
                if new_arg <= MAX_BYTE:
                    code_list[i + 1] = new_arg
                else:
                    # handle bytes overflow
                    if i - 2 > 0 and code_list[i - 2] == EXTENDED_ARG and code_list[i - 1] < MAX_BYTE:
                        # if new argument > 255 and EXTENDED_ARG already exists we need to increase it's argument
                        code_list[i - 1] += 1
                    else:
                        # if there isn't EXTENDED_ARG operator yet we have to insert the new operator
                        extended_arg_code = [EXTENDED_ARG, new_arg >> 8]
                        inserted_code.append((i, extended_arg_code))
                    code_list[i + 1] = new_arg & MAX_BYTE

        code_list = code_list[:current_offset] + current_code_list + code_list[current_offset:]

        for k in range(len(inserted_code)):
            offset, inserted_code_list = inserted_code[k]
            if current_offset < offset:
                inserted_code[k] = (offset + len(current_code_list), inserted_code_list)
        j += 1

    return bytes(code_list), inserted_code 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:59,代码来源:pydevd_modify_bytecode.py


注:本文中的dis.hasjabs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。