Beispiel #1
0
def connect_instance_port_names_to_module_port_names(
        parent_module, gbl, list_of_named_port_connections, mod_inst 
    ) :
    for (port_i, expr) in list_of_named_port_connections:
        print port_i,"=>",expr

    for (port_i, expr) in list_of_named_port_connections:

        # first, check the named ports exist in the new instance.
        port_name = port_i[1]  # port_i[0] = 'port_identifier'

        sig = mod_inst.get_named_signal_from_scope(port_name)
        if not sig: return False

        # fixme - check port directions are compatible
        assert sig.is_port

        if sig.port_dir == 'in':  # create code for: assign port = <expr>
            print "Input Port is same as: assign %s = %s" % (sig.hier_name, str(expr[1:]) )

            expr_code, sigs = Code.code_eval_expression(parent_module, gbl, expr[1:])
            #print "expr_code=",expr_code,"   sigs in expr=",
            #for s in sigs: print s.hier_name,
            #print 

            # make the port name look like a net_identifier lvalue
            wire    = port_i[:]
            wire[0] = 'net_identifier'
            lvalue  = [ 'net_lvalue', wire ]
            
            # create code to assign the expr to the lvalue (port)
            code = Code.code_assign_expr_code_to_lvalue( mod_inst, gbl, lvalue, expr_code)

            print "Code=",code
            
            # Add event for initial assignment.
            simcode = gbl.create_and_add_code_to_events( code, 0, 'active_list' )

            # Now we need to add the lvalue to the dependency list of all
            # signals in the expression (in sigs). In practice we need to recompute
            # the expression if any of the signals change. But we already have the
            # simcode to do that - we just need to invoke it when needed.

            if sigs: add_dependent_simcode_to_signals( simcode, sigs )

        else: # sig port is output
            print "Output Port is same as:assign %s = %s" % (str(expr[1:]), sig.hier_name )

            # Create code to evaluate (look up) the value of the child module's signal.
            # First, make signal look like an expression.
            sig_expr = [ 'net_identifier', sig.local_name ]

            expr_code, sigs = Code.code_eval_expression(mod_inst, gbl, sig_expr)

            # Make the expr[1] look like an lvalue
            lvalue  = [ 'net_lvalue', expr[1:] ]
            
            print "lvalue is", str(lvalue), "\ncode to eval sig is",expr_code

            # create code to assign the expr to the lvalue (port)
            code = Code.code_assign_expr_code_to_lvalue( parent_module, gbl, lvalue, expr_code)

            print "Code=",code

            # Add event for initial assignment.
            simcode = gbl.create_and_add_code_to_events( code, 0, 'active_list' )

            # Now we need to invoke code whenever the child signal value changes.
            assert sigs # Must be exactly one.
            add_dependent_simcode_to_signals( simcode, sigs )
           
    return True