Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.00 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from collections import defaultdict
  3.  
  4. import argparse
  5. import os
  6. cell_fail_list = {}
  7.  
  8.  
  9. class Transistor:
  10.     def __init__(self, transistor_name, drain, gate, source, transistor_type):
  11.         self.name = transistor_name
  12.         self.d = drain
  13.         self.g = gate
  14.         self.s = source
  15.         self.mos = transistor_type
  16.  
  17.  
  18. def get_transistors(cell_name):
  19.     drains_and_sources = []
  20.     transistors_data = {}
  21.     dgt_dict = defaultdict(list)
  22.     sgt_dict = defaultdict(list)
  23.     try:
  24.         with open("%s/cells/%s/%s.lvs" % (relative_path, cell_name, cell_name)) as lvs_file:
  25.             for t in lvs_file:
  26.                 t = t.strip()
  27.                 if len(t) != 0 and t[0].isalpha():
  28.                     t = t.split()
  29.                     name = t[0]
  30.                     d = t[1]
  31.                     g = t[2]
  32.                     s = t[3]
  33.                     mos = t[4]
  34.                     drains_and_sources.append(s)
  35.                     drains_and_sources.append(d)
  36.                     if d != s:
  37.                         dgt = '%s %s %s' % (d, g, mos)
  38.                         sgt = '%s %s %s' % (s, g, mos)
  39.                         transistors_data[name] = Transistor(name, d, g, s, mos)
  40.                         dgt_dict[dgt].append(transistors_data[name])
  41.                         sgt_dict[sgt].append(transistors_data[name])
  42.  
  43.             branch_points = []
  44.             for i in drains_and_sources:
  45.                 if drains_and_sources.count(i) > 2 and i not in branch_points:
  46.                     branch_points.append(i)
  47.             for i in dgt_dict.keys():
  48.                 if len(dgt_dict[i]) == 1 or i.split()[2] == 'VBP':
  49.                     del dgt_dict[i]
  50.             for i in sgt_dict.keys():
  51.                 if len(sgt_dict[i]) == 1 or i.split()[2] == 'VBN':
  52.                     del sgt_dict[i]
  53.         return drains_and_sources, dgt_dict, sgt_dict, branch_points, transistors_data
  54.     except IOError:
  55.         cell_fail_list[cell_name] = "no lvs, or corrupted file"
  56.  
  57.  
  58. def find_series(branch_head, cell_name):
  59.     current = branch_head
  60.     big_list = [current]
  61.     while True:
  62.         series = []
  63.         for t in get_transistors(cell_name)[4].values():
  64.             if t.mos == 'VBN':
  65.                 if current.s == t.d and current.s not in get_transistors(cell_name)[3]:
  66.                     series.append(t)
  67.             elif t.mos == 'VBP':
  68.                 if current.d == t.s and current.d not in get_transistors(cell_name)[3]:
  69.                     series.append(t)
  70.         if len(series) == 1:
  71.             big_list.append(series[0])
  72.             current = series[0]
  73.         else:
  74.             if len(big_list) == 0:
  75.                 big_list = [branch_head]
  76.             return [big_list, current]
  77.  
  78. # //parser//
  79. parser = argparse.ArgumentParser()
  80. group = parser.add_mutually_exclusive_group(required=True)
  81. group.add_argument('-all', help="test all cells", action="store_true")
  82. group.add_argument('-list', help="test for provided list")
  83. parser.add_argument('-path', help="enter the path for the review folder that contains \"cells\" folder",
  84.                     default=os.getcwd())
  85. args = parser.parse_args()
  86. # returns: object
  87.  
  88. relative_path = args.path
  89. if args.all:
  90.     cell_list_names = {cell: cell.split("_")[1][0] for cell in os.listdir(relative_path + "/cells") if
  91.                        (("_" in cell) and (cell.split("_")[1][0] in ("c", "v")))}
  92. else:
  93.     with open(args.list) as f:
  94.         cell_list_names = {cell: cell.split("_")[1][0] for cell in [line[:-1] for line in f] if
  95.                            (("_" in cell) and (cell.split("_")[1][0] in ("c", "v")))}
  96. for cell in cell_list_names:
  97.     data = get_transistors(cell)
  98.     # data is [drains_and_sources, dgt_dict, sgt_dict, branch_points, transistors_data]
  99.     to_delete = []
  100.     for key in data[1]:
  101.         temporary_dict = defaultdict(list)
  102.         for branch_point in data[1][key]:
  103.             for i in find_series(branch_point, cell)[0]:
  104.                 temporary_dict[branch_point.name].append(i.g)
  105.             temporary_dict[branch_point.name].append(find_series(branch_point, cell)[1].s)
  106.         history = []
  107.         for head, tail in temporary_dict.items():
  108.             if tail in history:
  109.                 to_delete.append(head)
  110.             else:
  111.                 history.append(tail)
  112.  
  113.     for key in data[2]:
  114.         temporary_dict = defaultdict(list)
  115.         for branch_point in data[2][key]:
  116.             for i in find_series(branch_point, cell)[0]:
  117.                 temporary_dict[branch_point.name].append(i.g)
  118.             temporary_dict[branch_point.name].append(find_series(branch_point, cell)[1].d)
  119.         history = []
  120.         for head, tail in temporary_dict.items():
  121.             if tail in history:
  122.                 to_delete.append(head)
  123.             else:
  124.                 history.append(tail)
  125.     final_list = []
  126.     for i in to_delete:
  127.         for u in find_series(data[4][i], cell)[0]:
  128.             final_list.append(u.name)
  129.     print '\n\n%s' % cell
  130.     print final_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement