def test_cable_shortcut(self): c = Cable('c_name', None, False, True, 2) self.assertEqual(c.name, 'c_name', 'Cable name init shorcut error') self.assertEqual(c.is_downto, False, 'Cable is_downto init shorcut error') self.assertEqual(c.is_scalar, True, 'Cable is_scalar init shorcut error') self.assertEqual(c.lower_index, 2, 'Cable lower_index init shorcut error') c2 = Cable(is_scalar = False) self.assertEqual(c2.name, None, 'Cable name init shorcut error') self.assertEqual(c2.is_downto, True, 'Cable is_downto init shorcut error') self.assertEqual(c2.is_scalar, False, 'Cable is_scalar init shorcut error') self.assertEqual(c2.lower_index, 0, 'Cable lower_index init shorcut error')
def test_wire_index_shortcut(self): cable = Cable() cable.create_wires(3) wire = Wire() cable.add_wire(wire,1) self.assertEqual(wire.cable.wires.index(wire), wire.index(), 'wire index shorcut error') self.assertEqual(wire.index(), 1, 'wire index shorcut error') wire2 = Wire() cable.add_wire(wire2,3) self.assertEqual(wire2.cable.wires.index(wire2), wire2.index(), 'wire index shorcut error') self.assertEqual(wire2.index(), 3, 'wire index shorcut error')
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')
def create_cable(self, name=None, properties=None, is_downto=None, is_scalar=None, lower_index=None, wires=None): """Create a cable, add it to the definition, and return the cable. parameters ---------- name - (str) the name of this instance properties - (dict) the dictionary which holds the properties id_downto - (bool) set the downto status. Downto is False if the right index is higher than the left one, True otherwise is_scalar - (bool) set the scalar status. Return True if the item is a scalar False otherwise. lower_index - (int) get the value of the lower index of the array. wires - (int) Create number of wires in the newly created cable """ cable = Cable(name, properties, is_downto, is_scalar, lower_index) self.add_cable(cable) if wires: cable.create_wires(wires) return cable
def parse_net(self): self.append_new_element(Cable()) self.expect(NET) self.parse_nameDef() self.elements[-1].is_scalar = True self.elements[-1].create_wires(1) # EDIF nets are single wire cables. self.parse_construct(self.parse_joined) 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()
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')
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 Cable as CableExtended c = CableExtended() memo[self] = c new_wires = list() for w in self._wires: new_wires.append(w._clone(memo)) c._wires = new_wires for w in c._wires: w._cable = c c._definition = None c._is_downto = deepcopy(self._is_downto) c._is_scalar = deepcopy(self._is_scalar) c._lower_index = deepcopy(self._lower_index) c._data = deepcopy(self._data) return c