From 219232f97ff023d205513f1b63d0a98edc88c6e3 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 21 Jul 2015 12:02:58 +0200 Subject: icebox_vlog: debug symbols and FF init values --- icebox/icebox.py | 2 ++ icebox/icebox_vlog.py | 56 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/icebox/icebox.py b/icebox/icebox.py index c7d76ce..3baf165 100644 --- a/icebox/icebox.py +++ b/icebox/icebox.py @@ -34,6 +34,7 @@ class iceconfig: self.ramt_tiles = dict() self.ram_data = dict() self.extra_bits = set() + self.symbols = dict() def setup_empty_1k(self): self.clear() @@ -579,6 +580,7 @@ class iceconfig: self.device = line[1] continue if line[0] in [".comment", ".sym"]: + self.symbols.setdefault(int(line[1]), set()).add(line[2]) expected_data_lines = -1 continue print("%sWarning: ignoring line %d: %s" % (logprefix, linenum, linetext.strip())) diff --git a/icebox/icebox_vlog.py b/icebox/icebox_vlog.py index 105445d..05a8197 100755 --- a/icebox/icebox_vlog.py +++ b/icebox/icebox_vlog.py @@ -26,6 +26,7 @@ strip_interconn = False lookup_pins = False check_ieren = False check_driver = False +lookup_symbols = False pcf_data = dict() portnames = set() unmatched_ports = set() @@ -44,6 +45,9 @@ Usage: icebox_vlog [options] [bitmap.txt] -l convert io tile port names to chip pin numbers + -L + lookup symbol names (using .sym statements in input) + -n name for the exported module (default: "chip") @@ -63,7 +67,7 @@ Usage: icebox_vlog [options] [bitmap.txt] sys.exit(0) try: - opts, args = getopt.getopt(sys.argv[1:], "sSlap:P:n:RD") + opts, args = getopt.getopt(sys.argv[1:], "sSlLap:P:n:RD") except: usage() @@ -74,6 +78,8 @@ for o, a in opts: strip_interconn = True elif o == "-l": lookup_pins = True + elif o == "-L": + lookup_symbols = True elif o == "-n": modname = a elif o == "-a": @@ -351,6 +357,35 @@ def seg_to_net(seg, default=None): text_wires.append("") return seg2net[seg] +if lookup_symbols: + text_func.append("// Debug Symbols") + with open("/usr/local/share/icebox/chipdb-%s.txt" % ic.device, "r") as f: + current_net = -1 + exported_names = dict() + for line in f: + line = line.split() + if len(line) == 0: + pass + elif line[0] == ".net": + current_net = int(line[1]) + if current_net not in ic.symbols: + current_net = -1 + elif line[0].startswith("."): + current_net = -1 + elif current_net >= 0: + seg = (int(line[0]), int(line[1]), line[2]) + if seg in seg2net: + for name in ic.symbols[current_net]: + while name in exported_names: + if exported_names[name] == seg2net[seg]: + break + name += "_" + if name not in exported_names: + text_func.append("wire \\_%s = %s;" % (name, seg2net[seg])) + exported_names[name] = seg2net[seg] + current_net = -1 + text_func.append("") + wb_boot = seg_to_net(icebox.warmbootinfo_db[ic.device]["BOOT"], "") wb_s0 = seg_to_net(icebox.warmbootinfo_db[ic.device]["S0"], "") wb_s1 = seg_to_net(icebox.warmbootinfo_db[ic.device]["S1"], "") @@ -781,19 +816,22 @@ for a in const_assigns + lut_assigns + carry_assigns: print("module %s (%s);\n" % (modname, ", ".join(text_ports))) new_text_wires = list() +new_text_regs = list() for line in text_wires: match = re.match(r"wire ([^ ;]+)(.*)", line) - if match and match.group(1) in wire_to_reg: - line = "reg " + match.group(1) + match.group(2) if strip_comments: - if new_text_wires and new_text_wires[-1].split()[0] == line.split()[0] and new_text_wires[-1][-1] == ";": - new_text_wires[-1] = new_text_wires[-1][0:-1] + "," + line[len(line.split()[0]):] - else: - new_text_wires.append(line) + if match and match.group(1) in wire_to_reg: + new_text_regs.append(match.group(1)) + elif match: + new_text_wires.append(match.group(1)) else: + if match and match.group(1) in wire_to_reg: + line = "reg " + match.group(1) + " = 0" + match.group(2) print(line) -for line in new_text_wires: - print(line) +for names in [new_text_wires[x:x+10] for x in range(0, len(new_text_wires), 10)]: + print("wire %s;" % ", ".join(names)) +for names in [new_text_regs[x:x+10] for x in range(0, len(new_text_regs), 10)]: + print("reg %s = 0;" % " = 0, ".join(names)) if strip_comments: print() -- cgit v1.2.3