Exemplo n.º 1
0
    def create_child(self, name=None, properties=None, reference=None):
        """Create an instance to add to the definition, add it, and return the instance.

        This functions calls the add_child funciton.

        parameters
        ----------

        name - (str) the name of this instance
        properties - (dict) the dictionary which holds the properties

        Example
        -------

        To create a child:

        >>> definition = sdn.Definition()
        >>> child_instance = definition.create_child()
        >>> child_instance.name = "child_instance"
        >>> child_instance.reference = reference_definition

        To create a child with optional parameters

        >>> child_instance = definition.create_child(name="child_instance", reference=reference_definition)

        The reference of the instance is the definition that initialized this instance.
        """
        instance = Instance(name, properties)
        instance.reference = reference
        self.add_child(instance)
        return instance
Exemplo n.º 2
0
    def set_top_instance(self, instance, instance_name='instance'):
        """Sets the top instance of the design.

        The instance must not be null and should probably come from this netlist

        Parameters
        ----------
        instance - (Instance or Definition) the instance to set as the top instance. If a definition is passed into the funciton,
        creates a new instance with that definition and set it as the top instance.
        """
        assert instance is None or isinstance(
            instance, Instance) or isinstance(
                instance, Definition), "Must specify an instance"
        global_callback._call_netlist_top_instance(self, instance)
        # TODO: should We have a DRC that makes sure the instance is of a definition contained in netlist? I think no
        #  but I am open to hear other points of veiw.

        if isinstance(instance, Definition):
            top = Instance()
            top.reference = instance
            instance.name = instance_name
            self.top_instance = top
            self.top_instance.name = instance_name
        else:
            self._top_instance = instance
Exemplo n.º 3
0
 def parse_design(self):
     self.expect(DESIGN)
     # self.tokenizer.next()
     instance = Instance()
     instance['metadata_prefix'] = list()
     self.elements.append(instance)
     instance['metadata_prefix'] = ['EDIF']
     if self.begin_construct():
         self.parse_rename()
         self.tokenizer.next()
     else:
         self.prefix_append('identifier')
         self.set_attribute(self.parse_identifier())
         self.prefix_pop()
     self.prefix_pop()
     self.tokenizer.next()
     self.tokenizer.next()
     definition_name = self.tokenizer.next()
     self.tokenizer.next()
     self.tokenizer.next()
     library_name = self.tokenizer.next()
     for library in self.elements[0].libraries:
         if library['EDIF.identifier'] == library_name:
             break
     for definition in library.definitions:
         if definition['EDIF.identifier'] == definition_name:
             break
     instance.reference = definition
     self.elements.pop()
     self.elements[0].top_instance = instance
     self.skip_until_next_construct()
Exemplo n.º 4
0
    def parse_instance(self):
        self.append_new_element(Instance())
        self.expect(INSTANCE)
        self.parse_nameDef()
        if self.begin_construct():
            if self.construct_is(VIEW_REF):
                definition = self.parse_viewRef()
                instance = self.elements[-1]
                instance.reference = definition

            elif self.construct_is(VIEW_LIST):
                raise NotImplementedError()
            else:
                self.expect(VIEW_REF)
            self.expect_end_construct()

        while self.begin_construct():
            if self.construct_is(PROPERTY):
                self.parse_property()
            elif self.construct_is(COMMENT):
                self.parse_comment()
            elif self.construct_is(USER_DATA):
                self.parse_userData()
            else:
                self.expect('|'.join([PROPERTY, COMMENT, USER_DATA]))
            self.expect_end_construct()
        return self.pop_element()
Exemplo n.º 5
0
 def _clone(self, memo):
     """Not api safe clone function
     clone the instance leaving all references in tact.
     The instance can then either be ripped or ripped and replaced
     """
     assert self not in memo, "the object should not have been copied twice in this pass"
     from spydrnet.ir import Instance as InstanceExtended
     c = InstanceExtended()
     memo[self] = c
     c._parent = None
     for inner_pin, outer_pin in self._pins.items():
         new_outer_pin = outer_pin._clone(memo)
         new_outer_pin._instance = c
         c._pins[inner_pin] = new_outer_pin
     c._reference = self._reference
     c._data = deepcopy(self._data)
     return c
Exemplo n.º 6
0
 def test_name_init_shortcut(self):
     d = Definition('d_name')
     self.assertEqual(d.name, 'd_name', 'Definition name init shorcut error')
     l = Library('l_name')
     self.assertEqual(l.name, 'l_name', 'Library name init shorcut error')
     n = Netlist('n_name')
     self.assertEqual(n.name, 'n_name', 'Netlist name init shorcut error')
     i = Instance('i_name')
     self.assertEqual(i.name, 'i_name', 'Instance name init shorcut error')
     c = Cable('c_name')
     self.assertEqual(c.name, 'c_name', 'Cable name init shorcut error')
     p = Port('p_name')
     self.assertEqual(p.name, 'p_name', 'Port name init shorcut error')
Exemplo n.º 7
0
 def test_if_leaf_shortcut(self):
     instance = Instance()
     definition = Definition()
     instance.reference = definition
     self.assertEqual(definition.is_leaf(), instance.is_leaf(), 'is_leaf shortcut error')
     definition.create_cable()
     instance.reference = definition
     self.assertEqual(definition.is_leaf(), instance.is_leaf(), 'is_leaf shortcut error')
Exemplo n.º 8
0
    def test_properties_init_shortcut(self):

        d = Definition('d_name',{'key1':1, 'key2':'value2' })
        self.assertEqual(d['key1'], 1, 'Definition properties init shorcut error')

        l = Library('l_name',{'key1':'value1', 'key2':'value2' })
        self.assertEqual(l['key1'], 'value1', 'Library properties init shorcut error')

        n = Netlist('n_name',{'key1':'value1', 'key2': 63 })
        self.assertEqual(n['key2'], 63, 'Netlist properties init shorcut error')

        i = Instance('i_name',{'key1':'value1', 'key2':'value2' })
        self.assertEqual(i['key1'], 'value1', 'Instance properties init shorcut error')

        c = Cable('c_name',{'key1':'value1', 'key2':'value2' })
        self.assertEqual(c['key2'], 'value2', 'Cable properties init shorcut error')

        p = Port('p_name',{'key1':'value1', 'key2':'value2' })
        self.assertEqual(p['key1'], 'value1', 'Port properties init shorcut error')
Exemplo n.º 9
0
    def parse_verilog(self):
        params = dict()

        token = self.tokenizer.next()
        line_num = self.tokenizer.line_number
        self.netlist = Netlist()
        self.primitive_cell = False
        top_next = False
        while token:

            if token == '`celldefine':
                self.primitive_cell = True
            elif self.primitive_cell and token == "`endcelldefine":
                self.primitive_cell = False

            elif token == "(":
                token = self.tokenizer.next()
                assert token == "*", "unexpected ( with out a *" + " " + str(
                    self.tokenizer.line_number)
                k, v = self.parse_star_parameters()
                if k == "STRUCTURAL_NETLIST":
                    top_next = True
                k = "VERILOG.star." + k
                params[k] = v

            elif token == "module":
                definition = self.parse_module(params, self.netlist)
                #if netlist.top_instance is None:
                if top_next == True:
                    instance = Instance()
                    instance.name = definition.name
                    instance.reference = definition
                    self.netlist.top_instance = instance
                    top_next = False

            elif token[:2] == "//":
                pass  #comment

            elif token == "primitive":
                while token != "endprimitive":
                    token = self.tokenizer.next()

            else:
                #print("unsorted token", token)
                pass  #unsorted token

            if self.tokenizer.has_next():
                token = self.tokenizer.next()
                line_num = self.tokenizer.line_number
            else:
                token = None

        for instance, port_map in self.instance_to_port_map.items():
            port_pin_map = dict()
            for port in instance.reference.ports:
                port_pin_map[port] = []
            for pin in instance.pins:
                port_pin_map[pin.inner_pin.port].append(pin)
            definition = instance.parent

            for port_name, cable_list in port_map.items():

                index_offset = 0
                for cable_name in cable_list:
                    low = None
                    high = None
                    index_offset_initial = index_offset
                    if cable_name[len(cable_name) - 1] == "]" and (
                            cable_name[0] != "\\"
                            or len(cable_name.split(" ")) > 1):
                        cable_name_real, index = cable_name.split(" ")
                        indicies = index[1:len(index) - 1].split(":")
                        if len(indicies) == 1:
                            low = int(indicies[0])
                            high = None
                        else:
                            low = min(int(indicies[0]), int(indicies[1]))
                            high = max(int(indicies[0]), int(indicies[1]))
                    else:
                        cable_name_real = cable_name
                    cable_def_list = definition.get_cables(cable_name_real)
                    cable = next(cable_def_list)
                    port_list = instance.reference.get_ports(port_name)
                    port = next(port_list)
                    if low == None and high == None:
                        if len(cable.wires) == len(port_pin_map[port]):
                            for i in range(len(cable.wires)):
                                cable.wires[i].connect_pin(
                                    port_pin_map[port][i +
                                                       index_offset_initial])
                                index_offset += 1
                        else:
                            for i in range(
                                    min(len(port_pin_map[port]),
                                        len(cable.wires))):
                                cable.wires[i].connect_pin(
                                    port_pin_map[port][i +
                                                       index_offset_initial])
                                index_offset += 1
                    else:
                        if high == None:
                            # try:
                            cable.wires[low - cable.lower_index].connect_pin(
                                port_pin_map[port][0 + index_offset_initial])
                            # except Exception:
                            #     import pdb; pdb.set_trace()
                            index_offset += 1
                        else:
                            for i in range(low, high + 1):
                                cable.wires[i - cable.lower_index].connect_pin(
                                    port_pin_map[port][i - low +
                                                       index_offset_initial])
                                index_offset += 1
        return self.netlist
Exemplo n.º 10
0
 def test_hRef_shortcut(self):
     item = Instance("myCable")
     def2 = Definition("Hello")
     item.reference = def2
     hr = HRef(item)
     self.assertEqual(hr.item.name,item.name,'Href item shorcut error')