Beispiel #1
0
 def create_definition(self):
     """
     create a definition, add it to the library, and return the definition
     """
     definition = Definition()
     self.add_definition(definition)
     return definition
Beispiel #2
0
    def parse_cell(self):
        definition = Definition()
        self.append_new_element(definition)

        self.expect(CELL)
        self.parse_nameDef()
        self.parse_construct(self.parse_cellType)

        has_status = False
        has_viewMap = False
        while self.begin_construct():
            if self.construct_is(STATUS):
                has_status = self.check_for_multiples(STATUS, has_status)
                self.parse_status()

            elif self.construct_is(VIEW):
                self.parse_view()
            elif self.construct_is(VIEW_MAP):
                has_viewMap = self.check_for_multiples(VIEW_MAP, has_viewMap)
                self.parse_viewMap()

            elif 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([STATUS, VIEW, VIEW_MAP, PROPERTY, COMMENT, USER_DATA]))
            self.expect_end_construct()

        return self.pop_element()
Beispiel #3
0
    def create_definition(self, name=None, properties=None):
        """Create a definition, add it to the library, and return the definition

        parameters
        ----------

        name - (str) the name of this instance
        properties - (dict) the dictionary which holds the properties
        """
        definition = Definition(name, properties)
        self.add_definition(definition)
        return definition
Beispiel #4
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')
Beispiel #5
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')
Beispiel #6
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')
Beispiel #7
0
    def _clone(self, memo):
        """Not api safe clone function

        clone leaving all references in tact.
        the element 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 Definition as DefinitionExtended
        c = DefinitionExtended()
        memo[self] = c
        c._data = deepcopy(self._data)
        c._library = None

        new_ports = list()
        for p in self.ports:
            new_ports.append(p._clone(memo))
        c._ports = new_ports

        new_cables = list()
        for ca in self.cables:
            new_cables.append(ca._clone(memo))
        c._cables = new_cables

        new_children = list()
        for ch in self.children:
            new_children.append(ch._clone(memo))
        c._children = new_children

        c._references = copy(self._references)

        for port in c._ports:
            port._definition = c
            port._clone_rip_and_replace(memo)

        for cable in c._cables:
            cable._definition = c
            cable._clone_rip_and_replace(memo)

        for instance in c._children:
            instance._parent = c
            instance._clone_rip_and_replace_in_definition(memo)

        return c
Beispiel #8
0
 def test_netlist_top_instance_definition_shortcut(self):
     top_definition = Definition('this is my name')
     netlist = Netlist()
     netlist.top_instance = top_definition
     self.assertEqual(netlist.top_instance.reference.name,top_definition.name,'Netlist\'s top instance\'s shorcut error')
Beispiel #9
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')
Beispiel #10
0
    def test_definition_child_instance_creation(self):
        d = Definition('d_name',{'key1':1, 'key2':'value2' })
        self.assertEqual(d['key1'], 1, 'Definition properties init shorcut error')

        d.create_port('p_name')
        self.assertEqual(d.ports[0].name, 'p_name', 'Port name init shorcut error')
        d.create_port(properties = {'key1':'value1', 'key2':'value2' })
        self.assertEqual(d.ports[1]['key1'], 'value1', 'Port properties init shorcut error')

        d.create_port(properties = {'key1':'value1', 'key2':'value2' })
        self.assertEqual(d.ports[1]['key1'], 'value1', 'Port properties init shorcut error')

        d.create_child('d_c_name', {'key1':1, 'key2':'value2' })
        self.assertEqual(d.children[0]['key1'], 1, 'Definition properties init shorcut error')
        self.assertEqual(d['key1'], 1, 'Definition properties init shorcut error')

        d.create_cable('c_name', None,  False, True, 2)
        self.assertEqual(d.cables[0].name, 'c_name', 'Cable name init shorcut error')
        self.assertEqual(d.cables[0].is_downto, False, 'Cable is_downto init shorcut error')
        self.assertEqual(d.cables[0].is_scalar, True, 'Cable is_scalar init shorcut error')
        self.assertEqual(d.cables[0].lower_index, 2, 'Cable lower_index init shorcut error')

        d.create_cable(is_scalar =  False)
        self.assertEqual(d.cables[1].name, None, 'Cable name init shorcut error')
        self.assertEqual(d.cables[1].is_downto, True, 'Cable is_downto init shorcut error')
        self.assertEqual(d.cables[1].is_scalar, False, 'Cable is_scalar init shorcut error')
        self.assertEqual(d.cables[1].lower_index, 0, 'Cable lower_index init shorcut error')