old_contents: #!/usr/bin/env python3
  
  from prjxray.segmaker import Segmaker
  
  verbose = 1
  
  segmk = Segmaker("design.bits")
  
  tiledata = dict()
  pipdata = dict()
  ignpip = set()
  todo = set()
  
  print("Loading todo from ../todo.txt.")
  with open("../todo.txt", "r") as f:
      for line in f:
          line = tuple(line.strip().split("."))
          verbose and print('todo', line)
          todo.add(line)
  
  print("Loading tags from design.txt.")
  with open("design.txt", "r") as f:
      for line in f:
          tile, pip, src, dst, pnum, pdir = line.split()
          _, pip = pip.split(".")
          _, src = src.split("/")
          _, dst = dst.split("/")
          pnum = int(pnum)
          pdir = int(pdir)
  
          if tile not in tiledata:
              tiledata[tile] = {"pips": set(), "srcs": set(), "dsts": set()}
  
          if pip in pipdata:
              assert pipdata[pip] == (src, dst)
          else:
              pipdata[pip] = (src, dst)
  
          tiledata[tile]["pips"].add(pip)
          tiledata[tile]["srcs"].add(src)
          tiledata[tile]["dsts"].add(dst)
  
          if pdir == 0:
              tiledata[tile]["srcs"].add(dst)
              tiledata[tile]["dsts"].add(src)
  
          if pnum == 1 or pdir == 0:
              verbose and print('ignore pnum == 1 or pdir == 0: ', pip)
              ignpip.add(pip)
  
          t = ("_".join(tile.split("_")[0:2]), dst, src)
          if t not in todo:
              verbose and print('ignore not todo: ', t)
              ignpip.add(pip)
  
  for tile, pips_srcs_dsts in tiledata.items():
      pips = pips_srcs_dsts["pips"]
      srcs = pips_srcs_dsts["srcs"]
      dsts = pips_srcs_dsts["dsts"]
  
      for pip, src_dst in pipdata.items():
          src, dst = src_dst
          if pip in ignpip:
              pass
          elif pip in pips:
              segmk.add_tile_tag(tile, "%s.%s" % (dst, src), 1)
          elif src_dst[1] not in dsts:
              segmk.add_tile_tag(tile, "%s.%s" % (dst, src), 0)
  
  segmk.compile()
  segmk.write()
  
new_contents: #!/usr/bin/env python3
  
  from prjxray.segmaker import Segmaker
  
  verbose = 1
  
  segmk = Segmaker("design.bits")
  
  tiledata = dict()
  pipdata = dict()
  ignpip = set()
  todo = set()
  
  print("Loading todo from ../todo.txt.")
  with open("../../todo.txt", "r") as f:
      for line in f:
          line = tuple(line.strip().split("."))
          verbose and print('todo', line)
          todo.add(line)
  
  print("Loading tags from design.txt.")
  with open("design.txt", "r") as f:
      for line in f:
          tile, pip, src, dst, pnum, pdir = line.split()
          _, pip = pip.split(".")
          _, src = src.split("/")
          _, dst = dst.split("/")
          pnum = int(pnum)
          pdir = int(pdir)
  
          if tile not in tiledata:
              tiledata[tile] = {"pips": set(), "srcs": set(), "dsts": set()}
  
          if pip in pipdata:
              assert pipdata[pip] == (src, dst)
          else:
              pipdata[pip] = (src, dst)
  
          tiledata[tile]["pips"].add(pip)
          tiledata[tile]["srcs"].add(src)
          tiledata[tile]["dsts"].add(dst)
  
          if pdir == 0:
              tiledata[tile]["srcs"].add(dst)
              tiledata[tile]["dsts"].add(src)
  
          if pnum == 1 or pdir == 0:
              verbose and print('ignore pnum == 1 or pdir == 0: ', pip)
              ignpip.add(pip)
  
          t = ("_".join(tile.split("_")[0:2]), dst, src)
          if t not in todo:
              verbose and print('ignore not todo: ', t)
              ignpip.add(pip)
  
  for tile, pips_srcs_dsts in tiledata.items():
      pips = pips_srcs_dsts["pips"]
      srcs = pips_srcs_dsts["srcs"]
      dsts = pips_srcs_dsts["dsts"]
  
      for pip, src_dst in pipdata.items():
          src, dst = src_dst
          if pip in ignpip:
              pass
          elif pip in pips:
              segmk.add_tile_tag(tile, "%s.%s" % (dst, src), 1)
          elif src_dst[1] not in dsts:
              segmk.add_tile_tag(tile, "%s.%s" % (dst, src), 0)
  
  segmk.compile()
  segmk.write()
  
subject: fix todo path