def run():
    """
    This example loads a netlist and then generates two connectivity graphs: one with top level ports and one without.
    The connectivity graph without top level ports could be generated more quickly by copying the graph containing the
    ports and then removing the nodes that represent top level ports. These connectivity graphs can also be used to
    generate sequential connectivity graphs by removing nodes that represent combinational logic and propagating their
    created connections (add an edge from all predecessors to all successors).    
    """
    global netlist
    global connectivity_graph
    netlist = sdn.load_example_netlist_by_name('b13')

    connectivity_graph_with_top_level_ports = get_connectivity_graph(
        include_top_ports=True)
    print("Total nodes in connectivity_graph with top_level_ports",
          connectivity_graph_with_top_level_ports.number_of_nodes())
    print("Total edges in connectivity_graph with top_level_ports",
          connectivity_graph_with_top_level_ports.number_of_edges())

    connectivity_graph_without_top_level_ports = get_connectivity_graph(
        include_top_ports=False)
    print("Total nodes in connectivity_graph without top_level_ports",
          connectivity_graph_without_top_level_ports.number_of_nodes())
    print("Total edges in connectivity_graph without top_level_ports",
          connectivity_graph_without_top_level_ports.number_of_edges())
Example #2
0
 def test_get_driver_2(self):
     netlist = sdn.load_example_netlist_by_name('adder')
     instance = next(netlist.get_instances('a'))
     cable = next(instance.get_cables('a'))
     wire = cable.wires[0]
     driver = list(x for x in wire.get_driver())
     self.assertTrue(len(driver) == 1)
     self.assertTrue('a[8:0]' in driver[0].port.name)
Example #3
0
 def test_is_top_instance(self):
     netlist = sdn.load_example_netlist_by_name('toggle')
     self.assertTrue(netlist.top_instance.is_top_instance)
     original_top_instance = netlist.top_instance
     random_instance = next(netlist.get_instances())
     netlist.top_instance = random_instance
     self.assertFalse(original_top_instance.is_top_instance)
     self.assertTrue(random_instance.is_top_instance)
Example #4
0
 def test_get_driver(self):
     netlist = sdn.load_example_netlist_by_name('toggle')
     instance = next(netlist.get_instances('out_reg'))
     input_pin = next(
         instance.get_pins(selection=Selection.OUTSIDE,
                           filter=lambda x: x.inner_pin.port.direction is
                           sdn.IN and 'D' in x.inner_pin.port.name))
     driver = list(x for x in input_pin.wire.get_driver())
     self.assertTrue(len(driver) == 1)
     self.assertTrue('out_i_1' in driver[0].instance.name)
     self.assertEqual(driver[0].inner_pin.port.name, 'O')
 def setUpClass(cls) -> None:
     cls.netlist = sdn.load_example_netlist_by_name('b13')
Example #6
0
    definition_clean_up(def_to_copy)
    return definition_copies


def clean(definition):
    for child in definition.children:
        if child.reference in definition_copies:
            make_instances_unique(child)


definition_count = dict()
original_inner_pin_to_new_inner_pin = dict()
instance_map = dict()
outer_pin_map = dict()
definition_copies = dict()

example_name = 'unique_challenge'
ir = sdn.load_example_netlist_by_name(example_name)
top_def = ir.top_instance.reference

reverse_topological_order = get_reverse_topological_order(ir)
for definition in reverse_topological_order:
    make_definition_copies(definition, definition_count[definition] - 1)
clean(top_def)

import tempfile
import os
with tempfile.TemporaryDirectory() as td:
    file_name = example_name + '_unique.edf'
    sdn.compose(ir, os.path.join(td, file_name))
Example #7
0
 def test_is_unique(self):
     example_name = 'unique_challenge'
     netlist = sdn.load_example_netlist_by_name(example_name)
     self.assertFalse(netlist.is_unique())
     uniquify(netlist)
     self.assertTrue(netlist.is_unique())
Example #8
0
 def test_top_instance_name(self):
     netlist = sdn.load_example_netlist_by_name('toggle')
     self.assertTrue('top_instance.name \'toggle\'' in netlist.__str__())
Example #9
0
+---+---+---+

The output Q for the OR gate is the following: ``Q = 4'b1110``, or in hexadecimal, ``Q=4'hE``.

