コード例 #1
0
ファイル: test_transform.py プロジェクト: UCSBarchlab/PyRTL
    def test_replace_input(self):
        def f(wire):
            if wire.name == 'a':
                w = pyrtl.clone_wire(wire, 'w2')
            else:
                w = pyrtl.clone_wire(wire, 'w3')
            return wire, w

        a, b = pyrtl.input_list('a/1 b/1')
        w1 = a & b
        o = pyrtl.Output(1, 'o')
        o <<= w1

        src_nets, dst_nets = pyrtl.working_block().net_connections()
        self.assertEqual(src_nets[w1], pyrtl.LogicNet('&', None, (a, b),
                                                      (w1, )))
        self.assertIn(a, dst_nets)
        self.assertIn(b, dst_nets)

        transform.wire_transform(f,
                                 select_types=pyrtl.Input,
                                 exclude_types=tuple())

        w2 = pyrtl.working_block().get_wirevector_by_name('w2')
        w3 = pyrtl.working_block().get_wirevector_by_name('w3')
        src_nets, dst_nets = pyrtl.working_block().net_connections()
        self.assertEqual(src_nets[w1],
                         pyrtl.LogicNet('&', None, (w2, w3), (w1, )))
        self.assertNotIn(a, dst_nets)
        self.assertNotIn(b, dst_nets)
コード例 #2
0
def insert_random_inversions(rate=0.5):
    import random

    def randomly_replace(wire):
        if random.random() < rate:
            new_src, new_dst = transform.clone_wire(wire), transform.clone_wire(wire)
            new_dst <<= ~new_src
            return new_src, new_dst
        return wire, wire

    transform.wire_transform(randomly_replace)
コード例 #3
0
def insert_random_inversions(rate=0.5):
    import random

    def randomly_replace(wire):
        if random.random() < rate:
            new_src, new_dst = transform.clone_wire(
                wire), transform.clone_wire(wire)
            new_dst <<= ~new_src
            return new_src, new_dst
        return wire, wire

    transform.wire_transform(randomly_replace)
コード例 #4
0
def probe_wire_if(condition_func):
    """

    :param condition_func: (logic net) -> bool
    :return:
    """
    def add_probe_if(wire):
        if condition_func(wire):
            pyrtl.probe(wire)
        return wire, wire

    transform.wire_transform(add_probe_if)
コード例 #5
0
def probe_wire_if(condition_func):
    """

    :param condition_func: (logic net) -> bool
    :return:
    """

    def add_probe_if(wire):
        if condition_func(wire):
            pyrtl.probe(wire)
        return wire, wire

    transform.wire_transform(add_probe_if)
コード例 #6
0
def insert_random_inversions(rate=0.5):
    """
    an example transform that can be used for testing
    """

    import random

    def randomly_replace(wire):
        if random.random() < rate:
            new_src, new_dst = transform.clone_wire(wire), transform.clone_wire(wire)
            new_dst <<= ~new_src
            return new_src, new_dst
        return wire, wire

    transform.wire_transform(randomly_replace)
コード例 #7
0
def insert_random_inversions(rate=0.5):
    """
    an example transform that can be used for testing
    """

    import random

    def randomly_replace(wire):
        if random.random() < rate:
            new_src, new_dst = transform.clone_wire(
                wire), transform.clone_wire(wire)
            new_dst <<= ~new_src
            return new_src, new_dst
        return wire, wire

    transform.wire_transform(randomly_replace)
コード例 #8
0
ファイル: test_transform.py プロジェクト: UCSBarchlab/PyRTL
    def test_replace_output(self):
        def f(wire):
            w = pyrtl.clone_wire(wire, 'w2')
            return w, wire

        a, b = pyrtl.input_list('a/1 b/1')
        w1 = a & b
        o = pyrtl.Output(1, 'o')
        o <<= w1

        src_nets, dst_nets = pyrtl.working_block().net_connections()
        self.assertEqual(dst_nets[w1],
                         [pyrtl.LogicNet('w', None, (w1, ), (o, ))])
        self.assertIn(o, src_nets)

        transform.wire_transform(f,
                                 select_types=pyrtl.Output,
                                 exclude_types=tuple())

        w2 = pyrtl.working_block().get_wirevector_by_name('w2')
        src_nets, dst_nets = pyrtl.working_block().net_connections()
        self.assertEqual(dst_nets[w1],
                         [pyrtl.LogicNet('w', None, (w1, ), (w2, ))])
        self.assertNotIn(o, src_nets)