示例#1
0
    def __call__(s, m):
        """ generate RTLIR for all upblks of m """
        if not hasattr(m, '_pass_behavioral_rtlir_gen'):
            m._pass_behavioral_rtlir_gen = PassMetadata()
        m._pass_behavioral_rtlir_gen.rtlir_upblks = {}
        visitor = BehavioralRTLIRGeneratorL3(m)

        upblks = {
            'CombUpblk': get_ordered_upblks(m),
            'SeqUpblk': get_ordered_update_ff(m),
        }
        # Sort the upblks by their name
        upblks['CombUpblk'].sort(key=lambda x: x.__name__)
        upblks['SeqUpblk'].sort(key=lambda x: x.__name__)

        for upblk_type in ('CombUpblk', 'SeqUpblk'):
            for blk in upblks[upblk_type]:
                visitor._upblk_type = upblk_type
                upblk_info = m.get_update_block_info(blk)
                upblk = visitor.enter(blk, upblk_info[-1])
                upblk.is_lambda = upblk_info[0]
                upblk.src = upblk_info[1]
                upblk.lino = upblk_info[2]
                upblk.filename = upblk_info[3]
                m._pass_behavioral_rtlir_gen.rtlir_upblks[blk] = upblk
示例#2
0
    def __call__(s, m):
        """Generate RTLIR for all upblks of m."""
        c = s.__class__

        if m.has_metadata(c.rtlir_upblks):
            rtlir_upblks = m.get_metadata(c.rtlir_upblks)
        else:
            rtlir_upblks = {}
            m.set_metadata(c.rtlir_upblks, rtlir_upblks)

        visitor = s.get_rtlir_generator_class()(m)
        upblks = {
            bir.CombUpblk: get_ordered_upblks(m),
            bir.SeqUpblk: get_ordered_update_ff(m),
        }
        # Sort the upblks by their name
        upblks[bir.CombUpblk].sort(key=lambda x: x.__name__)
        upblks[bir.SeqUpblk].sort(key=lambda x: x.__name__)

        for upblk_type in (bir.CombUpblk, bir.SeqUpblk):
            for blk in upblks[upblk_type]:
                visitor._upblk_type = upblk_type
                upblk_info = m.get_update_block_info(blk)
                upblk = visitor.enter(blk, upblk_info[-1])
                upblk.is_lambda = upblk_info[0]
                upblk.src = upblk_info[1]
                upblk.lino = upblk_info[2]
                upblk.filename = upblk_info[3]
                rtlir_upblks[blk] = upblk
示例#3
0
    def translate_behavioral(s, m):
        """Translate behavioral part of `m`."""
        # Get upblk metadata
        s.behavioral.accessed[
            m] = m._pass_behavioral_rtlir_type_check.rtlir_accessed
        # Translate upblks
        upblk_decls = []
        upblk_srcs = []
        upblk_py_srcs = []
        upblks = {
            'CombUpblk': get_ordered_upblks(m),
            'SeqUpblk': get_ordered_update_ff(m),
        }
        # Sort the upblks by their name
        upblks['CombUpblk'].sort(key=lambda x: x.__name__)
        upblks['SeqUpblk'].sort(key=lambda x: x.__name__)

        for upblk_type in ('CombUpblk', 'SeqUpblk'):
            for blk in upblks[upblk_type]:
                upblk_ir = s.behavioral.rtlir[m][blk]
                upblk_srcs.append(s.rtlir_tr_upblk_src(blk, upblk_ir))
                upblk_py_srcs.append(
                    s.rtlir_tr_upblk_py_src(blk, upblk_ir.is_lambda,
                                            upblk_ir.src, upblk_ir.lino,
                                            upblk_ir.filename))
                upblk_decls.append(
                    s.rtlir_tr_upblk_decl(blk, upblk_srcs[-1],
                                          upblk_py_srcs[-1]))
        s.behavioral.upblk_srcs[m] = s.rtlir_tr_upblk_srcs(upblk_srcs)
        s.behavioral.upblk_py_srcs[m] = s.rtlir_tr_upblk_decls(upblk_py_srcs)
        s.behavioral.upblk_decls[m] = s.rtlir_tr_upblk_decls(upblk_decls)

        # Generate free variable declarations
        freevars = []
        for name, fvar in s.behavioral.freevars[m].items():
            rtype = rt.get_rtlir(fvar)
            if isinstance(rtype, rt.Array):
                fvar_rtype = rtype.get_sub_type()
                array_rtype = rtype
            else:
                fvar_rtype = rtype
                array_rtype = None
            dtype = fvar_rtype.get_dtype()
            assert isinstance( dtype, rdt.Vector ), \
              f'{name} freevar should be an integer or a list of integers!'
            freevars.append(
                s.rtlir_tr_behavioral_freevar(
                    name, fvar_rtype,
                    s.rtlir_tr_unpacked_array_type(array_rtype),
                    s.rtlir_tr_vector_dtype(dtype), fvar))
        s.behavioral.decl_freevars[m] = s.rtlir_tr_behavioral_freevars(
            freevars)
示例#4
0
  def translate_behavioral( s, m ):
    """Translate behavioral part of `m`."""
    # Get upblk metadata
    s.behavioral.accessed[m] = \
        m.get_metadata( BehavioralRTLIRTypeCheckL1Pass.rtlir_accessed )
    # Translate upblks
    upblk_decls = []
    upblk_srcs = []
    upblk_py_srcs = []
    upblks = {
      'CombUpblk' : get_ordered_upblks(m),
      'SeqUpblk'  : get_ordered_update_ff(m),
    }
    # Sort the upblks by their name
    upblks['CombUpblk'].sort( key = lambda x: x.__name__ )
    upblks['SeqUpblk'].sort( key = lambda x: x.__name__ )

    for upblk_type in ( 'CombUpblk', 'SeqUpblk' ):
      for blk in upblks[ upblk_type ]:
        upblk_ir = s.behavioral.rtlir[ m ][ blk ]
        upblk_srcs.append( s.rtlir_tr_upblk_src(
          blk, upblk_ir
        ) )
        upblk_py_srcs.append( s.rtlir_tr_upblk_py_src(
          blk,
          upblk_ir.is_lambda,
          upblk_ir.src,
          upblk_ir.lino,
          upblk_ir.filename
        ) )
        upblk_decls.append( s.rtlir_tr_upblk_decl(
          blk, upblk_srcs[-1], upblk_py_srcs[-1]
        ) )
    s.behavioral.upblk_srcs[m] = s.rtlir_tr_upblk_srcs( upblk_srcs )
    s.behavioral.upblk_py_srcs[m] = s.rtlir_tr_upblk_decls( upblk_py_srcs )
    s.behavioral.upblk_decls[m] = s.rtlir_tr_upblk_decls( upblk_decls )

    # Generate free variable declarations
    freevars = []
    for name, (fvar, rtype) in s.behavioral.freevars[m].items():
      freevars.append( s.translate_freevar( name, fvar, rtype ) )
    s.behavioral.decl_freevars[m] = s.rtlir_tr_behavioral_freevars(freevars)