From 9284744028b5a48b07d0ffba3a05771fba1a56b0 Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Fri, 5 Oct 2018 07:26:55 -0700 Subject: [PATCH 1/2] Additional library behaviors after integration. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- prjxray/db.py | 7 ++++++- prjxray/grid.py | 4 ++++ prjxray/lib.py | 4 ++-- prjxray/tile.py | 50 +++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/prjxray/db.py b/prjxray/db.py index 5f08335e..57d03a65 100644 --- a/prjxray/db.py +++ b/prjxray/db.py @@ -69,13 +69,18 @@ class Database(object): self.site_types[site_type_name] = os.path.join(self.db_root, f) + self.tile_types_obj = {} + def get_tile_types(self): """ Return list of tile types """ return self.tile_types.keys() def get_tile_type(self, tile_type): """ Return Tile object for given tilename. """ - return tile.Tile(tile_type, self.tile_types[tile_type]) + if tile_type not in self.tile_types_obj: + self.tile_types_obj[tile_type] = tile.Tile(tile_type, self.tile_types[tile_type]) + + return self.tile_types_obj[tile_type] def _read_tilegrid(self): """ Read tilegrid database if not already read. """ diff --git a/prjxray/grid.py b/prjxray/grid.py index 82a81445..8f1a6ed2 100644 --- a/prjxray/grid.py +++ b/prjxray/grid.py @@ -29,6 +29,10 @@ class Grid(object): x, y = zip(*self.loc.keys()) self._dims = (min(x), max(x), min(y), max(y)) + def tiles(self): + """ Return list of tiles. """ + return self.tileinfo.keys() + def tile_locations(self): """ Return list of tile locations. """ return self.loc.keys() diff --git a/prjxray/lib.py b/prjxray/lib.py index aa0d2bb2..208c46b2 100644 --- a/prjxray/lib.py +++ b/prjxray/lib.py @@ -1,8 +1,6 @@ import os.path import csv import pickle -import pyjson5 as json5 -import progressbar import re from collections import namedtuple @@ -112,6 +110,8 @@ class NodeLookup(object): self.nodes = nodes def load_from_root_csv(self, nodes): + import pyjson5 as json5 + import progressbar for node in progressbar.progressbar(nodes): with open(node) as f: node_wires = json5.load(f) diff --git a/prjxray/tile.py b/prjxray/tile.py index 0600fe50..c4283d6f 100644 --- a/prjxray/tile.py +++ b/prjxray/tile.py @@ -4,7 +4,8 @@ from prjxray import lib """ Database files available for a tile """ TileDbs = namedtuple('TileDbs', 'segbits mask tile_type') -Pip = namedtuple('Pip', 'net_to net_from can_invert is_directional is_pseudo') +Pip = namedtuple('Pip', 'name net_to net_from can_invert is_directional is_pseudo') + """ Site - Represents an instance of a site within a tile. name - Name of site within tile, instance specific. @@ -16,6 +17,7 @@ pins - Instaces of site pins within this site and tile. This is an tuple of """ Site = namedtuple('Site', 'name prefix x y type site_pins') + """ SitePin - Tuple representing a site pin within a tile. Sites are generic based on type, however sites are instanced @@ -24,13 +26,13 @@ information and tile type specific information. name - Site type specific name. This name is expected to be the same for all sites of the same type. -direction - Direction of this site pin. This direction is expected to be the - same for all sites of the same type. wire - Wire name within the tile. This name is site instance specific. """ SitePin = namedtuple('SitePin', 'name wire') +WireInfo = namedtuple('WireInfo', 'pips sites') + class Tile(object): """ Provides abstration of a tile in the database. """ @@ -43,6 +45,7 @@ class Tile(object): self.wires = None self.sites = None self.pips = None + self.pips_by_name = {} def yield_sites(sites): for site in sites: @@ -59,8 +62,9 @@ class Tile(object): ) for name, wire in site['site_pins'].items())) def yield_pips(pips): - for pip in pips.values(): + for name, pip in pips.items(): yield Pip( + name = name, net_to=pip['dst_wire'], net_from=pip['src_wire'], can_invert=bool(int(pip['can_invert'])), @@ -75,6 +79,8 @@ class Tile(object): self.sites = tuple(yield_sites(tile_type['sites'])) self.pips = tuple(yield_pips(tile_type['pips'])) + self.wire_info = {} + def get_wires(self): """Returns a set of wire names present in this tile.""" return self.wires @@ -88,6 +94,34 @@ class Tile(object): """ return self.pips + def get_pip_by_name(self, name): + if len(self.pips_by_name) == 0: + for pip in self.pips: + self.pips_by_name[pip.name] = pip + + return self.pips_by_name[name] + + def get_wire_info(self, target_wire, allow_pseudo=False): + if len(self.wire_info) == 0: + for wire in self.wires: + pips = list() + sites = list() + + for site in self.sites: + for site_pin in site.site_pins: + if site_pin.wire == wire: + sites.append((site.name, site_pin.name)) + + for pip in self.pips: + pseudo_filter = (not pip.is_pseudo) or allow_pseudo + if (wire == pip.net_to or wire == pip.net_from) and pseudo_filter: + pips.append(pip.name) + + assert wire not in self.wire_info + self.wire_info[wire] = WireInfo(pips=pips, sites=sites) + + return self.wire_info[target_wire] + def get_instance_sites(self, grid_info): """ get_sites returns abstract sites for all tiles of type. get_instance_sites converts site info from generic to specific @@ -125,3 +159,11 @@ class Tile(object): ) assert site_names == set(grid_info.sites.keys()) + +def get_other_wire_from_pip(pip, wire): + if wire == pip.net_to: + return pip.net_from + elif wire == pip.net_from: + return pip.net_to + else: + assert False, (pip, wire) From 73dc0211fe4f82e4b672f92ecae0ea110a39532c Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Fri, 5 Oct 2018 09:43:33 -0700 Subject: [PATCH 2/2] Run make format. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- prjxray/db.py | 3 ++- prjxray/tile.py | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/prjxray/db.py b/prjxray/db.py index 57d03a65..c75ce52c 100644 --- a/prjxray/db.py +++ b/prjxray/db.py @@ -78,7 +78,8 @@ class Database(object): def get_tile_type(self, tile_type): """ Return Tile object for given tilename. """ if tile_type not in self.tile_types_obj: - self.tile_types_obj[tile_type] = tile.Tile(tile_type, self.tile_types[tile_type]) + self.tile_types_obj[tile_type] = tile.Tile( + tile_type, self.tile_types[tile_type]) return self.tile_types_obj[tile_type] diff --git a/prjxray/tile.py b/prjxray/tile.py index c4283d6f..85f2ca2a 100644 --- a/prjxray/tile.py +++ b/prjxray/tile.py @@ -4,8 +4,8 @@ from prjxray import lib """ Database files available for a tile """ TileDbs = namedtuple('TileDbs', 'segbits mask tile_type') -Pip = namedtuple('Pip', 'name net_to net_from can_invert is_directional is_pseudo') - +Pip = namedtuple( + 'Pip', 'name net_to net_from can_invert is_directional is_pseudo') """ Site - Represents an instance of a site within a tile. name - Name of site within tile, instance specific. @@ -17,7 +17,6 @@ pins - Instaces of site pins within this site and tile. This is an tuple of """ Site = namedtuple('Site', 'name prefix x y type site_pins') - """ SitePin - Tuple representing a site pin within a tile. Sites are generic based on type, however sites are instanced @@ -64,7 +63,7 @@ class Tile(object): def yield_pips(pips): for name, pip in pips.items(): yield Pip( - name = name, + name=name, net_to=pip['dst_wire'], net_from=pip['src_wire'], can_invert=bool(int(pip['can_invert'])), @@ -114,7 +113,8 @@ class Tile(object): for pip in self.pips: pseudo_filter = (not pip.is_pseudo) or allow_pseudo - if (wire == pip.net_to or wire == pip.net_from) and pseudo_filter: + if (wire == pip.net_to + or wire == pip.net_from) and pseudo_filter: pips.append(pip.name) assert wire not in self.wire_info @@ -160,6 +160,7 @@ class Tile(object): assert site_names == set(grid_info.sites.keys()) + def get_other_wire_from_pip(pip, wire): if wire == pip.net_to: return pip.net_from