Beispiel #1
0
def cread(c_name, input_nodes):
    f = open(c_name, 'r')
    indx = 0
    nodelist = []
    nodedict = {}
    lines = f.readlines()
    for line in lines:
        linesplit = line.split()
        new_node = node()
        new_node.ntype = ntype(int(linesplit[0])).name
        new_node.num = int(linesplit[1])
        new_node.gtype = gtype(int(linesplit[2])).name

        if (ntype(int(linesplit[0])).value == 2):  #if BRCH --> unodes
            new_node.add_unodes(nodedict.get(int(linesplit[3])))
            new_node.fout = 1
        else:  #if not BRCH --> fout
            new_node.fout = int(linesplit[3])

        if (ntype(int(linesplit[0])).value != 2):
            new_node.fin = int(linesplit[4])
            for i in range(int(linesplit[4])):
                new_node.add_unodes(nodedict.get(int(linesplit[5 + i])))
        else:
            new_node.fin = 1

        if ((ntype(int(linesplit[0])).value == 1)
                or (ntype(int(linesplit[0])).value == 2)):
            new_node.cpt = 1

        new_node.index = indx
        indx = indx + 1
        nodelist.append(new_node)
        nodedict.update({new_node.num: new_node})

    f.close()

    for i in range(len(nodelist)):
        if (nodelist[i].ntype != 'PI'):
            for j in range(nodelist[i].fin):
                nodelist[i].unodes[j].add_dnodes(nodelist[i])
        else:
            input_nodes.append(nodelist[i].num)
    return nodelist
Beispiel #2
0
    def read_circuit(self):
        """
        Read circuit from .ckt file, instantiate each node as a class,
        initialize self.nodes
        """
        path = "../circuits/{}.ckt".format(self.c_name)
        f = open(path, 'r')
        indx = 0
        nodedict = {}
        fileList = []
        nodedict_list = [None] * 1355
        temp_dict = {}
        lines = f.readlines()

        for line in lines:
            if (line != "\n"):
                fileList.append(line.split())
        for i in fileList:
            i[1] = int(i[1])
        for line in fileList:
            new_node = node()
            new_node.ntype = ntype(int(line[0])).name
            new_node.num = int(line[1])
            if new_node.num not in self.node_ids:
                self.node_ids.append(new_node.num)
            new_node.gtype = gtype(int(line[2])).name

            if (ntype(int(line[0])).value == 2):  #if BRCH --> unodes
                new_node.add_unodes(nodedict_list[int(line[3])])
                new_node.fout = 1
            else:  #if not BRCH --> fout
                new_node.fout = int(line[3])

            if (ntype(int(line[0])).value != 2):
                new_node.fin = int(line[4])
                for i in range(int(line[4])):
                    if (nodedict_list[int(line[5 + i])] == None):
                        new_node_temp = node()
                        new_node_temp.num = int(line[5 + i])
                        nodedict.update({new_node_temp.num: new_node_temp})
                        nodedict_list[new_node_temp.num] = new_node_temp
                        new_node.add_unodes(nodedict_list[int(line[5 + i])])
                        temp_dict.update({int(line[5 + i]): new_node.num})
                    else:
                        new_node.add_unodes(nodedict_list[int(line[5 + i])])
            else:
                new_node.fin = 1

            if ((ntype(int(line[0])).value == 1)
                    or (ntype(int(line[0])).value == 2)):
                new_node.cpt = 1

            new_node.index = indx
            indx = indx + 1
            self.nodes.append(new_node)
            if (temp_dict.get(new_node.num) != None):
                for i in self.nodes:
                    if (i.num == temp_dict.get(new_node.num)):
                        for j in i.unodes:
                            if (j.num == new_node.num):
                                i.unodes.remove(j)
                                i.unodes.append(new_node)
            nodedict_list[new_node.num] = new_node
            nodedict.update({new_node.num: new_node})
            #TODO:feedback only to one gate
        f.close()
        for i in range(len(self.nodes)):
            if (self.nodes[i].ntype != 'PI'):
                for j in range(self.nodes[i].fin):
                    self.nodes[i].unodes[j].add_dnodes(self.nodes[i])
            else:
                self.input_num_list.append(self.nodes[i].num)

        self.nodes_cnt = len(self.nodes)
        self.input_cnt = len(self.input_num_list)
Beispiel #3
0
def cread(c_name, input_nodes):
    f = open(c_name, 'r')
    indx = 0
    nodelist = []
    nodedict = {}
    fileList = []
    nodedict_list = [None] * 1355
    fileList_sorted = []
    temp_dict = {}
    lines = f.readlines()

    for line in lines:
        if (line != "\n"):
            fileList.append(line.split())
    for i in fileList:
        i[1] = int(i[1])
    #fileList_sorted = sorted(fileList, key = lambda x:x[1])
    # print (fileList_sorted)
    #cnt = 0
    for line in fileList:
        #print (cnt)
        #line = line.split()
        #print (line)
        new_node = node()
        new_node.ntype = ntype(int(line[0])).name
        new_node.num = int(line[1])
        new_node.gtype = gtype(int(line[2])).name

        if (ntype(int(line[0])).value == 2):  #if BRCH --> unodes
            # if (nodedict_list[int(line[3])] == None):
            #     new_node_temp = node()
            #     new_node_temp.num = int(line[3])
            #     nodedict.update({new_node_temp.num: new_node_temp})
            #     nodedict_list[new_node_temp.num] = new_node_temp
            #     new_node.add_unodes(nodedict_list[int(line[3])])
            # else:
            new_node.add_unodes(nodedict_list[int(line[3])])
            new_node.fout = 1
        else:  #if not BRCH --> fout
            new_node.fout = int(line[3])

        if (ntype(int(line[0])).value != 2):
            new_node.fin = int(line[4])
            for i in range(int(line[4])):
                if (nodedict_list[int(line[5 + i])] == None):
                    new_node_temp = node()
                    new_node_temp.num = int(line[5 + i])
                    nodedict.update({new_node_temp.num: new_node_temp})
                    nodedict_list[new_node_temp.num] = new_node_temp
                    new_node.add_unodes(nodedict_list[int(line[5 + i])])
                    temp_dict.update({int(line[5 + i]): new_node.num})
                else:
                    new_node.add_unodes(nodedict_list[int(line[5 + i])])
        else:
            new_node.fin = 1

        if ((ntype(int(line[0])).value == 1)
                or (ntype(int(line[0])).value == 2)):
            new_node.cpt = 1

        new_node.index = indx
        indx = indx + 1
        nodelist.append(new_node)
        if (temp_dict.get(new_node.num) != None):
            #print(temp_dict.get(new_node.num))
            for i in nodelist:
                if (i.num == temp_dict.get(new_node.num)):
                    for j in i.unodes:
                        if (j.num == new_node.num):
                            i.unodes.remove(j)
                            i.unodes.append(new_node)
        nodedict_list[new_node.num] = new_node
        nodedict.update({new_node.num: new_node})
        #TODO:feedback only to one gate
        #cnt = cnt+1
    # print(temp_dict)
    f.close()
    #print ("here")
    for i in range(len(nodelist)):
        #print (nodelist[i].ntype)
        if (nodelist[i].ntype != 'PI'):
            #print(nodelist[i].fin)
            for j in range(nodelist[i].fin):
                nodelist[i].unodes[j].add_dnodes(nodelist[i])
                #print (j)
        else:
            input_nodes.append(nodelist[i].num)
    # print (nodedict.get(723).fin)
    # print ("above in cread")
    return nodelist