The netlist example that is loaded in has a LUT configured to be an AND gate, but with SpyDrNet, you can modify that LUT to be something else. The LUT configuration ``'4'h8'`` (an AND gate) for the LUT in the netlist will be changed to ``'4'hE'`` (an OR gate) in this example.

After making this configuration, the new netlist will be composed twice, showing that SpyDrNet can either create an EDIF netlist file or a Verilog netlist file that both represent the same netlist.

"""

import spydrnet as sdn

# Change this line to change the configuration of the LUT in the design.
LUT_CONFIG = 0xE

logic_gate_netlist = sdn.load_example_netlist_by_name("AND_gate")

# Alternatively you can parse in your own netlist by changing the line below.
# logic_gate_netlist = sdn.parse('<my_netlist.edf>')

# Find the LUT2 definition
for definition in logic_gate_netlist.get_definitions():
    if definition.name == "LUT2":
        lut_instances = definition.references
        # Once the LUT2 definition has been found, go through its instances
        for instance in lut_instances:
            properties = instance["EDIF.properties"]
            # Change the value in the properties of the LUT2 instance
            properties[0]["value"] = "4'h" + str(hex(LUT_CONFIG)).upper()[2:]

# The netlist is composed into both an EDIF file and also in a Verliog file
Example #10
0
 def test_recursive_memory_use(self):
     netlist = sdn.load_example_netlist_by_name('leon3mp_hierarchical')
     hrefs = list(sdn.get_hinstances(netlist))
     self.assertTrue(len(hrefs) > 0)
Example #11
0
"""
=====================================
Traversal and Statistics of a Netlist
=====================================

Traverse a netlist and collect statistics on the netlist.
"""

import spydrnet as sdn

# Loads the example
ir = sdn.load_example_netlist_by_name("fourBitCounter")

print("Netlist stats")
print("Top instance:", ir.top_instance['EDIF.identifier'])
print(str(len(ir.libraries)) + " libraries detected")
# Loop through each library in a design
for library in ir.libraries:
    # Gets the name of the current library and reports number of definitions
    print("Library name:", library['EDIF.identifier'])
    print("\t", str(len(library.definitions)), "definitions detected")
    # Loop through each definition in current library
    for definition in library.definitions:
        # Gets the name of the current definition and how many times its been used
        print("\tDefinition name:", definition['EDIF.identifier'])
        print("\t\t", "Defintion used", str(len(definition.references)),
              "times")
        # Gets the number of Ports in definition
        print("\t\t", str(len(definition.ports)), "ports detected")
        # Loop through each port for the current definition
        for port in definition.ports:
Example #12
0
            print("Finished moving cells from", child['EDIF.identifier'])
    return created


#print the hierarchy of a netlist
def hierarchy(current_instance, indentation=""):
    print(indentation, current_instance.name)
    for child in current_instance.reference.children:
        hierarchy(child, indentation + "   ")


example_name1 = "unique_challenge"
example_name2 = "three_layer_hierarchy"
example_name3 = "unique_different_modules"
example_name = example_name1
ir = sdn.load_example_netlist_by_name(example_name)
ir_orig = sdn.load_example_netlist_by_name(
    example_name)  #store the original netlist for display later
top_def = ir.top_instance.reference
flatten_definition(top_def, top_definition=True)

with tempfile.TemporaryDirectory() as td:
    file_name = example_name + '_flat.edf'
    sdn.compose(ir, os.path.join(td, file_name))

# sdn.composers.compose("test.edf", ir)
print()

print("ORIGINAL HIERARCHY")
hierarchy(ir_orig.top_instance)
print("\nHIERARCHY AFTER FLATTENING")
Example #13
0
 def test_load_example_netlist_by_name(self):
     netlist = sdn.load_example_netlist_by_name(sdn.example_netlist_names[0])
     self.assertIsNotNone(netlist)
 def setUpClass(cls) -> None:
     sdn.namespace_manager.deregister_all_listeners()
     cls.netlist = sdn.load_example_netlist_by_name("b13")
Example #15
0
 def test_instance_parent_name_is_not_none(self):
     netlist = sdn.load_example_netlist_by_name('toggle')
     out_reg = next(netlist.get_instances('*out_reg*'))
     instance = sdn.Instance()
     out_reg.reference.add_child(instance)
     self.assertTrue('parent definition.name \'FDRE\'' in instance.__str__())