Esempio n. 1
0
        end_while_id = self.new_id('end_while')
        self.reset_block_name(branch_index, end_while_id)

        self.current_block.setup_loop_break_target(branch_index)
        return ACTION_PROCESS_NEXT_OPCODE

    def opcode_break_loop(self, oparg):
        """Break loop jumps to the target previously defined by the setup_loop
        opcode. This is deduced by execution flow analysis once all blocks
        have been proceceed.
        So at this time, we just mark the current block as a "loop ending"
        block to which the branching instruction will be appended once
        the matching setup_loop has been identified.
        Related opcodes: setup_loop, pop_block.
        """
        self.current_block.ends_with_loop_break()
        self.pending_break_jump_blocks.append(self.current_block)
        return ACTION_BRANCH

    def opcode_pop_block(self, oparg):
        """Opcodes executed when a while loop ends without break.
           In CPython, this pop the "setup_loop" context from a stack.
           For flow analysis, the current block is marked as ending a while loop,
           so that nested while loop are handled correctly.
        """
        self.current_block.ends_loop()
        return ACTION_PROCESS_NEXT_OPCODE

CODE_GENERATOR_OPCODE_FUNCTIONS = make_opcode_functions_map(
    FunctionCodeGenerator)
Esempio n. 2
0
        branch_index = oparg + self.next_instr_index
        end_while_id = self.new_id( 'end_while' )
        self.reset_block_name( branch_index, end_while_id )

        self.current_block.setup_loop_break_target( branch_index )
        return ACTION_PROCESS_NEXT_OPCODE

    def opcode_break_loop( self, oparg ):
        """Break loop jumps to the target previously defined by the setup_loop
        opcode. This is deduced by execution flow analysis once all blocks
        have been proceceed.
        So at this time, we just mark the current block as a "loop ending"
        block to which the branching instruction will be appended once
        the matching setup_loop has been identified.
        Related opcodes: setup_loop, pop_block.
        """
        self.current_block.ends_with_loop_break()
        self.pending_break_jump_blocks.append( self.current_block )
        return ACTION_BRANCH

    def opcode_pop_block( self, oparg ):
        """Opcodes executed when a while loop ends without break.
           In CPython, this pop the "setup_loop" context from a stack.
           For flow analysis, the current block is marked as ending a while loop,
           so that nested while loop are handled correctly.
        """
        self.current_block.ends_loop()
        return ACTION_PROCESS_NEXT_OPCODE
                
CODE_GENERATOR_OPCODE_FUNCTIONS = make_opcode_functions_map( FunctionCodeGenerator )
Esempio n. 3
0
    def opcode_compare_op(self, oparg):
        cmp_types = self.pop_types(2)
        opcode_location = self.get_opcode_location()
        self.push_type(rtypes.BoolType(location=opcode_location))
        return -1

    def opcode_pop_jump_if_false(self, oparg):
        return -1

    def opcode_dup_top(self, oparg):
        # Duplicate the top value on the stack
        r_type = self.pop_type()
        self.push_type(r_type)
        self.push_type(r_type)
        return -1

    def opcode_rot_two(self, oparg):
        # Swap the two top value on the stack
        r_type_v = self.pop_type()
        r_type_w = self.pop_type()
        self.push_type(r_type_v)
        self.push_type(r_type_w)
        return -1


FUNCTION_SCANNER_OPCODE_FUNCTIONS = make_opcode_functions_map(FunctionScanner)

if __name__ == '__main__':
    pass
Esempio n. 4
0
        cmp_types = self.pop_types( 2 )
        opcode_location = self.get_opcode_location()
        self.push_type( rtypes.BoolType( location=opcode_location ) )
        return -1

    def opcode_pop_jump_if_false( self, oparg ):
        return -1

    def opcode_dup_top( self, oparg ):
        # Duplicate the top value on the stack
        r_type = self.pop_type()
        self.push_type( r_type )
        self.push_type( r_type )
        return -1

    def opcode_rot_two( self, oparg ):
        # Swap the two top value on the stack
        r_type_v = self.pop_type()
        r_type_w = self.pop_type()
        self.push_type( r_type_v )
        self.push_type( r_type_w )
        return -1
        

                
FUNCTION_SCANNER_OPCODE_FUNCTIONS = make_opcode_functions_map( FunctionScanner )
            
            
if __name__ == '__main__':
    pass
Esempio n. 5
0
        attribute_type = self.pop_type()
        print( 'Storing attribute %s of type %r' % (attribute_name, attribute_type) )
        self_type.record_attribute_type( attribute_name, attribute_type )
        return -1

    def opcode_pop_top( self, oparg ):
        self.pop_type()
        return -1

    def opcode_return_value( self, oparg ):
        return_type = self.pop_type()
        self.r_func_type.record_return_type( return_type )
        return -1

    def opcode_compare_op( self, oparg ):
        cmp_types = self.pop_types( 2 )
        opcode_location = self.get_opcode_location()
        self.push_type( rtypes.BoolType( location=opcode_location ) )
        return -1

    def opcode_pop_jump_if_false( self, oparg ):
        return -1
        

                
TYPE_ANNOTATOR_OPCODE_FUNCTIONS = make_opcode_functions_map( TypeAnnotator )
            
            
if __name__ == '__main__':
    pass
Esempio n. 6
0
        self_type = self.pop_type()
        attribute_type = self.pop_type()
        print('Storing attribute %s of type %r' %
              (attribute_name, attribute_type))
        self_type.record_attribute_type(attribute_name, attribute_type)
        return -1

    def opcode_pop_top(self, oparg):
        self.pop_type()
        return -1

    def opcode_return_value(self, oparg):
        return_type = self.pop_type()
        self.r_func_type.record_return_type(return_type)
        return -1

    def opcode_compare_op(self, oparg):
        cmp_types = self.pop_types(2)
        opcode_location = self.get_opcode_location()
        self.push_type(rtypes.BoolType(location=opcode_location))
        return -1

    def opcode_pop_jump_if_false(self, oparg):
        return -1


TYPE_ANNOTATOR_OPCODE_FUNCTIONS = make_opcode_functions_map(TypeAnnotator)

if __name__ == '__main__':
    pass