Home | History | Annotate | Download | only in Compiler
      1 cimport cython
      2 
      3 from Cython.Compiler.Visitor cimport CythonTransform, TreeVisitor
      4 
      5 cdef class ControlBlock:
      6      cdef public set children
      7      cdef public set parents
      8      cdef public set positions
      9      cdef public list stats
     10      cdef public dict gen
     11      cdef public set bounded
     12      cdef public dict input
     13      cdef public dict output
     14 
     15      # Big integer it bitsets
     16      cdef public object i_input
     17      cdef public object i_output
     18      cdef public object i_gen
     19      cdef public object i_kill
     20      cdef public object i_state
     21 
     22      cpdef bint empty(self)
     23      cpdef detach(self)
     24      cpdef add_child(self, block)
     25 
     26 cdef class ExitBlock(ControlBlock):
     27      cpdef bint empty(self)
     28 
     29 cdef class NameAssignment:
     30     cdef public bint is_arg
     31     cdef public bint is_deletion
     32     cdef public object lhs
     33     cdef public object rhs
     34     cdef public object entry
     35     cdef public object pos
     36     cdef public set refs
     37     cdef public object bit
     38     cdef public object inferred_type
     39 
     40 cdef class AssignmentList:
     41     cdef public object bit
     42     cdef public object mask
     43     cdef public list stats
     44 
     45 cdef class AssignmentCollector(TreeVisitor):
     46     cdef list assignments
     47 
     48 @cython.final
     49 cdef class ControlFlow:
     50      cdef public set blocks
     51      cdef public set entries
     52      cdef public list loops
     53      cdef public list exceptions
     54 
     55      cdef public ControlBlock entry_point
     56      cdef public ExitBlock exit_point
     57      cdef public ControlBlock block
     58 
     59      cdef public dict assmts
     60 
     61      cpdef newblock(self, ControlBlock parent=*)
     62      cpdef nextblock(self, ControlBlock parent=*)
     63      cpdef bint is_tracked(self, entry)
     64      cpdef bint is_statically_assigned(self, entry)
     65      cpdef mark_position(self, node)
     66      cpdef mark_assignment(self, lhs, rhs, entry)
     67      cpdef mark_argument(self, lhs, rhs, entry)
     68      cpdef mark_deletion(self, node, entry)
     69      cpdef mark_reference(self, node, entry)
     70 
     71      @cython.locals(block=ControlBlock, parent=ControlBlock, unreachable=set)
     72      cpdef normalize(self)
     73 
     74      @cython.locals(bit=object, assmts=AssignmentList,
     75                     block=ControlBlock)
     76      cpdef initialize(self)
     77 
     78      @cython.locals(assmts=AssignmentList, assmt=NameAssignment)
     79      cpdef set map_one(self, istate, entry)
     80 
     81      @cython.locals(block=ControlBlock, parent=ControlBlock)
     82      cdef reaching_definitions(self)
     83 
     84 cdef class Uninitialized:
     85      pass
     86 
     87 cdef class Unknown:
     88     pass
     89 
     90 @cython.locals(dirty=bint, block=ControlBlock, parent=ControlBlock,
     91                assmt=NameAssignment)
     92 cdef check_definitions(ControlFlow flow, dict compiler_directives)
     93 
     94 @cython.final
     95 cdef class ControlFlowAnalysis(CythonTransform):
     96     cdef object gv_ctx
     97     cdef set reductions
     98     cdef list env_stack
     99     cdef list stack
    100     cdef object env
    101     cdef ControlFlow flow
    102     cdef bint in_inplace_assignment
    103 
    104     cpdef mark_assignment(self, lhs, rhs=*)
    105     cpdef mark_position(self, node)
    106