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')
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
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()
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
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
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')