use super::stdcell_placer::SimpleStdCellPlacer;
use libreda_db::netlist::traits::NetlistBase;
use libreda_db::prelude as db;
use libreda_db::prelude::{Point, SimplePolygon};
use log::debug;
use std::collections::{HashMap, HashSet};
pub struct SimpleStdCellPlacerCascade<N: NetlistBase> {
stages: Vec<Box<dyn SimpleStdCellPlacer<N>>>,
}
impl<N: NetlistBase> SimpleStdCellPlacerCascade<N> {
pub fn new(placers: Vec<Box<dyn SimpleStdCellPlacer<N>>>) -> Self {
SimpleStdCellPlacerCascade { stages: placers }
}
}
impl<N: NetlistBase> SimpleStdCellPlacer<N> for SimpleStdCellPlacerCascade<N> {
fn name(&self) -> &str {
"SimpleCascadePlacer"
}
fn find_cell_positions_impl(
&self,
netlist: &N,
circuit_id: &N::CellId,
core_area: &SimplePolygon<db::Coord>,
initial_positions: &HashMap<N::CellInstId, Point<db::Coord>>,
fixed_instances: &HashSet<N::CellInstId>,
cell_outlines: &HashMap<N::CellId, db::Rect<db::Coord>>,
net_weights: &HashMap<N::NetId, f64>,
) -> HashMap<N::CellInstId, Point<i32>> {
debug!("Placer cascade contains {} placers.", self.stages.len());
let mut initial_pos = initial_positions.clone();
for placer in &self.stages {
let mut result = placer.find_cell_positions(
netlist,
circuit_id,
core_area,
&initial_pos,
fixed_instances,
cell_outlines,
net_weights,
);
for inst in fixed_instances {
result.insert(inst.clone(), initial_positions[inst]);
}
initial_pos = result;
}
initial_pos
}
}