Simple framework for physical chip design (place & route) based on KLayout.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.1 KiB

<?xml version="1.0" encoding="utf-8"?>
Signal routing is not yet implemented.
Instead the routing connections are just highlighted with direct lines.
from kpnr.router.airwire_router import AirwireRouter
# === PREPARE for routing ===
# Draw layout of routing terminals, i.e. pin shapes of cells and macros.
# Create flat structure of routing terminals.
# Plot pin shapes and net names.
routing_terminal_layer = layout.layer(db.LayerInfo(21, 0, 'routing_terminal'))
routing_terminal_cell = layout.create_cell("routing_terminals")
top_cell.insert(db.CellInstArray(routing_terminal_cell.cell_index(), db.Trans(0, 0)))
pin_shapes_by_net = collections.defaultdict(set)
terminal_ids = itertools.count(1)
for net in design.top_circuit.each_net():
assert isinstance(net, db.Net)
net_pins = net.each_subcircuit_pin()
for p in net_pins:
subcircuit_id = p.subcircuit().id()
if subcircuit_id not in design.cell_instances_by_subcircuit_id:
logger.warning('No cell instance for subcircuit {}'.format(p.subcircuit().name))
cell_inst = design.cell_instances_by_subcircuit_id[subcircuit_id]
assert isinstance(cell_inst, db.Instance)
assert cell_inst.is_valid()
cell = cell_inst.cell
cell_name =
transf = cell_inst.trans
# Get the name of the pin.
pin_name =
# Get the associated pin shapes.
pin_shapes = cell_pin_shapes[cell_name][pin_name]
# Move the pin shapes to the location of the cell.
placed_pin_shapes = db.Shapes()
# Insert shapes and plot net names.
for s in placed_pin_shapes.each():
s = routing_terminal_cell.shapes(routing_terminal_layer).insert(s)
label_text =
s.set_property('terminal_id', next(terminal_ids))
text_position = polygon_label.find_polygon_label_position(s.polygon, label_text)
routing_terminal_cell.shapes(routing_terminal_layer).insert(db.Text(label_text, text_position))
# === Sketch pin connections ===
# Create layer for air wires.
airwire_layer = layout.layer(db.LayerInfo(1000, 1, 'air_wires'))
airwire_router = AirwireRouter(airwire_layer=(1000, 1))"Draw air-wires for visualization.")
# Call the AirwireRouter.
)"Air-wire visualization done.")
# Make sure all layers are displayed.