2019-04-26 21:21:50 +02:00
|
|
|
# See LICENSE for licensing information.
|
|
|
|
|
#
|
2019-06-14 17:43:41 +02:00
|
|
|
# Copyright (c) 2016-2019 Regents of the University of California and The Board
|
|
|
|
|
# of Regents for the Oklahoma Agricultural and Mechanical College
|
|
|
|
|
# (acting for and on behalf of Oklahoma State University)
|
|
|
|
|
# All rights reserved.
|
2019-04-26 21:21:50 +02:00
|
|
|
#
|
2016-11-08 18:57:35 +01:00
|
|
|
import hierarchy_layout
|
|
|
|
|
import hierarchy_spice
|
2017-06-02 20:11:57 +02:00
|
|
|
import debug
|
2017-11-16 22:52:58 +01:00
|
|
|
from globals import OPTS
|
2017-06-02 20:11:57 +02:00
|
|
|
|
2020-09-29 19:26:31 +02:00
|
|
|
|
2018-07-10 00:42:46 +02:00
|
|
|
class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
|
2016-11-08 18:57:35 +01:00
|
|
|
"""
|
|
|
|
|
Design Class for all modules to inherit the base features.
|
|
|
|
|
Class consisting of a set of modules and instances of these modules
|
|
|
|
|
"""
|
2017-06-02 20:11:57 +02:00
|
|
|
name_map = []
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2020-11-03 01:00:16 +01:00
|
|
|
def __init__(self, name, cell_name):
|
2020-07-13 23:08:00 +02:00
|
|
|
self.drc_errors = "skipped"
|
|
|
|
|
self.lvs_errors = "skipped"
|
|
|
|
|
|
2020-11-03 01:00:16 +01:00
|
|
|
hierarchy_spice.spice.__init__(self, name, cell_name)
|
|
|
|
|
hierarchy_layout.layout.__init__(self, name, cell_name)
|
2019-04-24 23:23:22 +02:00
|
|
|
self.init_graph_params()
|
2019-01-17 01:15:38 +01:00
|
|
|
|
2020-04-02 18:47:39 +02:00
|
|
|
def get_layout_pins(self, inst):
|
2017-08-07 19:24:45 +02:00
|
|
|
""" Return a map of pin locations of the instance offset """
|
|
|
|
|
# find the instance
|
|
|
|
|
for i in self.insts:
|
|
|
|
|
if i.name == inst.name:
|
|
|
|
|
break
|
|
|
|
|
else:
|
2020-06-22 20:33:02 +02:00
|
|
|
debug.error("Couldn't find instance {0}".format(inst.name), -1)
|
2017-08-07 19:24:45 +02:00
|
|
|
inst_map = inst.mod.pin_map
|
|
|
|
|
return inst_map
|
2020-11-03 15:29:17 +01:00
|
|
|
|
2020-04-02 18:47:39 +02:00
|
|
|
def DRC_LVS(self, final_verification=False, force_check=False):
|
2016-11-08 18:57:35 +01:00
|
|
|
"""Checks both DRC and LVS for a module"""
|
2020-06-30 16:16:05 +02:00
|
|
|
import verify
|
2020-04-02 20:31:28 +02:00
|
|
|
|
|
|
|
|
# No layout to check
|
|
|
|
|
if OPTS.netlist_only:
|
2020-07-13 23:08:00 +02:00
|
|
|
return
|
2018-07-11 01:39:32 +02:00
|
|
|
# Unit tests will check themselves.
|
2020-07-13 22:01:00 +02:00
|
|
|
elif not force_check and OPTS.is_unit_test:
|
2020-07-13 23:08:00 +02:00
|
|
|
return
|
2020-07-13 22:01:00 +02:00
|
|
|
elif not force_check and not OPTS.check_lvsdrc:
|
2020-07-13 23:08:00 +02:00
|
|
|
return
|
2018-07-11 01:39:32 +02:00
|
|
|
# Do not run if disabled in options.
|
2020-07-13 22:01:00 +02:00
|
|
|
elif (OPTS.inline_lvsdrc or force_check or final_verification):
|
2018-11-15 19:45:33 +01:00
|
|
|
|
2020-04-02 18:47:39 +02:00
|
|
|
tempspice = "{0}/{1}.sp".format(OPTS.openram_temp, self.name)
|
2020-04-03 22:39:54 +02:00
|
|
|
self.lvs_write(tempspice)
|
2020-11-11 02:06:24 +01:00
|
|
|
tempgds = "{0}/{1}.gds".format(OPTS.openram_temp, self.name)
|
2016-11-08 18:57:35 +01:00
|
|
|
self.gds_write(tempgds)
|
2020-04-02 20:31:28 +02:00
|
|
|
# Final verification option does not allow nets to be connected by label.
|
2020-11-11 02:06:24 +01:00
|
|
|
self.drc_errors = verify.run_drc(self.cell_name, tempgds, tempspice, extract=True, final_verification=final_verification)
|
2020-11-03 01:00:16 +01:00
|
|
|
self.lvs_errors = verify.run_lvs(self.cell_name, tempgds, tempspice, final_verification=final_verification)
|
2020-04-02 21:52:42 +02:00
|
|
|
|
|
|
|
|
# force_check is used to determine decoder height and other things, so we shouldn't fail
|
|
|
|
|
# if that flag is set
|
|
|
|
|
if OPTS.inline_lvsdrc and not force_check:
|
2020-07-13 21:49:24 +02:00
|
|
|
debug.check(self.drc_errors == 0,
|
2020-11-03 01:00:16 +01:00
|
|
|
"DRC failed for {0} with {1} error(s)".format(self.cell_name,
|
2020-07-13 21:49:24 +02:00
|
|
|
self.drc_errors))
|
|
|
|
|
debug.check(self.lvs_errors == 0,
|
2020-11-03 01:00:16 +01:00
|
|
|
"LVS failed for {0} with {1} errors(s)".format(self.cell_name,
|
2020-07-13 21:49:24 +02:00
|
|
|
self.lvs_errors))
|
2018-11-15 19:45:33 +01:00
|
|
|
|
2018-11-14 01:51:19 +01:00
|
|
|
def DRC(self, final_verification=False):
|
2016-11-08 18:57:35 +01:00
|
|
|
"""Checks DRC for a module"""
|
2020-06-30 16:16:05 +02:00
|
|
|
import verify
|
|
|
|
|
|
2018-07-11 01:39:32 +02:00
|
|
|
# Unit tests will check themselves.
|
|
|
|
|
# Do not run if disabled in options.
|
2018-11-15 19:45:33 +01:00
|
|
|
|
2020-04-02 20:31:28 +02:00
|
|
|
# No layout to check
|
|
|
|
|
if OPTS.netlist_only:
|
2020-07-13 23:08:00 +02:00
|
|
|
return
|
2020-07-13 22:01:00 +02:00
|
|
|
elif (not OPTS.is_unit_test and OPTS.check_lvsdrc and (OPTS.inline_lvsdrc or final_verification)):
|
2020-11-11 02:06:24 +01:00
|
|
|
tempspice = "{0}{1}.sp".format(OPTS.openram_temp, self.name)
|
|
|
|
|
self.lvs_write(tempspice)
|
|
|
|
|
tempgds = "{0}{1}.gds".format(OPTS.openram_temp, self.cell_name)
|
2016-11-08 18:57:35 +01:00
|
|
|
self.gds_write(tempgds)
|
2020-11-11 02:06:24 +01:00
|
|
|
num_errors = verify.run_drc(self.cell_name, tempgds, tempspice, final_verification=final_verification)
|
2020-04-02 18:47:39 +02:00
|
|
|
debug.check(num_errors == 0,
|
2020-11-03 01:00:16 +01:00
|
|
|
"DRC failed for {0} with {1} error(s)".format(self.cell_name,
|
2020-04-02 18:47:39 +02:00
|
|
|
num_errors))
|
2018-11-15 19:45:33 +01:00
|
|
|
|
2018-02-05 23:52:51 +01:00
|
|
|
def LVS(self, final_verification=False):
|
2016-11-08 18:57:35 +01:00
|
|
|
"""Checks LVS for a module"""
|
2020-06-30 16:16:05 +02:00
|
|
|
import verify
|
|
|
|
|
|
2018-07-11 01:39:32 +02:00
|
|
|
# Unit tests will check themselves.
|
|
|
|
|
# Do not run if disabled in options.
|
2018-11-15 19:45:33 +01:00
|
|
|
|
2020-04-02 20:31:28 +02:00
|
|
|
# No layout to check
|
|
|
|
|
if OPTS.netlist_only:
|
2020-07-13 23:08:00 +02:00
|
|
|
return
|
2020-07-13 22:01:00 +02:00
|
|
|
elif (not OPTS.is_unit_test and OPTS.check_lvsdrc and (OPTS.inline_lvsdrc or final_verification)):
|
2020-11-11 02:06:24 +01:00
|
|
|
tempspice = "{0}{1}.sp".format(OPTS.openram_temp, self.cell_name)
|
2020-04-03 22:39:54 +02:00
|
|
|
self.lvs_write(tempspice)
|
2020-11-11 02:06:24 +01:00
|
|
|
tempgds = "{0}{1}.gds".format(OPTS.openram_temp, self.name)
|
2016-11-08 18:57:35 +01:00
|
|
|
self.gds_write(tempgds)
|
2019-09-03 20:23:35 +02:00
|
|
|
num_errors = verify.run_lvs(self.name, tempgds, tempspice, final_verification=final_verification)
|
2020-04-02 18:47:39 +02:00
|
|
|
debug.check(num_errors == 0,
|
2020-11-03 01:00:16 +01:00
|
|
|
"LVS failed for {0} with {1} error(s)".format(self.cell_name,
|
2020-04-02 18:47:39 +02:00
|
|
|
num_errors))
|
2020-11-03 15:29:17 +01:00
|
|
|
|
2019-04-24 23:23:22 +02:00
|
|
|
def init_graph_params(self):
|
2020-11-03 15:29:17 +01:00
|
|
|
"""
|
2020-09-29 19:26:31 +02:00
|
|
|
Initializes parameters relevant to the graph creation
|
|
|
|
|
"""
|
2020-04-02 18:47:39 +02:00
|
|
|
# Only initializes a set for checking instances which should not be added
|
2019-04-24 23:23:22 +02:00
|
|
|
self.graph_inst_exclude = set()
|
2020-11-03 15:29:17 +01:00
|
|
|
|
2020-04-02 18:47:39 +02:00
|
|
|
def build_graph(self, graph, inst_name, port_nets):
|
2020-09-29 19:26:31 +02:00
|
|
|
"""
|
|
|
|
|
Recursively create graph from instances in module.
|
|
|
|
|
"""
|
2020-11-03 15:29:17 +01:00
|
|
|
|
2020-04-02 18:47:39 +02:00
|
|
|
# Translate port names to external nets
|
2019-04-19 10:27:06 +02:00
|
|
|
if len(port_nets) != len(self.pins):
|
2020-04-02 18:47:39 +02:00
|
|
|
debug.error("Port length mismatch:\nExt nets={}, Ports={}".format(port_nets,
|
|
|
|
|
self.pins),
|
|
|
|
|
1)
|
|
|
|
|
port_dict = {pin: port for pin, port in zip(self.pins, port_nets)}
|
2019-04-24 23:23:22 +02:00
|
|
|
debug.info(3, "Instance name={}".format(inst_name))
|
2019-04-19 10:27:06 +02:00
|
|
|
for subinst, conns in zip(self.insts, self.conns):
|
2019-04-24 23:23:22 +02:00
|
|
|
if subinst in self.graph_inst_exclude:
|
|
|
|
|
continue
|
2020-04-02 18:47:39 +02:00
|
|
|
subinst_name = inst_name + '.X' + subinst.name
|
2019-04-19 10:27:06 +02:00
|
|
|
subinst_ports = self.translate_nets(conns, port_dict, inst_name)
|
|
|
|
|
subinst.mod.build_graph(graph, subinst_name, subinst_ports)
|
2020-11-03 15:29:17 +01:00
|
|
|
|
2019-05-27 22:08:59 +02:00
|
|
|
def build_names(self, name_dict, inst_name, port_nets):
|
2020-09-29 19:26:31 +02:00
|
|
|
"""
|
|
|
|
|
Collects all the nets and the parent inst of that net.
|
|
|
|
|
"""
|
2020-04-02 18:47:39 +02:00
|
|
|
# Translate port names to external nets
|
2019-05-27 22:08:59 +02:00
|
|
|
if len(port_nets) != len(self.pins):
|
2020-04-02 18:47:39 +02:00
|
|
|
debug.error("Port length mismatch:\nExt nets={}, Ports={}".format(port_nets,
|
|
|
|
|
self.pins),
|
|
|
|
|
1)
|
|
|
|
|
port_dict = {pin: port for pin, port in zip(self.pins, port_nets)}
|
2019-05-27 22:08:59 +02:00
|
|
|
debug.info(3, "Instance name={}".format(inst_name))
|
|
|
|
|
for subinst, conns in zip(self.insts, self.conns):
|
2020-04-02 18:47:39 +02:00
|
|
|
subinst_name = inst_name + '.X' + subinst.name
|
2019-05-27 22:08:59 +02:00
|
|
|
subinst_ports = self.translate_nets(conns, port_dict, inst_name)
|
|
|
|
|
for si_port, conn in zip(subinst_ports, conns):
|
2020-04-02 18:47:39 +02:00
|
|
|
# Only add for first occurrence
|
2019-05-27 22:08:59 +02:00
|
|
|
if si_port.lower() not in name_dict:
|
2020-04-02 18:47:39 +02:00
|
|
|
mod_info = {'mod': self, 'int_net': conn}
|
2019-05-27 22:08:59 +02:00
|
|
|
name_dict[si_port.lower()] = mod_info
|
2020-04-02 18:47:39 +02:00
|
|
|
subinst.mod.build_names(name_dict, subinst_name, subinst_ports)
|
2019-05-27 22:08:59 +02:00
|
|
|
|
2019-04-19 10:27:06 +02:00
|
|
|
def translate_nets(self, subinst_ports, port_dict, inst_name):
|
2020-09-29 19:26:31 +02:00
|
|
|
"""
|
|
|
|
|
Converts connection names to their spice hierarchy equivalent
|
|
|
|
|
"""
|
2019-04-19 10:27:06 +02:00
|
|
|
converted_conns = []
|
|
|
|
|
for conn in subinst_ports:
|
|
|
|
|
if conn in port_dict:
|
|
|
|
|
converted_conns.append(port_dict[conn])
|
|
|
|
|
else:
|
|
|
|
|
converted_conns.append("{}.{}".format(inst_name, conn))
|
2020-04-02 18:47:39 +02:00
|
|
|
return converted_conns
|
2020-11-03 15:29:17 +01:00
|
|
|
|
2019-05-07 09:52:27 +02:00
|
|
|
def add_graph_edges(self, graph, port_nets):
|
2020-09-29 19:26:31 +02:00
|
|
|
"""
|
|
|
|
|
For every input, adds an edge to every output.
|
|
|
|
|
Only intended to be used for gates and other simple modules.
|
|
|
|
|
"""
|
2020-04-02 18:47:39 +02:00
|
|
|
# The final pin names will depend on the spice hierarchy, so
|
|
|
|
|
# they are passed as an input.
|
|
|
|
|
pin_dict = {pin: port for pin, port in zip(self.pins, port_nets)}
|
2019-05-07 09:52:27 +02:00
|
|
|
input_pins = self.get_inputs()
|
|
|
|
|
output_pins = self.get_outputs()
|
|
|
|
|
inout_pins = self.get_inouts()
|
2020-04-02 18:47:39 +02:00
|
|
|
for inp in input_pins + inout_pins:
|
|
|
|
|
for out in output_pins + inout_pins:
|
|
|
|
|
if inp != out: # do not add self loops
|
|
|
|
|
graph.add_edge(pin_dict[inp], pin_dict[out], self)
|
2020-11-03 15:29:17 +01:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
def __str__(self):
|
|
|
|
|
""" override print function output """
|
2019-04-17 22:41:17 +02:00
|
|
|
pins = ",".join(self.pins)
|
|
|
|
|
insts = [" {}".format(x) for x in self.insts]
|
2020-04-02 18:47:39 +02:00
|
|
|
objs = [" {}".format(x) for x in self.objs]
|
2020-11-03 01:00:16 +01:00
|
|
|
s = "********** design {0} **********".format(self.cell_name)
|
2019-04-17 22:41:17 +02:00
|
|
|
s += "\n pins ({0})={1}\n".format(len(self.pins), pins)
|
|
|
|
|
s += "\n objs ({0})=\n{1}\n".format(len(self.objs), "\n".join(objs))
|
|
|
|
|
s += "\n insts ({0})=\n{1}\n".format(len(self.insts), "\n".join(insts))
|
|
|
|
|
return s
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
""" override print function output """
|
|
|
|
|
text="( design: " + self.name + " pins=" + str(self.pins) + " " + str(self.width) + "x" + str(self.height) + " )\n"
|
|
|
|
|
for i in self.objs:
|
2020-04-02 18:47:39 +02:00
|
|
|
text+=str(i) + ",\n"
|
2016-11-08 18:57:35 +01:00
|
|
|
for i in self.insts:
|
2020-04-02 18:47:39 +02:00
|
|
|
text+=str(i) + ",\n"
|
2016-11-08 18:57:35 +01:00
|
|
|
return text
|
2020-11-03 15:29:17 +01:00
|
|
|
|