Ophidian
 All Classes Namespaces Functions
netlist.h
1 /*
2  * Copyright 2016 Ophidian
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0
12 
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19  */
20 
21 #ifndef SRC_NETLIST_NETLIST_H_
22 #define SRC_NETLIST_NETLIST_H_
23 
24 #include "../standard_cell/standard_cells.h"
25 #include "../entity_system/entity_system.h"
26 #include <boost/bimap.hpp>
27 #include "cells.h"
28 #include "pins.h"
29 #include "nets.h"
30 
31 #include <iostream>
32 #include <unordered_map>
33 
34 namespace ophidian {
36 namespace netlist {
38 
41 class netlist {
42 
43  standard_cell::standard_cells * m_std_cells;
44 
45  std::string m_module_name;
46 
47  entity_system::entity_system m_cells_system;
48  entity_system::entity_system m_pins_system;
49  entity_system::entity_system m_nets_system;
50 
51  cells m_cells;
52  pins m_pins;
53  nets m_nets;
54 
55  using entity2index_map = typename boost::bimap< entity_system::entity, std::size_t >;
56  entity2index_map m_PI_mapping;
57  entity2index_map m_PO_mapping;
58 
59  std::vector<entity_system::entity> m_PI;
60  std::vector<entity_system::entity> m_PO;
61 
62  std::unordered_map<std::string, entity_system::entity> m_name2cell;
63  std::unordered_map<std::string, entity_system::entity> m_name2pin;
64  std::unordered_map<std::string, entity_system::entity> m_name2net;
65 
66 public:
67 
68  void cell_preallocate(std::size_t qnt);
69  void pin_preallocate(std::size_t qnt);
70  void net_preallocate(std::size_t qnt);
71 
73 
78 
79  virtual ~netlist();
80 
82 
88 
94 
99 
100  void module_name(std::string name) {
101  m_module_name = name;
102  }
103  std::string module_name() const {
104  return m_module_name;
105  }
106 
108 
113  return *m_std_cells;
114  }
115 
116  // cell
118 
123  entity_system::entity cell_find(std::string name) const;
125 
131  entity_system::entity cell_insert(std::string name, std::string type);
133 
137  void cell_remove(entity_system::entity cell);
138 
140 
144  std::size_t cell_count() const {
145  return m_cells_system.size();
146  }
148 
153  std::string cell_name(entity_system::entity cell) const {
154  return m_cells.name(cell);
155  }
157 
162  const std::vector<entity_system::entity> & cell_pins(entity_system::entity cell) const {
163  return m_cells.pins(cell);
164  }
166 
171  entity_system::entity cell_std_cell(entity_system::entity cell) const {
172  return m_cells.standard_cell(cell);
173  }
175 
181  bool cell_std_cell(entity_system::entity cell, std::string type);
183 
189  bool cell_std_cell(entity_system::entity cell, entity_system::entity std_cell);
191 
196  return m_cells_system;
197  }
199 
203  const cells & cells_properties() const {
204  return m_cells;
205  }
206 
207  // pin
209 
215  entity_system::entity pin_insert(entity_system::entity cell, std::string name);
217 
221  std::size_t pin_count() const {
222  return m_pins_system.size();
223  }
225 
230  std::string pin_name(entity_system::entity pin) const {
231  auto owner = m_pins.owner(pin);
232  std::string the_name;
233  if (!(owner == entity_system::invalid_entity))
234  {
235  the_name = m_cells.name(owner) + ":";
236  std::string std_cell_pin_name = m_std_cells->pin_name(m_pins.standard_cell_pin(pin));
237  std_cell_pin_name = std_cell_pin_name.substr(std_cell_pin_name.find_last_of(':')+1);
238  the_name += std_cell_pin_name;
239  } else
240  the_name = m_std_cells->pin_name(m_pins.standard_cell_pin(pin));
241  return the_name;
242  }
244 
249  entity_system::entity pin_owner(entity_system::entity pin) const {
250  return m_pins.owner(pin);
251  }
253 
258  entity_system::entity pin_net(entity_system::entity pin) const {
259  return m_pins.net(pin);
260  }
262 
267  entity_system::entity pin_std_cell(entity_system::entity pin) const {
268  return m_pins.standard_cell_pin(pin);
269  }
271 
276  entity_system::entity pin_by_name(std::string name) const {
277  return m_name2pin.at(name);
278  }
280 
285  return m_pins_system;
286  }
288 
292  const pins & pins_properties() const {
293  return m_pins;
294  }
295 
296  // net
298 
303  entity_system::entity net_insert(std::string name);
305 
311  entity_system::entity net_insert(std::string name, std::size_t pin_count);
313 
317  void net_remove(entity_system::entity net);
319 
323  std::size_t net_count() const {
324  return m_nets_system.size();
325  }
327 
332  std::string net_name(entity_system::entity net) const {
333  return m_nets.name(net);
334  }
336 
341  const std::vector<entity_system::entity> & net_pins(entity_system::entity net) const {
342  return m_nets.pins(net);
343  }
344 
346 
350  std::pair<std::vector<std::string>::const_iterator,
351  std::vector<std::string>::const_iterator> net_names() const {
352  return m_nets.names();
353  }
355 
360  return m_nets_system;
361  }
363 
368  entity_system::entity net_by_name(std::string name) const {
369  return m_name2net.at(name);
370  }
372 
376  const nets & nets_properties() const {
377  return m_nets;
378  }
379 
381 
386  void connect(entity_system::entity net, entity_system::entity pin);
388 
392  void disconnect(entity_system::entity pin);
393 
394  // PI
396 
401  entity_system::entity PI_insert(std::string name);
403 
407  void PI_remove(entity_system::entity PI);
409 
413  std::size_t PI_count() const {
414  return m_PI.size();
415  }
417 
421  std::vector<entity_system::entity>::const_iterator PI_begin() const {
422  return m_PI.begin();
423  }
425 
429  std::vector<entity_system::entity>::const_iterator PI_end() const {
430  return m_PI.end();
431  }
432 
433  // PO
435 
440  entity_system::entity PO_insert(std::string name);
442 
446  void PO_remove(entity_system::entity PO);
448 
452  std::size_t PO_count() const {
453  return m_PO.size();
454  }
456 
460  std::vector<entity_system::entity>::const_iterator PO_begin() const {
461  return m_PO.begin();
462  }
464 
468  std::vector<entity_system::entity>::const_iterator PO_end() const {
469  return m_PO.end();
470  }
471 
472 };
473 
474 } /* namespace netlist */
475 } /* namespace ophidian */
476 
477 #endif /* SRC_NETLIST_NETLIST_H_ */
const entity_system::entity_system & net_system() const
Net system getter.
Definition: netlist.h:359
void register_net_property(entity_system::property *property)
Registers net property.
Definition: netlist.cpp:58
const entity_system::entity_system & pin_system() const
Pin system getter.
Definition: netlist.h:284
std::size_t PI_count() const
Returns the number of primary inputs.
Definition: netlist.h:413
std::vector< entity_system::entity >::const_iterator PI_begin() const
Primary input begin iterator.
Definition: netlist.h:421
entity_system::entity pin_insert(entity_system::entity cell, std::string name)
Inserts a new pin.
Definition: netlist.cpp:93
const pins & pins_properties() const
Pin properties getter.
Definition: netlist.h:292
std::vector< entity_system::entity >::const_iterator PO_begin() const
Primary output begin iterator.
Definition: netlist.h:460
Definition: nets.h:32
std::vector< entity_system::entity >::const_iterator PO_end() const
Primary output end iterator.
Definition: netlist.h:468
void PO_remove(entity_system::entity PO)
Removes a primary output.
Definition: netlist.cpp:200
const std::vector< entity_system::entity > & cell_pins(entity_system::entity cell) const
Cell pins getter.
Definition: netlist.h:162
entity_system::entity cell_insert(std::string name, std::string type)
Inserts a new cell.
Definition: netlist.cpp:69
entity_system::entity net_insert(std::string name)
Inserts a new net.
Definition: netlist.cpp:112
std::size_t cell_count() const
Returns the number of cells.
Definition: netlist.h:144
entity_system::entity pin_owner(entity_system::entity pin) const
Pin owner getter.
Definition: netlist.h:249
std::vector< entity_system::entity >::const_iterator PI_end() const
Primary input end iterator.
Definition: netlist.h:429
netlist(standard_cell::standard_cells *std_cells)
Constructor.
Definition: netlist.cpp:43
entity_system::entity cell_std_cell(entity_system::entity cell) const
Cell type getter.
Definition: netlist.h:171
void connect(entity_system::entity net, entity_system::entity pin)
Connects a pin to a net.
Definition: netlist.cpp:130
std::string cell_name(entity_system::entity cell) const
Cell name getter.
Definition: netlist.h:153
const standard_cell::standard_cells & std_cells() const
Standard cells getter.
Definition: netlist.h:112
entity_system::entity pin_net(entity_system::entity pin) const
Pin net getter.
Definition: netlist.h:258
const cells & cells_properties() const
Cell properties getter.
Definition: netlist.h:203
std::size_t pin_count() const
Returns the number of pins.
Definition: netlist.h:221
void disconnect(entity_system::entity pin)
Disconnects a pin from its net.
Definition: netlist.cpp:140
Netlist class.
Definition: netlist.h:41
void register_pin_property(entity_system::property *property)
Registers pin property.
Definition: netlist.cpp:54
void PI_remove(entity_system::entity PI)
Removes a primary input.
Definition: netlist.cpp:167
Definition: cells.h:32
Property class.
Definition: property.h:33
entity_system class.
Definition: entity_system.h:40
entity_system::entity PO_insert(std::string name)
Inserts a new primary output.
Definition: netlist.cpp:188
const entity_system::entity_system & cell_system() const
Cell system getter.
Definition: netlist.h:195
void cell_remove(entity_system::entity cell)
Removes a cell.
Definition: netlist.cpp:83
Definition: pins.h:31
entity_system::entity pin_std_cell(entity_system::entity pin) const
Pin type getter.
Definition: netlist.h:267
std::string pin_name(entity_system::entity pin) const
Pin name getter.
Definition: netlist.h:230
std::size_t net_count() const
Returns the number of nets.
Definition: netlist.h:323
void register_cell_property(entity_system::property *property)
Registers cell property.
Definition: netlist.cpp:50
std::string net_name(entity_system::entity net) const
Net name getter.
Definition: netlist.h:332
entity_system::entity net_by_name(std::string name) const
Finds net.
Definition: netlist.h:368
std::size_t size() const
Returns the size of the system.
Definition: entity_system.h:82
const std::vector< entity_system::entity > & net_pins(entity_system::entity net) const
Net pins getter.
Definition: netlist.h:341
void net_remove(entity_system::entity net)
Removes a net.
Definition: netlist.cpp:158
std::pair< std::vector< std::string >::const_iterator, std::vector< std::string >::const_iterator > net_names() const
Net names iterator.
Definition: netlist.h:351
entity_system::entity PI_insert(std::string name)
Inserts a new primary input.
Definition: netlist.cpp:145
entity_system::entity cell_find(std::string name) const
Finds cell.
Definition: netlist.cpp:62
std::size_t PO_count() const
Returns the number of primary outputs.
Definition: netlist.h:452
Standard cell class.
Definition: standard_cells.h:37
std::string pin_name(entity_system::entity pin) const
Pin name getter.
Definition: standard_cells.h:158
const nets & nets_properties() const
Net properties getter.
Definition: netlist.h:376
entity_system::entity pin_by_name(std::string name) const
Finds pin.
Definition: netlist.h:276