1use libreda_db::prelude as db;
14
15use std::collections::HashMap;
16
17use super::place::placement_problem::{PlacementProblem, PlacementStatus};
18use super::route::routing_problem::{RoutingProblem, GlobalRoutingProblem};
19use db::{SimpleRPolygon, Rect, SimpleTransform};
20
21pub struct SimpleDesign<C: db::L2NBase> {
25 pub fused_layout_netlist: C,
27 pub top_cell: C::CellId,
29 pub cell_outlines: HashMap<C::CellId, db::Rect<C::Coord>>,
31 pub placement_region: Vec<SimpleRPolygon<C::Coord>>,
33 pub placement_status: HashMap<C::CellInstId, PlacementStatus>
35}
36
37impl<C: db::L2NBase> SimpleDesign<C> {
38 pub fn set_placement_status(&mut self, cell_inst: C::CellInstId, placement_status: PlacementStatus) {
40 self.placement_status.insert(cell_inst, placement_status);
41 }
42}
43
44
45impl<C: db::L2NBase> PlacementProblem<C> for SimpleDesign<C> {
46 fn fused_layout_netlist(&self) -> &C {
47 &self.fused_layout_netlist
48 }
49
50 fn top_cell(&self) -> C::CellId {
51 self.top_cell.clone()
52 }
53
54 fn placement_region(&self) -> Vec<SimpleRPolygon<C::Coord>> {
55 self.placement_region.clone()
56 }
57
58 fn initial_position(&self, cell_instance: &C::CellInstId) -> SimpleTransform<C::Coord> {
59 self.fused_layout_netlist.get_transform(cell_instance)
60 }
61
62 fn placement_status(&self, cell_instance: &C::CellInstId) -> PlacementStatus {
63 self.placement_status.get(cell_instance)
64 .copied()
65 .unwrap_or(PlacementStatus::Ignore)
66 }
67
68 fn cell_outline(&self, cell: &C::CellId) -> Option<Rect<C::Coord>> {
69 self.cell_outlines.get(cell).copied()
70 }
71}
72
73pub struct SimpleDesignRef<'a, C: db::L2NBase> {
77 pub fused_layout_netlist: &'a C,
79 pub top_cell: C::CellId,
81 pub cell_outlines: &'a HashMap<C::CellId, db::Rect<C::Coord>>,
83 pub placement_region: &'a Vec<SimpleRPolygon<C::Coord>>,
85 pub placement_status: &'a HashMap<C::CellInstId, PlacementStatus>,
87 pub net_weights: &'a HashMap<C::NetId, f64>,
89 pub placement_location: &'a HashMap<C::CellInstId, db::SimpleTransform<C::Coord>>
91}
92
93
94impl<'a, C: db::L2NBase> PlacementProblem<C> for SimpleDesignRef<'a, C> {
95 fn fused_layout_netlist(&self) -> &C {
96 self.fused_layout_netlist
97 }
98
99 fn top_cell(&self) -> C::CellId {
100 self.top_cell.clone()
101 }
102
103 fn placement_region(&self) -> Vec<SimpleRPolygon<C::Coord>> {
104 self.placement_region.to_vec()
105 }
106
107 fn initial_position(&self, cell_instance: &C::CellInstId) -> SimpleTransform<C::Coord> {
108 self.placement_location.get(cell_instance)
109 .cloned()
110 .unwrap_or_else(|| self.fused_layout_netlist.get_transform(cell_instance))
111 }
112
113 fn placement_status(&self, cell_instance: &C::CellInstId) -> PlacementStatus {
114 self.placement_status.get(cell_instance)
115 .copied()
116 .unwrap_or(PlacementStatus::Ignore)
117 }
118
119 fn cell_outline(&self, cell: &C::CellId) -> Option<Rect<C::Coord>> {
120 self.cell_outlines.get(cell).copied()
121 }
122
123 fn net_weight(&self, net_id: &C::NetId) -> f64 {
124 self.net_weights.get(net_id).copied().unwrap_or(1.0)
125 }
126}
127
128
129impl<'a, C: db::L2NBase> RoutingProblem<C> for SimpleDesignRef<'a, C> {
130 fn fused_layout_netlist(&self) -> &C {
131 self.fused_layout_netlist
132 }
133
134 fn top_cell(&self) -> C::CellId {
135 self.top_cell.clone()
136 }
137
138 fn nets(&self) -> Box<dyn Iterator<Item=C::NetId> + '_> {
139 Box::new(self.fused_layout_netlist.each_internal_net(&self.top_cell))
140 }
141
142 fn net_weight(&self, net: &C::NetId) -> f64 {
143 self.net_weights.get(net).copied().unwrap_or(1.0)
144 }
145
146 fn blockages(&self) -> Box<dyn Iterator<Item=(C::LayerId, db::SimpleRPolygon<C::Coord>)>> {
147 Box::new(std::iter::empty())
148 }
149
150
151 fn boundary(&self) -> Option<db::SimpleRPolygon<C::Coord>> {
152 unimplemented!("boundary")
153 }
154}
155
156impl<'a, C: db::L2NBase> GlobalRoutingProblem<C> for SimpleDesignRef<'a, C> {
157
158}