diff options
Diffstat (limited to 'icebox/icebox_colbuf.py')
-rwxr-xr-x | icebox/icebox_colbuf.py | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/icebox/icebox_colbuf.py b/icebox/icebox_colbuf.py new file mode 100755 index 0000000..8d1ac3b --- /dev/null +++ b/icebox/icebox_colbuf.py @@ -0,0 +1,140 @@ +#!/usr/bin/python2 +# +# Copyright (C) 2015 Clifford Wolf <clifford@clifford.at> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +from __future__ import division +from __future__ import print_function + +import icebox +import getopt, sys, re + +check_mode = False +fixup_mode = False + +def usage(): + print(""" +Usage: icebox_colbuf [options] [bitmap.txt] + + -c + check colbuf bits + + -f + fix colbuf bits +""") + sys.exit(1) + +try: + opts, args = getopt.getopt(sys.argv[1:], "cf") +except: + usage() + +for o, a in opts: + if o == "-c": + check_mode = True + elif o == "-f": + fixup_mode = True + else: + usage() + +if len(args) == 0: + args.append("/dev/stdin") + +if len(args) != 1: + usage() + +if check_mode == fixup_mode: + print("Error: Use either -c or -f!") + sys.exit(1) + +print("Reading file '%s'.." % args[0]) +ic = icebox.iceconfig() +ic.read_file(args[0]) + +def make_cache(stmt, raw_db): + cache = list() + for entry in raw_db: + if entry[1] == stmt and entry[2].startswith("glb_netwk_"): + cache_entry = [int(entry[2][-1]), []] + for bit in entry[0]: + value = "1" + if bit.startswith("!"): + value = "0" + bit = bit[1:] + match = re.match("B([0-9]+)\[([0-9]+)\]", bit) + cache_entry[1].append((int(match.group(1)), int(match.group(2)), value)) + cache.append(cache_entry) + return cache + +def match_cache_entry(cache_entry, tile_dat): + for entry in cache_entry[1]: + if tile_dat[entry[0]][entry[1]] != entry[2]: + return False + return True + +def analyze_tile(ic, cache, tile_pos): + glbs = set() + tile_dat = ic.tile(tile_pos[0], tile_pos[1]) + for cache_entry in cache: + if match_cache_entry(cache_entry, tile_dat): + glbs.add(cache_entry[0]) + return glbs + +colbuf_map = dict() +used_glbs_map = dict() +driven_glbs_map = dict() + +for entry in ic.colbuf_db(): + colbuf_map[(entry[2], entry[3])] = (entry[0], entry[1]) + +for tiles in [ic.io_tiles, ic.logic_tiles, ic.ramb_tiles, ic.ramt_tiles]: + cache = None + for tile in tiles: + if cache is None: + cache = make_cache("buffer", ic.tile_db(tile[0], tile[1])) + glbs = analyze_tile(ic, cache, tile) + if len(glbs): + assert tile in colbuf_map + used_glbs_map[colbuf_map[tile]] = glbs + + cache = None + for tile in tiles: + if cache is None: + cache = make_cache("ColBufCtrl", ic.tile_db(tile[0], tile[1])) + glbs = analyze_tile(ic, cache, tile) + if len(glbs): + driven_glbs_map[tile] = glbs + +if check_mode: + error_count = 0 + for tile, bits in used_glbs_map.items(): + for bit in bits: + if tile not in driven_glbs_map or bit not in driven_glbs_map[tile]: + print("Missing driver for glb_netwk_%d in tile %s" % (bit, tile)) + error_count += 1 + for tile, bits in driven_glbs_map.items(): + for bit in bits: + if tile not in used_glbs_map or bit not in used_glbs_map[tile]: + print("Unused driver for glb_netwk_%d in tile %s" % (bit, tile)) + error_count += 1 + if error_count != 0: + print("Found %d errors!" % error_count) + sys.exit(1) + print("No errors found.") + +if fixup_mode: + print("Error: Fixup mode is not implemented yet!") + sys.exit(1) + |